I have an app (in the form of a single binary) that I need to run on one of my servers, and I'd like to be able to control its lifecycle properly. What I'd like is the following:
- simple one command start/stop/restart
- as little configuration as possible, I don't want to setup big things like monit, or write 500 lines of shell scripts
- handle stdout/stderr/failures in a log file
- manage a pidfile in a way that there only is a pid file if the process is running (this seems to be really hard to do by hand using shell scripts correctly)
- (optional) be able to do something if the binary crashes
- (optional) start automatically if the server reboots and/or the application crashes
What I'm looking for is a lightweight solution that ideally works with Ubuntu Server out of the box, without much configuration.
For Ubuntu, I think Upstart is what you are looking for.
https://askubuntu.com/questions/19320/how-to-enable-or-disable-services This AskUbuntu question has excellent info on getting started with what you are doing.
In a nutshell, copy the following to /etc/init/mybinary.conf.
This should get you going with the following:
The Upstart cookbook as all the info you'll need: http://upstart.ubuntu.com/cookbook/
As an aside, I feel I should mention Ubuntu is planning to retire Upstart in favour of Systemd, but no roadmap is laid out.