(may be useful for other Raspberry Pi services)
A couple of days ago I blogged about getting Cassandra running on a Raspberry Pi, a fairly straight forward procedure! However the way I had it set up required Cassandra to be restarted manually each time the Pi was turned on which is not ideal. We really want our Cassandra to start each time the Pi is started and to run as a service in the background. Services on Debian (which I am using) are defined in Init.d and are managed by the update-rc.d command. So, we need a command script to put into /etc/init.d that will be run when the Pi restarts. There is an example script at: http://www.jansipke.nl/centos-cassandra-init-start-stop-script/ but for the pi this has a number of problems.
The first problem is that the script uses the daemon command to run the Cassandra script. This command does not exist under Debian instead we will need to use the start-stop-daemon command. Instead of :
daemon $CASSANDRA_BIN -p $CASSANDRA_PID >> $CASSANDRA_LOG 2>&1
we will use:
start-stop-daemon --start --pidfile $CASSANDRA_PID --startas $CASSANDRA_BIN -p $CASSANDRA_PID >> $CASSANDRA_LOG 2>&1
The second problem is that usleep doesn’t exist under this Debian, use “sleep 0.500000” instead. Finally we will need to add the java path and java_home to the start of the file:
The full file is available on github here: https://github.com/acobley/CassandraStartup. Remember you will need to change the variables that point to the locations of Cassandra and it’s PID file and lock file. Once the file is copied to /etc/init.d (remember to change I so it’s executable “sudo chmod +x Cassandra”) you can use update-rc.d to add it to all the /etc/rc?.d files:
update-rc.d cassandra defaults
No doubt this procedure and the Cassandra file can be improved !
For more info on the update-rc.d file see: http://www.debuntu.org/how-to-manage-services-with-update-rc.d