티스토리 뷰
fabric 설치
1 | pip install fabric | cs |
install.py(fabfile.py) 스크립트 작성
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | from fabric.state import output from fabric.api import run, env, put, sudo #env.hosts=[ # "root@server-001.test.com" #] #env.password = "passwd" #env.warn_only = True #output.status = False #output.everything = False env.disable_known_hosts = True env.reject_unknown_hosts = False def install_daemon(opt1, opt2, opt3): output.result = run("uname -a") #put('./install_daemon.sh', '~/') #output.result = run('/bin/bash ~/install_daemon.sh -a "%s" -b "%s" -c "%s"' % (opt1, opt2, opt3)) return output.result.return_code if __name__ == '__main__': from fabric.tasks import execute env.password = "password" result = execute(install_daemon, "opt1", "opt2", "opt3", hosts=["root@server-001.test.com"]) for host in result.keys(): return_code = result[host] print host, return_code | cs |
install_daemon.py 스크립트 작성
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | #!/bin/bash while [[ $# -gt 1 ]] do key="$1" case $key in -a|--opt1) OPT1="$2" shift # past argument ;; -b|--opt2) OPT2="$2" shift # past argument ;; -c|--opt3) OPT3="$2" shift # past argument ;; *) # unknown option ;; esac shift # past argument or value done if [ ! "$OPT1" ] then echo "required opt1" exit -1 fi if [ ! "$OPT2" ] then echo "required opt2" exit -2 fi if [ ! "$OPT3" ] then echo "required opt3" exit -3 fi PROCESS_NAME="daemon.py" PROCESS_EXISTS=`ps auxwww |fgrep $PROCESS_NAME |grep -v grep |wc -l` if [ "$PROCESS_EXISTS" -ne "0" ] then killall $PROCESS_NAME sleep 3 fi NOW_DATETIME=`date +%Y%m%d%H%M%S` USER=`whoami` PWD=`cd ~;pwd` INSTALL_DIR="/usr/local/daemon" INSTALL_VER="1.1.0" INSTALL_SRC="daemon-${INSTALL_VER}" SRC_DIR="$PWD/src" SRC_URL="http://download.test.com/src/${INSTALL_SRC}.tar.gz" if [ -d "$INSTALL_DIR" ] then mv ${INSTALL_DIR} ${INSTALL_DIR}_${NOW_DATETIME} fi if [ ! -d "$SRC_DIR" ] then mkdir $SRC_DIR fi if [ -d "${SRC_DIR}/${INSTALL_SRC}" ] then mv ${SRC_DIR}/${INSTALL_SRC} ${SRC_DIR}/${INSTALL_SRC}_${NOW_DATETIME} fi wget -q ${SRC_URL} -O "${SRC_DIR}/${INSTALL_SRC}.tar.gz" if [ "$?" -ne "0" ]; then exit -4; fi tar xvfz "${SRC_DIR}/${INSTALL_SRC}.tar.gz" -C $SRC_DIR if [ "$?" -ne "0" ]; then exit -5; fi cd ${SRC_DIR}/${INSTALL_SRC} ./configure --prefix=${INSTALL_DIR} \ --sbindir=${INSTALL_DIR}/bin \ --sysconfdir=${INSTALL_DIR}/etc \ --with-pid-dir=${INSTALL_DIR}/var/run if [ "$?" -ne "0" ]; then exit -6; fi make -j `grep processor /proc/cpuinfo | wc -l` if [ "$?" -ne "0" ]; then exit -7; fi make install if [ "$?" -ne "0" ]; then exit -8; fi mkdir -p ${INSTALL_DIR}/var/run if [ "$?" -ne "0" ]; then exit -9; fi mkdir -p ${INSTALL_DIR}/var/lock if [ "$?" -ne "0" ]; then exit -10; fi ${INSTALL_DIR}/bin/daemon start if [ "$?" -ne "0" ]; then exit -11; fi sleep 3 PORT_EXISTS=`netstat -lnp | grep ':8001 '|fgrep ${PROCESS_NAME} |wc -l` if [ "$PORT_EXISTS" -eq "0" ] then echo "port is not open" exit -11 fi BOOT_START=`egrep "${INSTALL_DIR}/bin/daemon\s+start" /etc/rc.d/rc.local |wc -l` if [ "$BOOT_START" -eq "0" ] then echo -e "# daemon start\n${INSTALL_DIR}/bin/daemon start" >> /etc/rc.d/rc.local if [ "$?" -ne "0" ]; then exit -12; fi fi exit 0 | cs |
fab 커멘드로 설치 실행
1 | fab -f install.py -H root@server-001.test.com install_daemon:opt1,opt2,opt | cs |
python 스크립트로 설치 실행
1 | python install.py | cs |
'엔지니어링' 카테고리의 다른 글
Web Deploy 윈도우 웹서버 이전 하기 (0) | 2017.07.21 |
---|---|
Perl 구조화된 문자열 정규표현식 치환 (0) | 2017.02.08 |
MySQL auto_increment 증가와 최대값 (0) | 2017.01.04 |
bacula 백업 (0) | 2016.10.10 |
Nginx + uwsgi unix socket 문제 (0) | 2016.09.13 |
댓글
warpmemory
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
페이지
TAG
- mysql
- Windows
- apache
- 명령어
- example
- MariaDB
- Ansible
- error
- RESTful
- File
- 이슈처리
- configuration
- httpd
- deview
- command
- Linux
- 외부링크
- limits
- 예제
- code
- 코드
- Web
- monitoring
- PowerShell
- engineering
- 번역
- Module
- Python
- client
- check
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
글 보관함