Below is a upstart script for redis. How to I create a pid so I use monit for monitoring?
#!upstart
description "Redis Server"
env USER=redis
start on startup
stop on shutdown
respawn
exec sudo -u $USER sh -c "/usr/local/bin/redis-server /etc/redis/redis.conf 2>&1 >> /var/log/redis/redis.log"
If start-stop-daemon is available on your machine, I would highly recommend using it to launch your process. start-stop-daemon will handle launching the process as an unprivileged user without forking from sudo or su (recommended in the upstart cookbook) AND it also has built in support for pid file management. Eg:
/etc/init/app_name.conf
Alternatively you could manually manage the pid file by using the
post-start scriptstanza to create it andpost-stop scriptstanza to delete it. Eg:/etc/init/app_name.conf