This post has started as a research on How to start Sidekiq on a system reboot. After read blogs and try different approaches we ended with Upstart, that is the new way of managing jobs on the Ubuntu platform (Actually not so new, it was included on the standard releases since 10.04 I think). With it you basically define a standard Ubuntu Job and then you can just:
We have a quite standard Rails stack that involves:
- Ubuntu 12.04 LTS
- Sidekiq with Redis
- RVM to manage our ruby versions (with rbenv you can use the example on the official sidekiq github repo)
- Capistrano for deploying the application
The only thing to do in order to get your new job up and running, it’s create a conf file under
/etc/init directory. The file name will be the job name that you will
[start | stop | restart | status] later.
The structure of this file must follow the Upstart DSL (you can see different example on
/etc/init directory and on the official documentation).
For our purpose we are going to create a file
/etc/init/sidekiq.conf so you can run
sudo service sidekiq [start | stop | restart | status] and at the same time we can tell Upstart that it should start everytime the system boot.
On my case I used this example as a starting point adapting it to RVM (note that it uses rbenv). On the other hand this script was not thought to start sidekiq when the OS is booted but that is a quite simple thing, just add
start on startup
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
One more thing that might be helpful is how to debug this in case it doesn’t work on the first try or if you need to adapt it. Well you can just
tail -f /var/log/syslog and see the errors.
That is pritty much it, now your Sidekiq process is being managed as a standard Ubuntu Job.