Pascal Dreissen
2016-07-08 a481a62a13c241df0b3269f7f915789f4451d51b
commit | author | age
c59632 1 #!/bin/bash
MC 2 #
3 # /etc/init.d/hhvm_{SYSTEM_USER}
4 #
5 ### BEGIN INIT INFO
6 # Provides:          hhvm_{SYSTEM_USER}
7 # Required-Start:    $remote_fs $network
8 # Required-Stop:     $remote_fs $network
9 # Default-Start:     2 3 4 5
10 # Default-Stop:      0 1 6
11 # Description:       Starts The HHVM FastCGI Daemon
12 ### END INIT INFO
13 PATH=/sbin:/usr/sbin:/bin:/usr/bin
14 DESC="HHVM FastCGI Daemon"
15 NAME=hhvm
16
17 do_start()
18 {
1c6da3 19     if [ ! -d /var/run/hhvm ]; then
1b0683 20         mkdir -p -m0777 /var/run/hhvm
MC 21     else
22         chmod 777 /var/run/hhvm
23     fi
24     
25     if [[ -e "/var/run/hhvm/hhvm_{SYSTEM_USER}.pid" ]] ; then
26         kill -0 `cat /var/run/hhvm/hhvm_{SYSTEM_USER}.pid` >/dev/null 2>&1 ;
27         case "$?" in
28             0)
29                 return 1
30                 ;;
31         esac
32     fi
33     
d71067 34     if [[ -S /var/run/mysqld/mysqld.sock && ! -S /tmp/mysql.sock ]] ; then
MC 35         ln -s /var/run/mysqld/mysqld.sock /tmp/mysql.sock ;
36     fi
37     
d22277 38     umask 022
1b0683 39     sudo -u {SYSTEM_USER} touch /var/run/hhvm/hhvm_{SYSTEM_USER}.pid
d5f2d5 40     
MC 41     BASEINIFILE=""
42     if [[ -e "/etc/hhvm/php.ini" ]] ; then
43         BASEINIFILE="--config /etc/hhvm/php.ini" ;
44     fi
45     
9d9ea6 46     INIFILE=""
MC 47     if [[ -e "/var/www/conf/{SYSTEM_USER}/php.ini" ]] ; then
d5f2d5 48         INIFILE="--config /var/www/conf/{SYSTEM_USER}/php.ini" ;
9d9ea6 49     elif [[ -e "/etc/php5/hhvm/php.ini" ]] ; then
d5f2d5 50         INIFILE="--config /etc/php5/hhvm/php.ini" ;
MC 51     elif [[ -e "/etc/php5/fpm/php.ini" ]] ; then
52         INIFILE="--config /etc/php5/fpm/php.ini" ;
9d9ea6 53     elif [[ -e "/etc/php5/cgi/php.ini" ]] ; then
d5f2d5 54         INIFILE="--config /etc/php5/cgi/php.ini" ;
9d9ea6 55     fi
d5f2d5 56     
MC 57     CUSTOMINIFILE=""
58     if [[ -e "/etc/hhvm/{SYSTEM_USER}.ini" ]] ; then
59         CUSTOMINIFILE="--config /etc/hhvm/{SYSTEM_USER}.ini" ;
60     fi
61     
404c72 62     /usr/bin/hhvm --mode daemon -vServer.Type=fastcgi --user {SYSTEM_USER} -vServer.FileSocket=/var/run/hhvm/hhvm.{SYSTEM_USER}.sock -vLog.Level=Warning -vLog.UseLogFile=false -vRepo.Central.Path=/var/run/hhvm/hhvm.{SYSTEM_USER}.hhbc -vServer.FixPathInfo=true $BASEINIFILE $INIFILE $CUSTOMINIFILE -vPidFile=/var/run/hhvm/hhvm_{SYSTEM_USER}.pid & echo $! > /var/run/hhvm/hhvm_{SYSTEM_USER}.pid
c59632 63 }
MC 64
65 do_stop()
66 {
1c6da3 67     if [[ -e "/var/run/hhvm/hhvm_{SYSTEM_USER}.pid" ]] ; then
MC 68         kill -SIGTERM `cat /var/run/hhvm/hhvm_{SYSTEM_USER}.pid` >/dev/null 2>&1 ;
69     fi
70     rm -f /var/run/hhvm/hhvm.{SYSTEM_USER}.sock /var/run/hhvm/hhvm.{SYSTEM_USER}.hhbc /var/run/hhvm/hhvm_{SYSTEM_USER}.pid
c59632 71 }
MC 72
73 case "$1" in
1b0683 74     start)
MC 75         do_start
76         ;;
77     stop)
78         do_stop
79         ;;
80     restart|force-reload)
81         do_stop
82         case "$?" in
83             0|1)
84                 do_start
85                 ;;
86             *)
87                 ;;
88         esac
89         ;;
90     *)
91         exit 3
92         ;;
c59632 93 esac
MC 94
95 :