supervisorctl使用记录

常用命令:
#查看所有服务状态
supervisorctl status
#查看单个服务状态
supervisorctl status 服务名
#启动/停止/重启服务
supervisorctl start/stop/restart 服务名
新增一个服务:
[program:<服务名>]
command=<启动命令>
process_name=%(program_name)s ; process_name expr (default %(program_name)s)
numprocs=1                    ; number of processes copies to start (def 1)
directory=<运行目录>                ; 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)
autorestart=unexpected        ; whether/when to restart (default: unexpected)
startsecs=1                   ; number of secs prog must stay running (def. 1)
startretries=3                ; max # of serial start failures (default 3)
exitcodes=0,2                 ; 'expected' exit codes for process (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=skywell                  ; setuid to this UNIX account to run the program
;redirect_stderr=true          ; redirect proc stderr to stdout (default false)
stdout_logfile=/var/log/<服务名>.log        ; stdout log path, NONE for none; default AUTO
stdout_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
stdout_logfile_backups=1     ; # of stdout logfile backups (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        ; 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 (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",HOME="/home/skywell"       ; process environment additions (def no adds)
serverurl=AUTO                ; override serverurl computation (childutils)

首先添加任务描述文件,在/etc/supervisor目录下新建文件sparkportal.conf, 将上面任务模板内容复制进文件sparkportal.conf中,将<服务名>替换为任务名sparkportal,将<启动命令>替换为node www.js,将<运行目录>替换为程序所在目录/usr/local/sparkportal/bin。

sparkportal的配置文件为
[program:sparkportal]
command=node www.js
process_name=%(program_name)s ; process_name expr (default %(program_name)s)
numprocs=1                    ; number of processes copies to start (def 1)
directory=/usr/local/sparkportal/bin                ; 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)
autorestart=unexpected        ; whether/when to restart (default: unexpected)
startsecs=1                   ; number of secs prog must stay running (def. 1)
startretries=3                ; max # of serial start failures (default 3)
exitcodes=0,2                 ; 'expected' exit codes for process (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=skywell                  ; setuid to this UNIX account to run the program
;redirect_stderr=true          ; redirect proc stderr to stdout (default false)
stdout_logfile=/var/log/sparkportal.log        ; stdout log path, NONE for none; default AUTO
stdout_logfile_maxbytes=1MB   ; max # logfile bytes b4 rotation (default 50MB)
stdout_logfile_backups=1     ; # of stdout logfile backups (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/sparkportal.err        ; 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 (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",HOME="/home/skywell"       ; process environment additions (def no adds)
serverurl=AUTO                ; override serverurl computation (childutils)

最小必要配置
[program:easyswoole-xxx-xxx-com]
#process_name=%(process_num)02d
command=php /home/www/xx.xxx.com/easyswoole start produce
autostart=true
autorestart=true
user=root
#numprocs=1
redirect_stderr=true
stdout_logfile=/home/www/xxx.xxx.com/Log/supervisor.log
增加任务
supervisorctl update

该命令会将sparkportal.conf所描述的任务启动并纳入管理。然后运用查看任务命令即可查看新增任务的运行状态,如若运行失败,可查看/usr/log目录下的相关日志分析原因。

设置环境变量
在配置文件找到environment所在行,若没有没有最下面增加environment=变量名="变量值"即可,如果多个环境变量用逗号分隔,例如environment=变量名1=“变量值1”,变量名2=“变量值2”。

将nodejs运行环境设置为生产环境,增加如下代码:

environment=NODE_ENV=production

转载自:https://www.jianshu.com/p/f8735b039c67?from=groupmessage

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值