我有一个类似这样的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服务文件中创建自定义命令?如果是,那么如何着手做这件事呢?
发布于 2017-03-22 21:46:17
这不是一个“自定义”命令,但您可以使用
Sidekiq >= 5:
systemctl kill -s TSTP --kill-who=main example.service Sidekiq < 5:
systemctl kill -s USR1 --kill-who=main example.service 发出“安静”信号。有关更多解释,请参阅http://0pointer.de/blog/projects/systemd-for-admins-4.html。
发布于 2016-11-22 00:50:49
您可以使用此处介绍的ExecReload:
https://www.freedesktop.org/software/systemd/man/systemd.service.html
Sidekiq < 5:
ExecReload=/bin/kill -USR1 $MAINPID
Sidekiq 5 (USR1在5中已弃用,它使用TSTP):
ExecReload=/bin/kill -TSTP $MAINPID
然后运行systemctl reload sidekiq来发送安静的信号。
https://stackoverflow.com/questions/40717036
复制相似问题