Subscribed unsubscribe Subscribe Subscribe

OngaLog

最近GOが楽しくて、

SupervisorでGoをデーモン化する。CentOS/Ubuntu

GoアプリケーションをCentOS環境で、デーモン化する必要があったので、その時の作業ログ。

CentOS

$ wget https://bootstrap.pypa.io/ez_setup.py -O - | python
$ easy_install --version
$ easy_install supervisor
$ supervisord -v
$ echo_supervisord_conf > /etc/supervisord.conf

設定ファイルを変更

;/etc/supervisord.conf
[unix_http_server]
file = /tmp/supervisor.sock
chmod = 0777
chown= root:root


[inet_http_server]
port=9001
username = admin
password = yourpassword

[supervisorctl]
serverurl = unix:///tmp/supervisor.sock

[supervisord]
logfile=/var/log/supervisord/supervisord.log
logfile_maxbytes=50MB
logfile_backups=10
loglevel=info
pidfile=/var/run/supervisord.pid
nodaemon=true
minfds=1024
minprocs=200
user=root
childlogdir=/var/log/supervisord/


[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface


[program:app]
command=/path-to-path/yourappname
autostart = true
startsecs = 5
user = root
redirect_stderr = true
stdout_logfile = /var/log/supervisord/app.log

Run

supervisord

Stop/Reload

以下のコマンドで管理モードに入る

supervisorctl
reload

Ubuntu

$ sudo apt-get install supervisor
$ sudo vim /etc/supervisor/conf.d/app.conf

設定ファイルを変更

[unix_http_server]
file=/var/run/supervisor.sock
chmod=0700

[supervisord]
logfile=/var/log/supervisor/supervisord.log
pidfile=/var/run/supervisord.pid
childlogdir=/var/log/supervisor

[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface

[supervisorctl]
serverurl=unix:///var/run/supervisor.sock

[include]
files = /etc/supervisor/conf.d/*.conf

[program:app]
command=<your path>
autostart=true
autorestart=true
startretries=10
user=root
redirect_stderr=true
stderr_logfile=/var/log/long.err.log
stdout_logfile=/var/log/long.out.log
stdout_logfile_maxbytes=50MB
stdout_logfile_backups=10

(command に指定する前にbuildしておく必要がある。)

$ sudo service supervisor restart