Created
July 12, 2017 09:12
-
-
Save madumlao/5150a69e8c214207ea382c5e588bef33 to your computer and use it in GitHub Desktop.
phpenv / php-fpm init script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# start/stop php-fpm app server | |
### BEGIN INIT INFO | |
# Provides: php-fpm | |
# Required-Start: $remote_fs $network $syslog | |
# Required-Stop: $remote_fs $network $syslog | |
# Should-Start: $named | |
# Should-Stop: $named | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Start the php-fpm app server | |
# Description: Start the php-fpm app server | |
### END INIT INFO | |
# substitute the user / home dir / path that php-fpm will run in | |
USER=madumlao | |
NAME=myproject | |
PATH=/sbin:/bin:/usr/sbin:/usr/bin | |
PREFIX="/home/$USER" | |
APP_DIR="$PREFIX/public_html" | |
FPM_CONFIG="$PREFIX/etc/php-fpm.conf" | |
PHP_CONFIG="$PREFIX/etc/php.ini" | |
PIDFILE="$PREFIX/var/run/php-fpm.pid" | |
. /lib/lsb/init-functions | |
set -e | |
test -x $DAEMON || exit 0 | |
if [ "$(id -u)" != "0" ]; then | |
echo "Must be root" | |
exit 1 | |
fi | |
case "$1" in | |
start) | |
echo "Starting $NAME app server " | |
sudo -iu $USER <<-ENDSUDO | |
cd $APP_DIR | |
php5-fpm --prefix "$PREFIX" --fpm-config "$FPM_CONFIG" -c "$PHP_CONFIG" | |
ENDSUDO | |
;; | |
stop) | |
echo "Stopping $NAME app server " | |
sudo -iu $USER <<-ENDSUDO | |
cd $APP_DIR | |
if [ -f "$PIDFILE" ] && kill -0 \$(cat $PIDFILE) 2>/dev/null; then | |
echo "killing \$(cat $PIDFILE)" | |
kill \$(cat $PIDFILE) | |
else | |
echo "No servers running" | |
fi | |
ENDSUDO | |
;; | |
restart) | |
$0 stop | |
$0 start | |
;; | |
reload|force-reload) | |
$0 restart | |
;; | |
status) | |
sudo -iu $USER <<-ENDSUDO | |
cd $APP_DIR | |
if [ -f "$PIDFILE" ] && kill -0 \$(cat $PIDFILE) 2>/dev/null; then | |
echo "Server running as pid \$(cat $PIDFILE)" | |
else | |
echo "No servers running" | |
fi | |
ENDSUDO | |
;; | |
*) | |
N=/etc/init.d/$NAME | |
echo "Usage: $N {start|stop|restart|reload|force-reload|status}" >&2 | |
exit 1 | |
;; | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment