简体   繁体   中英

Cron for restarting a service when it fails on Amazon EC2 Ubuntu instance

I have made a service which contains some redis operations and node scripts on a ubuntu Amazon Ec2 instance. However when there are any errors the service stops with a pid.

I need a cron job to do the following :

  1. detect when service has failed
  2. delete the pid
  3. restart the service

I have seen that cron can be created for time interval but have not come across if this can be done for service fail scenarios as well . Any hints and answers on this will be very helpful .

You can use Forever . From their page:

A simple CLI tool for ensuring that a given script runs continuously (ie forever).

The usage is quite simple:

forever start your_app.js

You can read the documentation in their page: Forever - Github . You have several examples here: Forever examples .

There are other alternatives:

  1. Monit: http://mmonit.com/monit/
  2. Upstart: http://upstart.ubuntu.com/
  3. Daemontools: http://cr.yp.to/daemontools.html
  4. Launchtool: http://people.debian.org/~enrico/launchtool.html

Other alternatives I like (which they're not written in Node.js) are:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM