Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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!

share|improve this question

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
share|improve this answer
    
But that would be run at every start, right? I think the question is only after a respawn, as opposed to a normal start. – David Ammouial Jan 27 at 2:36

You could add a mail command inside your script or write a wrapper script that does that and then calls your script. Then you'd have Upstart use your wrapper script.

echo 'Script scriptname respawned' | mail -s "respawn notice" foo@example.com
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.