Supervisor works on just about everything except for Windows.
准确点说,基本UNIX-Like系统都支持。
主要组件
supervisord
supervisor的服务进程,响应客户端的命令、管理子进程
使用的时候要读取配置文件。寻找配置文件的优先级如下:
1 2 3 4 5 6
$CWD/supervisord.conf $CWD/etc/supervisord.conf /etc/supervisord.conf /etc/supervisor/supervisord.conf (since Supervisor 3.3.0) ../etc/supervisord.conf (Relative to the executable) ../supervisord.conf (Relative to the executable)
[inet_http_server] ; inet (TCP) server disabled by default port=127.0.0.1:9001 ; ip_address:port specifier, *:port for all iface username=onecer ; default is no username (open server) password=youpassword ; default is no password (open server)
[program:roomstatus_dev] command=/usr/bin/java -jar /data/www/room/devshixin.jar ; the program (relative uses PATH, can take args) ;process_name=%(program_name)s ; process_name expr (default %(program_name)s) ;numprocs=1 ; number of processes copies to start (def 1) ;directory=/tmp ; directory to cwd to before exec (def no cwd) ;umask=022 ; umask for process (default None) ;priority=999 ; the relative start priority (default 999) autostart=true ; start at supervisord start (default: true) ;startsecs=1 ; # of secs prog must stay up to be running (def. 1) ;startretries=3 ; max # of serial start failures when starting (default 3) autorestart=unexpected ; when to restart if exited after running (def: unexpected) ;exitcodes=0,2 ; 'expected' exit codes used with autorestart (default 0,2) ;stopsignal=QUIT ; signal used to kill process (default TERM) ;stopwaitsecs=10 ; max num secs to wait b4 SIGKILL (default 10) ;stopasgroup=false ; send stop signal to the UNIX process group (default false) ;killasgroup=false ; SIGKILL the UNIX process group (def false) ;user=chrism ; setuid to this UNIX account to run the program ;redirect_stderr=true ; redirect proc stderr to stdout (default false) stdout_logfile=/var/log/dev_room.log ; stdout log path, NONE for none; default AUTO stdout_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB) stdout_logfile_backups=10 ; # of stdout logfile backups (0 means none, default 10) ;stdout_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0) ;stdout_events_enabled=false ; emit events on stdout writes (default false) stderr_logfile=/var/log/err_dev_room.log ; stderr log path, NONE for none; default AUTO stderr_logfile_maxbytes=1MB ; max # logfile bytes b4 rotation (default 50MB) stderr_logfile_backups=10 ; # of stderr logfile backups (0 means none, default 10) ;stderr_capture_maxbytes=1MB ; number of bytes in 'capturemode' (default 0) ;stderr_events_enabled=false ; emit events on stderr writes (default false) ;environment=A="1",B="2" ; process environment additions (def no adds) ;serverurl=AUTO ; override serverurl computation (childutils)
# 记录日志 deflogger(line): if ENABLE_LOG: if os.path.isfile(LOGFILE): with codecs.open(LOGFILE,'a','utf-8') as f: f.write("{time}{logline}\n".format(time=get_time(), logline=line)) else: with codecs.open(LOGFILE,'w','utf-8') as f: f.write("{time}{logline}\n".format(time=get_time(), logline=line))
# 记录命令日志 deflogger_commands(status,result): logger('result:{status}'.format(status=status)) if VERBOSE_MODE: logger(result)
# 执行剧本 defplay_playbooks(filelists): for filelist in filelists: if os.path.isfile(filelist) and os.path.splitext(filelist)[-1]=='.yaml': withopen(filelist,'r') as f: playbook = yaml.load(f) sences = playbook['playbook']['sences'] for sence in sences: if playbook['execute']['pre-local']: deploy_sences(True,playbook['execute']['pre-local']) if playbook['execute']['pre-remote']: deploy_sences(False, playbook['execute']['pre-remote'],playbook['actor']) sync_files(playbook['actor'],sence) if playbook['execute']['post-remote']: deploy_sences(False,playbook['execute']['post-remote'],playbook['actor']) if playbook['execute']['post-local']: deploy_sences(True,playbook['execute']['post-local'])
if __name__=='__main__': play_playbooks(get_file_lists(os.path.join(BASEDIR,'playbook')))
fate phan # systemctl stop mysql fate phan # mysqld_safe --skip-grant-tables & [1] 14391 fate phan # 170527 11:46:39 mysqld_safe Logging to syslog. 170527 11:46:39 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
fate phan # mysql -uroot Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 2 Server version: 10.0.29-MariaDB-0ubuntu0.16.04.1 Ubuntu 16.04
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h'forhelp. Type '\c' to clear the current input statement.
MariaDB [(none)]> use mysql; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A
Database changed MariaDB [mysql]> update user set password=PASSWORD("gjdEdufD93J") where User='root'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0