Skip to main content

Does anyone have tips on setting up redis and sidekiq on a Digital Ocean ubuntu 16.04 droplet?

Rails • Asked by Lance Williams


I have no trouble setting up redis but for some reason I can't get sidekiq to work. I can get sidekiq and redis to work locally on a mac using brew but not on a Digital Ocean Ubuntu 16.04 server.

I'm currently using sucker_punch for running transactional email jobs but I would love to figure out how to set up Redis and Sidekiq on a Digital Ocean Droplet.

Does anyone have any tips or resources you've used to set this up?

Gravatar Chris Oliver commented on : Mod Staff

Basically at this point now, you'll need to use systemd to manage Sidekiq. It will make sure it starts or if it dies, it will restart it. This is nice, but kind of confusing sometimes how to get it setup.

I have this in /etc/systemd/system/sidekiq.service and you can enable it and manage it using the commands at the top there.

#
# systemd unit file for CentOS 7, Ubuntu 15.04
#
# Customize this file based on your bundler location, app directory, etc.
# Put this in /usr/lib/systemd/system (CentOS) or /lib/systemd/system (Ubuntu).
# 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).
#
# See Inspeqtor's Systemd wiki page for more detail about Systemd:
# https://github.com/mperham/inspeqtor/wiki/Systemd
#
[Unit]
Description=sidekiq
# start us only once the network and logging subsystems are available,
# consider adding redis-server.service if Redis is local and systemd-managed.
After=syslog.target network.target

# See these pages for lots of options:
# http://0pointer.de/public/systemd-man/systemd.service.html
# http://0pointer.de/public/systemd-man/systemd.exec.html
[Service]
Type=simple
WorkingDirectory=/home/deploy/myapp/current
# If you use rbenv:
ExecStart=/home/deploy/.rbenv/shims/bundle exec "sidekiq -e production"
User=deploy
Group=deploy
UMask=0002

# 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

Not that you'll need to change the WorkingDirectory option for the location of your app and this assumes you're using rbenv on your server for running Ruby.

Chris answered this well, but there's also another option of using the God gem to manage sidekiq which I believe is based off of bluepill. Either way will work, but systemd can handle this as Chris mentioned.

Gravatar Chris Oliver commented on : Mod Staff

Yeah, there's a few options like that. I like not having to add another dependency, plus this is nice if you're already us it to run things like Redis, etc.

Gravatar Jack commented on :

Not sure what you're usage is, but unless you're doing lots of (heavy) backgrounding I would stick with sucker_punch. Sidekiq adds quite a lot of extras which I am not sure is worth the time.

Now if you just want to learn how to do it, I am happy to give some pointers though :)


Edit: Ah, lots of valuable stuff already . 👍

Thanks for the helpful insight. I'll definitely do some set up practice on a droplet to test everything out. Yeah, I was struggling with the systemd configuration file. This helps tremendously.

And Jack thanks for pointing out the reason maybe to just stick with sucker_punch. I'll test it all out and see what makes the most sense.

Shakycode, I'll definitely take a look at the God gem as well.

I was mainly just frustrated that I couldn't figure out the Sidekiq setup.

Thanks for all the pointers!

Login or create an account to join the conversation.