I’ve got a Currentcost Envi device connected to my Viglen MPC-L. A python script runs on a loop parsing the data from the serial cable and sending it to a remote Mosquitto instance. The problem is that the exception catching bits aren’t very good..in fact they are rubbish. I should just take some time and effort to improve the script, but I’ve got the attention span of….oooh, there’s a birdy out of the window. Anyway, at the moment the script falls over once a day or so, and stays that way until I restart it (via a screen session).
I’ve looked at a number of approaches, including monit, but have never got any of them to work very well. So step forward Upstart. From the website -
Upstart is an event-based replacement for the
/sbin/initdaemon which handles starting of tasks and services during boot, stopping them during shutdown and supervising them while the system is running.
You can add a service to upstart by adding a configuration file to /etc/init/ and then running “sudo initctl reload”.
Here’s my config file for my python script
description “CurrentCost Monitor”
author “meeee!”
start on runlevel[234]
stop on runlevel[0156]
script
chdir /usr/bin/scripts
exec /usr/bin/python currentcost.py
end script
respawn
There’s probably more in there than there needs to be, but so far it’s been working for a week with no problems, so I guess I’ve got a working solution.
Anyway, a big thanks to Upstart and the team that are working on it!