Reputation: 492
I exported an upstart script via foreman, and I added a line to the .conf file to send an email if the process was restarted. However, when ever I kill the process to test the functionality, it spams my inbox with over 20 emails. Does anyone know if there is a more efficient way of doing this, or am I SOL?
start on starting square-web
stop on stopping square-web
respawn
exec su - deployer -c 'cd /rails/square; echo "Thin 5000 restarted on square.local" | mail [email protected]; export PORT=5000; export RAILS_ENV=production; rails s thin -p $PORT >> /var/log/square/web-1.log 2>&1'
Upvotes: 2
Views: 327
Reputation: 1115
The problem is most likely that rails is hanging on to the listen socket for a little while. This will happen especially if it takes more than 5 seconds to close down all of the sockets and die from SIGTERM, as after that upstart will send SIGKILL which will leave those sockets all in TIME_WAIT.
If you can get your listener to use SO_REUSEADDR then this goes away as you'll just take back the TIME_WAIT listening port. You may also want to raise the kill timeout if you expect things to take longer than 5 seconds:
kill timeout 20
If you just want to reduce the spam, you can just have your job sleep a bit to give the OS time to shut down the listening socket:
post-stop exec sleep 1
Upvotes: 1