The situation: I have a rails app, with sidekiq, working very well, under debian8.
I want an easier control of my sidekiq, so instead of daemonize it with the -d option, I want to create a sidekiq.service
file in /etc/systemd/system/sidekiq.service
.
( So I'll able to sudo systemctl restart sidekiq.service
)
I saw how gitlab do on github, but it's not working for me, because I use rvm to install ruby.
If I do the same with /path/to/rvm/bin/bundle, It returns me an error as "Can't locate Gemfile". ( And I also have run gem install bundler
, previously )
I can launch sidekiq from another directory than my rails app with :
BUNDLE_GEMFILE=/home/me/myapp/Gemfile bundle exec sidekiq --config /home/me/myapp/config/sidekiq.yml --require /home/me/myapp/config/environment.rb
But in my /etc/systemd/system/sidekiq.service at the ExecStart line, I have an error : Executable path is not absolute
Any clue on how I can do it?
Or, maybe it'll be more efficient / simpler, to run sidekiq in a docker container?
I just tried this with systemd on Ubuntu 15.04. (This also works for Upstart on Ubuntu 14.x.) I use RVM's alias command for an absolute path for bundle. I think that it will help to also tell it which directory to be in at the start, as well.
To make a RVM wrapper/alias. From the Rails directory:
so if your gemset name was ruby-2.2.2@awesome_app, and you want your wrapper/alias to be called 'awesome_app', it'd be:
Then in systemd, the full path is something like
PATH=/usr/local/rvm/wrappers/awesome_app/
which makes the ExecStart command this:Edit: I've confirmed that my sidekiq worker is now working properly. Here's my full sidekiq.service file.
Currently I have it monitored with monit. I personally prefer Upstart, since systemd requires password every. single. time. but, like I said, can confirm that this works for me.