How to receive an email when an upstart monitored script respawns

upstart

My upstart config looks something like this

start on filesystem
stop on runlevel S

respawn

exec /path/to/my/script

When this script dies and is respawned I would like to receive an email. Is this possible, or am I using the wrong tool for the job?

Thanks!

Best Answer

You could write a post-start stanza to send e-mail(s).

# An Upstart script to manage the foo service
respawn

post-start script
    echo "my-foo service started at `date +"%F %T.%N"`" | mail -s "My-foo Service Started" me@mydomain.org
    echo "my-foo service started at `date +"%F %T"`" | mail -s "My-foo Service Started" them@theirdomain.org
end script

exec -u foo-user /usr/local/bin/foo
Related Topic