Skip to content

Instantly share code, notes, and snippets.

@TsaiKoga
Created February 19, 2019 02:44
Show Gist options
  • Save TsaiKoga/3cb6d99b07b895a50f51358f2c48472a to your computer and use it in GitHub Desktop.
Save TsaiKoga/3cb6d99b07b895a50f51358f2c48472a to your computer and use it in GitHub Desktop.
Start / Stop / Restart php-fpm easily
#!/bin/sh
param=$1
start() {
fpms=`ps aux | grep -i "php-fpm" | grep -v grep | awk '{print $2}'`
if [ ! -n "$fpms" ]; then
php-fpm
echo "PHP-FPM Start"
else
echo "PHP-FPM Already Start"
fi
}
stop() {
fpms=`ps aux | grep -i "php-fpm" | grep -v grep | awk '{print $2}'`
echo $fpms | xargs kill -9
for pid in $fpms; do
if echo $pid | egrep -q '^[0-9]+$'; then
echo "PHP-FPM Pid $pid Kill"
else
echo "$pid IS Not A PHP-FPM Pid"
fi
done
}
case $param in
'start')
start;;
'stop')
stop;;
'restart')
stop
start;;
*)
echo "Usage: ./phpfpm.sh start|stop|restart";;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment