Upstart Boilerplate for Background Workers
I use foreman to run background work process when developing.
After writing the Procfile
, we can export it to many process management through foreman export
command.
The generated files never worked well for me (when exporting to Upstart). Very likely because rbenv or RVM is not loaded.
Here is the boilerplate I've used:
Note:
- Replace
ironman
by the name of your application - Replace
deploy
by your server's user - Replace
/var/log/ironman/
by your log path - Replace
/path/to/ironman
by the path of your application - Replace
staging
(inexport RAILS_ENV=staging;
) by your application environment - Replace
bundle exec sidekiq
by the command you wanna run (bundle exec rake resque:work QUEUE=communication,normal
for instance)
Place these files in /etc/init
, then you can use sudo service ironman
to start
, stop
etc.
ironman-clock.conf
and ironman-clock-1.conf
.You will want to restart the workers after deploying new code (to reload application). But if your user isn't root, you have no permission to run sudo service ironman restart
.
To solve it, I grant permission to my application user. Run sudo visudo
and add the following:
deploy
(server's user) and ironman
here again.That is it, thanks.