我该如何在Ubuntu上将sidekiq作为守护进程运行?
如果我运行bundle exec sidekiq -D
,我会得到invalid option: -D
错误提示,有没有其他方式可以运行它而不需要使用god、upstart等控制器?
我该如何在Ubuntu上将sidekiq作为守护进程运行?
如果我运行bundle exec sidekiq -D
,我会得到invalid option: -D
错误提示,有没有其他方式可以运行它而不需要使用god、upstart等控制器?
从Sidekiq 6.0开始,守护进程模式将无法正常工作。如果您传递-d参数,会收到以下提示:
在Sidekiq 6.0中已删除守护进程模式,请使用正确的进程监管器来启动和管理您的服务
请查看此问题 #4045
sidekiq
意外崩溃时重新启动。另一种选择是将 sidekiq 作为服务运行(使用 upstart job)。如果系统重新启动,则 upstart job 也会运行 sidekiq。这里 提供了完整的脚本和运行 sidekiq 作为服务的方法。sudo service sidekiq start/stop/restart
简单地启动/停止/重新启动 sidekiq。对于Sidekiq 6或更高版本,不支持将程序作为Unix运行,需要将进程作为服务运行。
根据您的bundler位置编写脚本,或者您可以修改下面的代码片段,并将其复制到/usr/lib/systemd/system
(CentOS)或/lib/systemd/system
(Ubuntu)中。
[Unit]
Description=sidekiq
After=syslog.target network.target
[Service]
Type=notify
WatchdogSec=10
WorkingDirectory=/home/deploy/apps/project_name
# If you use rbenv:
# ExecStart=/bin/bash -lc 'exec /home/deploy/.rbenv/shims/bundle exec sidekiq -e production'
# If you use the system's ruby:
# ExecStart=/usr/local/bin/bundle exec sidekiq -e production
# If you use rvm in production, don't.
#ExecStart=/home/deploy/.rvm/wrappers/ruby-2.6.5/bundle exec sidekiq -e production
# Use `systemctl kill -s TSTP sidekiq` to quiet the Sidekiq process
# !!! Change this to your deploy user account !!!
User=deploy
Environment=MALLOC_ARENA_MAX=2
# if the script crash, restart
RestartSec=1
Restart=on-failure
# output goes to /var/log/syslog (Ubuntu) or /var/log/messages (CentOS)
StandardOutput=syslog
StandardError=syslog
# This will default to "bundler" if we don't specify it
SyslogIdentifier=sidekiq
[Install]
WantedBy=multi-user.target
ExecStart
中提供了正确的bundler路径以启动进程。将其保存为sidekiq.service
并运行systemctl enable sidekiq
。然后,我们可以使用命令systemctl start sidekiq
、systemctl stop sidekiq
和systemctl restart sidekiq
来管理该进程。journalctl -u sidekiq -rn 100
查看日志的最后100行。
-d
选项需要通过-L
选项指定日志文件。之所以分享这个信息是因为我尝试将其转化为守护进程时遇到了错误。 - axilsidekiq.yml
中声明了logfile
,就不需要使用-L
参数。 - mahemoffObjectSpace 被禁用; each_object 只会与 Class 一起工作, 请传递 -X+O 以启用
- RAJ