aboutsummaryrefslogtreecommitdiff
path: root/network/hiawatha/rc.php-fcgi
blob: a8d4a4f8586c78d2a176237cad1bc72910ed5aaa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/sh

# Start/stop/restart PHP as FastCGI daemon
# Copyright (c) 2009-2011 Antonio Hernández Blas <hba.nihilismus@gmail.com>

#
#            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
#                    Version 2, December 2004
#
# Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>
#
# Everyone is permitted to copy and distribute verbatim or modified
# copies of this license document, and changing it is allowed as long
# as the name is changed.
#
#            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
#   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
#
#  0. You just DO WHAT THE FUCK YOU WANT TO.
#

CONF='/etc/hiawatha/php-fcgi.conf'
CMMD="/usr/sbin/php-fcgi -c $CONF"

php_fcgi_start() {
  if [ -x /usr/sbin/php-fcgi ]; then
    if [ -f $CONF ]; then
      PIDOF=$(pgrep -f /usr/bin/php-cgi)
      if [ ! -z "$PIDOF" ]; then
        echo "Error, PHP as FastCGI daemon is already running."
      else
        echo "Starting PHP as FastCGI daemon:  $CMMD"
        $CMMD
      fi
    else
      echo "Error, file $CONF does not exist."
    fi
  fi
}

php_fcgi_stop() {
  echo "Stoping PHP as FastCGI daemon:  /usr/sbin/php-fcgi -k"
  /usr/sbin/php-fcgi -k
}

php_fcgi_status() {
  PIDOF=$(pgrep -f /usr/bin/php-cgi)
  if [ ! -z "$PIDOF" ]; then
    echo "PHP as FastCGI daemon is running."
  else
    echo "PHP as FastCGI daemon is not running."
  fi
}

case $1 in
  start)
    php_fcgi_start
  ;;
  stop)
    php_fcgi_stop
  ;;
  restart)
    php_fcgi_stop
    sleep 3
    php_fcgi_start
  ;;
  status)
    php_fcgi_status
  ;;
  *)
    echo "Usage $0 {start|stop|restart|status}"
    exit 1
  ;;
esac