Supervisord中控制upstart jobs

supervisord是很好用的进程管理工具,我们可以将一些service放入其中,这样不用通过ssh,只通过网页就可以控制服务的启动停止,查看状态了。

以下是添加php fpm的脚本:

#! /bin/bash


NAME=php5-fpm


function term_service() {
  sudo service $NAME stop
  echo "Service termed normally!"
  exit 0
}


function check_started() {
  sudo service $NAME status 2>/dev/null 1>/dev/null && echo "WARNING: Service ${NAME} is launched before!"
}


function start_service() {
  sudo service $NAME start 2>/dev/null 1>/dev/null &&
  sudo service $NAME status 1>/dev/null 2>/dev/null &&
  echo "Service ${NAME} launched!"
}


function start_fail() {
  echo "Service ${NAME} failed at start!"
  exit 0
}


function fail_unexpected() {
  echo "Service $NAME exit unexpectedly!"
  exit 0
}


trap 'term_service' TERM


echo "PID = $$"
check_started || start_service || start_fail
while [ 1 ]; do
  sleep 1
  sudo service $NAME status 2>/dev/null 1>/dev/null || fail_unexpected
done

你可能感兴趣的:(supervisord,php-fpm)