Ubuntu,upstart和创建一个pid进行监控

前端之家收集整理的这篇文章主要介绍了Ubuntu,upstart和创建一个pid进行监控前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
下面是redis的upstart脚本。如何创建一个pid,所以我使用monit进行监控?
  1. #!upstart
  2. description "Redis Server"
  3.  
  4. env USER=redis
  5.  
  6. start on startup
  7. stop on shutdown
  8.  
  9. respawn
  10.  
  11. exec sudo -u $USER sh -c "/usr/local/bin/redis-server /etc/redis/redis.conf 2>&1 >> /var/log/redis/redis.log"
如果启动 – 停止 – 守护程序在您的机器上可用,我强烈建议使用它启动您的过程。 start-stop-daemon将处理作为非特权用户启动进程,而不从sudo或su( recommended in the upstart cookbook)分支,并且它还内置支持pid文件管理。例如:

/etc/init/app_name.conf

  1. #!upstart
  2. description "Redis Server"
  3.  
  4. env USER=redis
  5.  
  6. start on startup
  7. stop on shutdown
  8.  
  9. respawn
  10.  
  11. exec start-stop-daemon --start --make-pidfile --pidfile /var/run/app_name.pid --chuid $USER --exec /usr/local/bin/redis-server /etc/redis/redis.conf >> /var/log/redis/redis.log 2>&1

或者,您可以使用启动后脚本节来创建pid文件并使用停止后脚本节来手动管理pid文件。例如:

/etc/init/app_name.conf

  1. #!upstart
  2. description "Redis Server"
  3.  
  4. env USER=redis
  5.  
  6. start on startup
  7. stop on shutdown
  8.  
  9. respawn
  10.  
  11. exec sudo -u $USER sh -c "/usr/local/bin/redis-server /etc/redis/redis.conf 2>&1 >> /var/log/redis/redis.log"
  12.  
  13. post-start script
  14. PID=`status app_name | egrep -oi '([0-9]+)$' | head -n1`
  15. echo $PID > /var/run/app_name.pid
  16. end script
  17.  
  18. post-stop script
  19. rm -f /var/run/app_name.pid
  20. end script

猜你在找的Ubuntu相关文章