gpt4 book ai didi

ubuntu - 对服务的 systemd 自定义命令

转载 作者:太空宇宙 更新时间:2023-11-03 16:54:28 27 4
gpt4 key购买 nike

我有一个像这样的 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 服务文件中创建自定义命令?如果是,那么该怎么做?

最佳答案

这不是“自定义”命令,但您可以使用

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以获得更多解释。

关于ubuntu - 对服务的 systemd 自定义命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40717036/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com