0

I am using UPSTART to restart my executable if by any chance it goes down and it works fine.

start on runlevel [2345]
stop on runlevel [016]

chdir /opt/data/data_server
respawn

post-stop script
  sleep 30
end script

limit nofile 8092 8092
setuid david
exec ./data_server --file=../config/property.init --data_port=8080

Is there any way we can add another feature which is to send out an email (as my program went down and going to be restarted) if my executable goes down and then restart it in the same UPSTART config? I am not sure whether there is any way to do that using the same UPSTART config.

I want to send an email from [email protected] to [email protected] with a simple message that my program went down at this time and also as soon as my program is restarted then I want to send another email that my program got restarted at this time.

1 Answer 1

1

You could try something like this:

start on runlevel [2345]
stop on runlevel [016]

chdir /opt/data/data_server
respawn

post-start script
    echo "Service Started at `date +"%F %T"` on `hostname`" | mail -s "Service Started" [email protected]
end script

post-stop script
  sleep 30
end script

limit nofile 8092 8092
setuid david
exec ./data_server --file=../config/property.init --data_port=8080

The hostname command in the echo will print the server's hostname so you should be able to tell in the email what server it was restarted on.

4
  • Thanks for suggestion. Where I will fit this in my above script? Can we also not add who is sending the email? Commented Feb 10, 2015 at 20:57
  • @david I updated my post, see if that makes more sense to you. Let me know if not. Commented Feb 10, 2015 at 21:05
  • got the idea now. In your post-start script, I can see hostname from where it gets hostname? Or is it some predefined function to get the hostname Commented Feb 10, 2015 at 21:18
  • @david hostname is a linux command, you can type hostname in your terminal and you should see the desired output. man hostname for more information: hostname - show or set the system’s host name. You can also test the echo in your terminal while testing the mail feature but just running it in terminal: echo "Service Started at `date +"%F %T"` on `hostname`" | mail -s "Service Started" [email protected] Commented Feb 10, 2015 at 21:26

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.