LoginSignup
0
0

Amazon Linux 2023でSupervisor設定

Last updated at Posted at 2024-06-20

概要

Amazon Linux 2023にSupervisorをインストールして、Laravelのキューを管理できるようにする。

環境

  • Amazon Linux 2023
  • Laravel 11系

手順

※ 各種手順は必要に応じてroot権限で実行してください。

1. pipをインストール

$ dnf install pip -y

2. Supervisorをインストール

$ pip install supervisor

3. supervisord.serviceファイル作成

$ vi /lib/systemd/system/supervisord.service
supervisord.service
[Unit]
Description=Process Monitoring and Control Daemon
After=rc-local.service nss-user-lookup.target

[Service]
Type=forking
ExecStart=/usr/local/bin/supervisord -c /etc/supervisord.conf

[Install]
WantedBy=multi-user.target

4. Supervisorのlogとsockフォルダ作成

$ mkdir -p /var/log/supervisor/
$ mkdir -p /var/run/supervisor/

5. supervisor.confを作成

$ vi /etc/supervisord.conf
/etc/supervisord.conf
[unix_http_server]
file=/var/run/supervisor/supervisor.sock ; (the path to the socket file)

[supervisord]
logfile=/var/log/supervisor/supervisord.log ; (main log file;default $CWD/supervisord.log)
logfile_maxbytes=50MB ; (max main logfile bytes b4 rotation;default 50MB)
logfile_backups=10 ; (num of main logfile rotation backups;default 10)
loglevel=info ; (log level;default info; others: debug,warn,trace)
pidfile=/var/run/supervisord.pid ; (supervisord pidfile;default supervisord.pid)
nodaemon=false ; (start in foreground if true;default false)
minfds=1024 ; (min. avail startup file descriptors;default 1024)
minprocs=200 ; (min. avail process descriptors;default 200)

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

[supervisorctl]
serverurl=unix:///var/run/supervisor/supervisor.sock ; use a unix:// URL for a unix socket

[include]
files = supervisord.d/*.ini

6. カスタム用のconfディレクトリを作成

$ mkdir /etc/supervisord.d

7. Laravelキュー管理用のlaravel-worker.ini作成

$ vi /etc/supervisord.d/laravel-worker.ini

設定サンプル

laravel-worker.ini
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /home/forge/app.com/artisan queue:work sqs --sleep=3 --tries=3 --max-time=3600
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=forge
numprocs=8
redirect_stderr=true
stdout_logfile=/home/forge/app.com/worker.log
stopwaitsecs=3600

※ command、user、stdout_logfileはアプリケーションに応じて変更してください。
※ command:artisanコマンドが実行できるように絶対パスで指定することにご注意ください。
※ user:サーバーにログインしているユーザー名を指定してください。

実例:https://cloudool.com/

laravel-worker.ini
[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /srv/cloudool/server/artisan queue:work --sleep=3 --tries=3 --max-time=3600
autostart=true
autorestart=true
stopasgroup=true
killasgroup=true
user=cloudool-user
numprocs=8
redirect_stderr=true
stdout_logfile=/srv/cloudool/server/storage/logs/worker.log
stopwaitsecs=3600

Supervisor起動および自動起動設定

systemctl daemon-reload
systemctl enable supervisord
systemctl start supervisord

確認

$ systemctl status supervisord

Active: active (running) となっていればOKです。

参考

0
0
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0