Created
March 17, 2016 02:42
-
-
Save franklingu/27e56f9a17e54d77e41c to your computer and use it in GitHub Desktop.
a simple script for serving php scripts
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 | |
| CHILDREN=16 | |
| FASTCGI_USER=vagrant | |
| FASTCGI_GROUP=vagrant | |
| FASTCGI_DIR=$(dirname $(readlink -f $0)) | |
| PID_FILE=$FASTCGI_DIR/php-fastcgi.pid | |
| SOCKET=$FASTCGI_DIR/php-fastcgi.sock | |
| PHP5=/usr/bin/php-cgi | |
| PHP_SCRIPT="/usr/bin/spawn-fcgi -s $SOCKET -P $PID_FILE -C $CHILDREN -u $FASTCGI_USER -g $FASTCGI_GROUP -U vagrant -G vagrant -f $PHP5" | |
| RET_VAL=0 | |
| case "$1" in | |
| start) | |
| if [[ ! -d $FASTCGI_DIR ]] | |
| then | |
| mkdir $FASTCGI_DIR | |
| chown $FASTCGI_USER:$FASTCGI_GROUP $FASTCGI_DIR | |
| chmod 0770 $FASTCGI_DIR | |
| fi | |
| if [[ -r $PID_FILE ]] | |
| then | |
| echo "php-fastcgi already running with PID `cat $PID_FILE`" | |
| RET_VAL=1 | |
| else | |
| $PHP_SCRIPT | |
| RET_VAL=$? | |
| fi | |
| ;; | |
| stop) | |
| if [[ -r $PID_FILE ]] | |
| then | |
| kill `cat $PID_FILE` | |
| rm $PID_FILE | |
| RET_VAL=$? | |
| else | |
| echo "Could not find PID file $PID_FILE" | |
| RET_VAL=1 | |
| fi | |
| ;; | |
| restart) | |
| if [[ -r $PID_FILE ]] | |
| then | |
| kill `cat $PID_FILE` | |
| rm $PID_FILE | |
| RET_VAL=$? | |
| else | |
| echo "Could not find PID file $PID_FILE" | |
| fi | |
| $PHP_SCRIPT | |
| RET_VAL=$? | |
| ;; | |
| status) | |
| if [[ -r $PID_FILE ]] | |
| then | |
| echo "php-fastcgi running with PID `cat $PID_FILE`" | |
| RET_VAL=$? | |
| else | |
| echo "Could not find PID file $PID_FILE, php-fastcgi does not appear to be running" | |
| fi | |
| ;; | |
| *) | |
| echo "Usage: php-fastcgi {start|stop|restart|status}" | |
| RET_VAL=1 | |
| ;; | |
| esac | |
| exit $RET_VAL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment