From your mention of Upstart, I will assume that this question is for a service running on an Ubuntu server.
On an Ubuntu server, a higher task is the easiest and most convenient option to always create a service that starts at the right time and can be stopped or restarted by familiar commands.
To create an upstart service, you need to add one file to /etc/init . <service-name>.conf called. An example script looks like this:
description "My chat server" author "your@email-address.com" start on runlevel [2345] stop on runlevel [!2345] env AN_ENVIRONMENTAL_VARIABLE=i-want-to-set respawn exec /srv/applications/chat.py
This means that every time the machine starts, it starts the chat.py program. If he dies for any reason, he will restart it. You donβt need to worry about double forcing or otherwise demonizing your code. It was an upstart for you.
If you want to stop or start your process, you can do it with
service chat start service chat stop
The chat name will be automatically found from the .conf file name inside /etc/init
I only cover the basics of the upstart here. There are many other possibilities to make it even more useful. Everything is available by running man upstart .
This method is much more convenient than writing your own demonization code. The 4-8 line configuration file for the Ubuntu built-in component is much less error prone than the secure double fork code and then another process monitor to make sure it does not disappear.
Monit is a little red herring. If you want downtime alerts, you still need to run the monitoring program on a separate server. Rely on the upstart so that the process always runs on the server. Then run another service that ensures that the server is actually running. Downtime occurs for various reasons. A process running on the same server will not tell you anything if the server itself goes down. You need a separate machine (or a third-party vendor such as pingdom) to warn you of this condition.
aychedee Jul 24. '13 at 14:02 2013-07-24 14:02
source share