【发布时间】:2016-11-21 09:42:29
【问题描述】:
我有一个这样的 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 服务文件中创建自定义命令?如果是,那该怎么做呢?
【问题讨论】: