dnf install python3 python3-pip
python -V
pip3 -V
pip3 install --upgrade pip
pip3 install supervisor
バージョン確認
supervisord --version
設定ファイルの作成
mkdir /etc/supervisor/
mkdir /etc/supervisor/conf.d
/etc/supervisor/supervisor.sock
vi /etc/supervisor/supervisord.conf
supervisord.conf
[unix_http_server]
file=/run/supervisor/supervisor.sock ; UNIXソケットファイルのパス
chmod=0700 ; ソケットファイルのパーミッション
[supervisord]
logfile=/var/log/supervisord.log ; メインのログファイル
logfile_maxbytes=50MB ; ログファイルの最大サイズ
logfile_backups=10 ; ログファイルのバックアップ数
loglevel=info ; ログレベル
pidfile=/tmp/supervisord.pid ; pidファイルのパス
nodaemon=false ; フォアグラウンドで実行するかどうか
minfds=1024 ; 最小のファイルディスクリプタ数
minprocs=200 ; 最小のプロセス記述子数
[rpcinterface:supervisor]
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface
[supervisorctl]
serverurl=unix:///tmp/supervisor.sock ; スーパーバイザに接続するためのUNIXソケット
[program:example_program]
command=/path/to/program/api_app_server'
autostart=true ; supervisordの起動時に自動的に開始
autorestart=true ; 予期せず終了した場合に再起動
stderr_logfile=/var/log/example_program.err.log ; 標準エラー出力のログファイル
stdout_logfile=/var/log/example_program.out.log ; 標準出力のログファイル
user=kusanagi ; プログラムを実行するユーザー
sudo mkdir -p /run/supervisor
sudo chown root:root /run/supervisor
sudo chmod 0700 /run/supervisor
vi /etc/systemd/system/supervisord.service
[Unit]
Description=Supervisor process control system for UNIX
Documentation=http://supervisord.org
After=network.target
[Service]
ExecStart=/usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf
ExecStop=/usr/bin/supervisorctl $OPTIONS shutdown
ExecReload=/usr/bin/supervisorctl $OPTIONS reload
KillMode=process
Restart=on-failure
RestartSec=50s
User=root
Group=root
[Install]
WantedBy=multi-user.target
# デーモンをリロード
sudo systemctl daemon-reload
# 自動起動 on
sudo systemctl enable supervisord
# 開始
sudo systemctl start supervisord
# systemd ステータスの確認
sudo systemctl status supervisord
sudo systemctl status supervisord
supervisord -c /etc/supervisor/supervisord.conf
起動時にエラーとなる場合は次のコマンドでプロセスしてから再度起動します
sudo killall supervisord
sudo supervisorctl reread
sudo supervisorctl update
sudo systemctl restart supervisord
supervisorctl status
結果例
my_api RUNNING pid 39984, uptime 8 days, 9:40:03
supervisorctl signal TERM my_api
supervisorctl shutdown
https://askubuntu.com/questions/911994/supervisorctl-3-3-1-http-localhost9001-refused-connection
supervisorctl help
こちらの方法で確認するのがとても分かりやすくて良いです ! https://chariosan.com/2019/11/10/supervisor4_al2/
1. hello.sh の用意
cd /home/myuser
vi hello.sh
#!/bin/bash
while :; do
echo "Hello, world!"
sleep 1
done
chmod +x hello.sh
1. hello.sh を監視する設定ファイルを作成
vi /etc/supervisor/conf.d/hello.conf
[program:hello]
command=/home/kusanagi/MYDOMAIN.COM/sh/hello.sh
process_name=%(program_name)s_%(process_num)02d
autostart=true
autorestart=true
user=kusanagi
numprocs=1
redirect_stderr=true
stdout_logfile=/tmp/hello.log