#!/bin/env/bash
SHELL_DIR=$(cd "$(dirname "$0")";pwd)
opt="${@:2}"
echo "shell dir: $SHELL_DIR, arguments:$opt"
psid=
checkpid() {
psid=`ps -ef | grep 'php-fpm' | grep -v 'grep' | grep -v 'sh' | awk '{print $2}' | tr '\n' ' '`
echo "psid: $psid"
}
start() {
echo "starting..."
checkpid
if [ ${#psid} -ne 0 ]; then
echo "================================"
echo "warn: php-fpm already started! (pid=$psid)"
echo "================================"
else
echo "============ Start ============="
echo "starting php-fpm ..."
php-fpm $opt
checkpid
if [ ${#psid} -ne 0 ]; then
echo "php-fpm started successfully!"
else
echo "php-fpm started failed!"
fi
fi
}
stop() {
checkpid
if [ ${#psid} -ne 0 ]; then
echo "killing pid -> "$psid
kill -9 $psid
checkpid
if [ ${#psid} -ne 0 ]; then
echo "php-fpm stopped failed!"
else
echo "php-fpm stopped successfully!"
fi
else
echo "================================"
echo "warn: php-fpm is not running!"
echo "================================"
fi
}
status() {
checkpid
if [ ${#psid} -ne 0 ]; then
echo "php-fpm is running!"
else
echo "php-fpm is not running!"
fi
}
echo "running $1 command as $USER"
case "$1" in
'start')
start
;;
'stop')
stop
;;
'restart')
stop
start
;;
'status')
status
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac
exit 0
网友评论