As @vnp pointed out, the sleep 1
calls are dodgy, I did not fix that. To fix that, look for pid
files created by those services, and use them to check if the service is still running or not.
As @vnp pointed out, the sleep 1
calls are dodgy, I did not fix that. To fix that, look for pid
files created by those services, and use them to check if the service is still running or not.
Ideally, you should standardize everything: make it possible to start/stop/restart your custom php-fpm
and nginx
just like other services. That way you can remove the service-specific logic from this script (doesn't really belong here anyway), and then it can work for any service you throw at it. Unfortunately I don't know enough Ubuntu to guide you, but I'm sure the guys on askubuntu.com askubuntu.com can help with that.
Ideally, you should standardize everything: make it possible to start/stop/restart your custom php-fpm
and nginx
just like other services. That way you can remove the service-specific logic from this script (doesn't really belong here anyway), and then it can work for any service you throw at it. Unfortunately I don't know enough Ubuntu to guide you, but I'm sure the guys on askubuntu.com can help with that.
Ideally, you should standardize everything: make it possible to start/stop/restart your custom php-fpm
and nginx
just like other services. That way you can remove the service-specific logic from this script (doesn't really belong here anyway), and then it can work for any service you throw at it. Unfortunately I don't know enough Ubuntu to guide you, but I'm sure the guys on askubuntu.com can help with that.
#!/bin/sh -e
NGINX=/home/prahlad/programs/nginx-1.6.0/sbin/nginx
PHP=/home/prahlad/programs/php-5.4/sbin/php-fpm
PHP_NAME=$(basename $PHP)
startstop_service() {
cmd=1ドル
name=2ドル
sudo service $name $cmd
}
startstop_nginx() {
cmd=1ドル
case $cmd in
stop) $NGINX -s stop ;;
start) $NGINX ;;
restart)
$NGINX -s stop
sleep 1
$NGINX
;;
esac
}
startstop_php() {
cmd=1ドル
case $cmd in
stop) pkill $PHP_NAME ;;
start) $PHP ;;
restart)
pkill $PHP_NAME
sleep 1
$PHP
;;
esac
}
case "1ドル" in
start|stop|restart) cmd=1ドル ;;
*)
shift
servicenames=${@-servicenames}
echo "usage: 0ドル [start|stop|restart] servicenames";$servicenames"
exit 1
esac
shift
for name; do
case "$name" in
php-fpm) startstop_php $cmd ;;
nginx) startstop_nginx $cmd ;;
*) startstop_service $cmd $name ;;
esac
done
#!/bin/sh -e
NGINX=/home/prahlad/programs/nginx-1.6.0/sbin/nginx
PHP=/home/prahlad/programs/php-5.4/sbin/php-fpm
PHP_NAME=$(basename $PHP)
startstop_service() {
cmd=1ドル
name=2ドル
sudo service $name $cmd
}
startstop_nginx() {
cmd=1ドル
case $cmd in
stop) $NGINX -s stop ;;
start) $NGINX ;;
restart)
$NGINX -s stop
sleep 1
$NGINX
;;
esac
}
startstop_php() {
cmd=1ドル
case $cmd in
stop) pkill $PHP_NAME ;;
start) $PHP ;;
restart)
pkill $PHP_NAME
sleep 1
$PHP
;;
esac
}
case "1ドル" in
start|stop|restart) cmd=1ドル ;;
*) echo "usage: 0ドル [start|stop|restart] servicenames"; exit 1
esac
shift
for name; do
case "$name" in
php-fpm) startstop_php $cmd ;;
nginx) startstop_nginx $cmd ;;
*) startstop_service $cmd $name ;;
esac
done
#!/bin/sh -e
NGINX=/home/prahlad/programs/nginx-1.6.0/sbin/nginx
PHP=/home/prahlad/programs/php-5.4/sbin/php-fpm
PHP_NAME=$(basename $PHP)
startstop_service() {
cmd=1ドル
name=2ドル
sudo service $name $cmd
}
startstop_nginx() {
cmd=1ドル
case $cmd in
stop) $NGINX -s stop ;;
start) $NGINX ;;
restart)
$NGINX -s stop
sleep 1
$NGINX
;;
esac
}
startstop_php() {
cmd=1ドル
case $cmd in
stop) pkill $PHP_NAME ;;
start) $PHP ;;
restart)
pkill $PHP_NAME
sleep 1
$PHP
;;
esac
}
case "1ドル" in
start|stop|restart) cmd=1ドル ;;
*)
shift
servicenames=${@-servicenames}
echo "usage: 0ドル [start|stop|restart] $servicenames"
exit 1
esac
shift
for name; do
case "$name" in
php-fpm) startstop_php $cmd ;;
nginx) startstop_nginx $cmd ;;
*) startstop_service $cmd $name ;;
esac
done