Ask A Question

Notifications

You’re not receiving notifications from this thread.

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

Lance Williams asked in Rails

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?

Reply

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.

Reply

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.

Reply

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.

Reply

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!

Reply

Hi
I added a file at /etc/systemd/system/sidekiq.service

[Unit]
Description=sidekiq
After=syslog.target network.target

[Service]
Type=simple
WorkingDirectory=/home/deploy/ezlarm-server/current

ExecStart=/home/deploy/.rbenv/shims/bundle exec "sidekiq -e production"
User=deploy
Group=deploy
UMask=0002

Environment=MALLOC_ARENA_MAX=2

RestartSec=1
Restart=on-failure

StandardOutput=syslog
StandardError=syslog

SyslogIdentifier=sidekiq

[Install]
WantedBy=multi-user.target

not while running

systemctl {start,stop,restart} sidekiq

it gives following errors

==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to start 'stop.service'.
Authenticating as: ,,, (deploy)
Password: 
==== AUTHENTICATION COMPLETE ===
Failed to start stop.service: Unit stop.service not found.
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to start 'restart.service'.
Authenticating as: ,,, (deploy)
Password: 
==== AUTHENTICATION COMPLETE ===
Failed to start restart.service: Unit restart.service not found.
==== AUTHENTICATING FOR org.freedesktop.systemd1.manage-units ===
Authentication is required to start 'sidekiq.service'.
Authenticating as: ,,, (deploy)
Password: 
==== AUTHENTICATION COMPLETE ===

Where did I went wrong?

Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 87,563+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.