我有以下supervisord配置(从this answer复制):
[program:myprogram]
process_name=MYPROGRAM%(process_num)s
directory=/var/www/apps/myapp
command=/var/www/apps/myapp/virtualenv/bin/python index.py --PORT=%(process_num)s
startsecs=2
user=youruser
stdout_logfile=/var/log/myapp/out-%(process_num)s.log
stderr_logfile=/var/log/myapp/err-%(process_num)s.log
numprocs=4
numprocs_start=14000
我可以用systemd做同样的事情吗?
答案 0 :(得分:6)
systemd单元可以包含specifiers,可用于编写将多次实例化的通用单元服务。
基于supervisord
配置的示例:/etc/systemd/system/mydaemon@.service
:
[Unit]
Description=My awesome daemon on port %i
After=network.target
[Service]
User=youruser
WorkingDirectory=/var/www/apps/myapp
Type=simple
ExecStart=/var/www/apps/myapp/virtualenv/bin/python index.py --PORT=%i
[Install]
WantedBy=multi-user.target
然后,您可以使用以下示例启用/启动该服务的多个实例:
# systemctl start mydaemon@4444.service
有关Fedora Magazine.org的更多示例的文章:systemd: Template unit files。