I'm new to upstart. Below is the upstart config for the "myserver" daemon. It works fine, but I want to execute custom commands when I issue "stop myserver", to cleanly shut it down. start-stop-daemon simply kills the pid of the daemon.
description "My server"
start on filesystem or runlevel [2345]
stop on run level [!2345]
respawn
respawn limit 3 60
env cmd="/home/ubuntu/bin/server -- --config=server_conf.py start"
exec start-stop-daemon --start --chuid ubuntu --chdir /home/ubuntu/bin --exec $cmd