我有一个如下的systemd服务脚本:
#
# systemd unit file for Debian
#
# Put this in /lib/systemd/system
# Run:
# - systemctl enable sidekiq
# - systemctl {start,stop,restart} sidekiq
#
# This file corresponds to a single Sidekiq process. Add multiple copies
# to run multiple processes (sidekiq-1, sidekiq-2, etc).
#
[Unit]
Description=sidekiq
# start sidekiq only once the network, logging subsystems are available
After=syslog.target network.target
[Service]
Type=simple
WorkingDirectory=/home/deploy/app
User=deploy
Group=deploy
UMask=0002
ExecStart=/bin/bash -lc "bundle exec sidekiq -e ${environment} -C config/sidekiq.yml -L log/sidekiq.log -P /tmp/sidekiq.pid"
ExecStop=/bin/bash -lc "bundle exec sidekiqctl stop /tmp/sidekiq.pid"
# if we crash, restart
RestartSec=1
Restart=on-failure
# output goes to /var/log/syslog
StandardOutput=syslog
StandardError=syslog
# This will default to "bundler" if we don't specify it
SyslogIdentifier=sidekiq
[Install]
WantedBy=multi-user.target
现在我可以发出类似以下的命令:
sudo systemctl enable sidekiq
sudo systemctl start sidekiq
我希望创建另一个自定义命令,使我能够退出sidekiq工作者。要静默sidekiq,我必须向进程发送USR1信号,类似于以下内容:
sudo kill -s USR1 `cat #{sidekiq_pid}`
我希望使用systemd服务来实现这个功能,基本上就像一个命令:
sudo systemctl queit sidekiq
有没有一种方法可以在systemd服务文件中创建自定义命令?如果是,那么如何进行操作呢?
systemctl quiet sidekiq
,但我建议您进行更多的研究,不要轻信我的话。 - Mike Perham