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?
What is Sidekiq? Sidekiq is a Ruby-written open source job scheduler. It is important to be aware that Sidekiq does not do scheduling by default, it only performs jobs. The Enterprise version comes with outbox scheduling.
To run sidekiq, you will need to open a terminal, navigate to your application's directory, and start the sidekiq process, exactly as you would start a web server for the application itself. When the command executes you will see a message that sidekiq has started.
Sidekiq is a efficient tool to take care backgroud jobs of rails and reuired the support of Redis. Switch to root.
Sidekiq uses simple and efficient background processing. Sidekiq is supported by Redis as a job management tool to process thousands of jobs in a second.
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:
rvm current # grab gemset name
rvm alias create NAME GEMSET_NAME
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:
rvm alias create awesome_app ruby-2.2.2@awesome_app
Then in systemd, the full path is something like PATH=/usr/local/rvm/wrappers/awesome_app/
which makes the ExecStart command this:
ExecStart=/usr/local/rvm/wrappers/awesome_app/bundle exec sidekiq ...
Edit: I've confirmed that my sidekiq worker is now working properly. Here's my full sidekiq.service file.
Description=Sidekiq Background Worker
[Service]
Type=forking
User=rails
Group=rails
WorkingDirectory=/home/deployer/app
Environment=RAILS_ENV=production
GuessMainPID=true
ExecStart=/usr/local/rvm/wrappers/awesome_app/bundle exec "sidekiq -d -L log/sidekiq.log -q mailer,5 -q default -e production >> log/sidekiq.log 2>&1"
ExecStop=/usr/local/rvm/wrappers/awesome_app/bundle exec "sidekiqctl stop /home/deployer/app/tmp/pids/sidekiq.pid >> /home/deployer/app/log/sidekiq.log 2>&1"
[Install]
WantedBy=multi-user.target
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With