Skip to content

Instantly share code, notes, and snippets.

@sj26
Forked from dsadaka/\lib\systemd\system\sidekiq-static.service
Last active July 4, 2023 19:20
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save sj26/5d6d0bff1adf06d2ef2f1468cd9d3402 to your computer and use it in GitHub Desktop.
Save sj26/5d6d0bff1adf06d2ef2f1468cd9d3402 to your computer and use it in GitHub Desktop.
systemd unit files for multiple sidekiq workers
[Unit]
Description=Sidekiq workers
# start as many workers as you want here
Wants=sidekiq@1.service
Wants=sidekiq@2.service
# ...
[Service]
Type=oneshot
ExecStart=/bin/true
RemainAfterExit=true
[Unit]
Description=Sidekiq worker %I
# restarts/stops with sidekiq
PartOf=sidekiq.service
After=network.target
[Service]
# Run as a systemd notify service with watchdog support (sidekiq v6.0.6+)
Type=notify
WatchdogSec=5
# Modify to your application user/group/pwd
User=app
Group=app
UMask=0002
WorkingDirectory=/app
ExecStart=/app/bin/sidekiq -C config/sidekiq.yml -e production
# restart & stop send TERM to main process, wait up to 30 seconds, then KILL if still running
KillMode=mixed
TimeoutStopSec=30
# restart on non-zero exit or other failure after 5 seconds
Restart=on-failure
RestartSec=5
# don't create a new systemd.slice per instance
Slice=system.slice
@collimarco
Copy link

Thanks for this!

What command do you use to quiet all the sidekiq workers at once (e.g. before a capistrano deploy)?
I used this for a single process: pgrep -f 'sidekiq' | xargs kill -USR1

What command do you use to restart all the sidekiq processes at once (e.g. after a capistrano deploy)?
I used this for a single process: sudo service sidekiq restart

@sj26
Copy link
Author

sj26 commented Sep 3, 2019

@collimarco most systemctl commands take a pattern, so to quiet you can:

systemctl kill --signal=USR1 "sidekiq@*.service"

and to restart you can:

systemctl restart "sidekiq@*.service"

but because of PartOf=sidekiq.service you can just restart the parent and all the instances will restart, too:

systemctl restart sidekiq.service

which is probably what service restart sidekiq is doing under the hood.

@noorani786
Copy link

Is this still valid and will it work for Ubuntu 20?

@sj26
Copy link
Author

sj26 commented Oct 9, 2021

Probably!

@jpriollaud
Copy link

This is out of date as of April 2023. -i is no longer a flag.
It looks like there is limited guidance other than ~ Sidekiq Pro or Foreman make it really easy.

@sj26
Copy link
Author

sj26 commented Apr 30, 2023

This is out of date as of April 2023. -i is no longer a flag.

I've just removed -i. It was an old option required for sidekiq pro's reliable fetch, but is no longer used.

The rest of the example should work.

@jpriollaud
Copy link

@sj26 very helpful thank you so much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment