Run Sidekiq as daemon on Ubuntu
Asked Answered
D

4

21

How can I run sidekiq as daemon on Ubuntu?

If I run bundle exec sidekiq -D I get invalid option: -D, is there any way to run it without some other controller, like god, upstart...?

Dilapidate answered 20/3, 2013 at 10:14 Comment(0)
P
29

there's an option to Daemonize sidekiq, just pass -d option

commit

Puff answered 20/3, 2013 at 10:28 Comment(6)
There's an upstart script in examples/upstart that you should use. Using upstart you'll get respawning and it'll start when you boot - two very useful properties.Stopover
Using -d will need to specify a log file with -L option. Just sharing because I encountered an error when I tried to use it daemonized.Schlessel
@Schlessel Thanks for noting it. As a further data point, I found you don't need the -L arg as long as you have a logfile declared inside sidekiq.yml.Strauss
Doesn't seems to be working for jruby: ObjectSpace is disabled; each_object will only work with Class, pass -X+O to enableMarduk
@Strauss I don't have sidekiq.ymlTotten
Hey and how to stop demonizing?Totten
O
8

As of sidekiq 6.0 Daemonization wouldnt work and if you pass -d, you'll get a message:

Daemonization mode was removed in Sidekiq 6.0, please use a proper process supervisor to start and manage your services

check the issue here #4045

Oyez answered 23/10, 2019 at 4:48 Comment(0)
P
6

Running as daemon won't restart the sidekiq if it crashes unexpectedly. One alternate way could be to run sidekiq as a service (An upstart job). If the system is rebooted than also the upstart job will run sidekiq. Here is the complete script and method to run sidekiq as a service.

After running sidekiq as a service you can simply start/stop/restart sidekiq by command sudo service sidekiq start/stop/restart.

Portray answered 4/3, 2016 at 7:6 Comment(0)
E
1

Daemonization, running a program as Unix, for Sidekiq version 6 or later is not supported. Instead, we have to run the process as a service.

Write a script according to your bundler location, or you can modify the below code snippet and copy the snippet into /usr/lib/systemd/system (CentOS) or /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

Make sure you have given the correct path of your bundler for ExecStart in order to start the process. Save it as sidekiq.service and run systemctl enable sidekiq. Then we can manage the process using the commands systemctl start sidekiq, systemctl stop sidekiq, and systemctl restart sidekiq.

We can see the last 100 lines of log by using journalctl -u sidekiq -rn 100.

Eventuality answered 5/7, 2020 at 9:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.