xref: /PHP-7.0/sapi/phpdbg/phpdbg.init.d (revision cee72c13)
1 ################################################################
2 # File:         /etc/init.d/phpdbg                             #
3 # Author:       krakjoe                                        #
4 # Purpose:      Daemonize phpdbg automatically on boot         #
5 # chkconfig:    2345    07 09                                  #
6 # description:  Starts, stops and restarts phpdbg daemon       #
7 ################################################################
8 LOCKFILE=/var/lock/subsys/phpdbg
9 PIDFILE=/var/run/phpdbg.pid
10 STDIN=4000
11 STDOUT=8000
12 ################################################################
13 # Either set path to phpdbg here or rely on phpdbg in ENV/PATH #
14 ################################################################
15 if [ "x${PHPDBG}" == "x" ]; then
16 	PHPDBG=$(which phpdbg 2>/dev/null)
17 fi
18 ################################################################
19 # Options to pass to phpdbg upon boot                          #
20 ################################################################
21 OPTIONS=
22 LOGFILE=/var/log/phpdbg.log
23 ################################################################
24 #     STOP EDITING STOP EDITING STOP EDITING STOP EDITING      #
25 ################################################################
26 . /etc/rc.d/init.d/functions
27 RETVAL=1
28 ################################################################
29 insanity()
30 {
31 	if [ "x${PHPDBG}" == "x" ]; then
32 		PHPDBG=$(which phpdbg 2>>/dev/null)
33 		if [ $? != 0 ]; then
34 			echo -n $"Fatal: cannot find phpdbg ${PHPDBG}"
35 			echo_failure
36 			echo
37 			return 1
38 		fi
39 	else
40 		if [ ! -x ${PHPDBG} ]; then
41 			echo -n $"Fatal: cannot execute phpdbg ${PHPDBG}"
42 			echo_failure
43 			echo
44 			return 1
45 		fi
46 	fi
47 
48 	return 0
49 }
50 
51 start()
52 {
53 	insanity
54 
55 	if [ $? -eq 1 ]; then
56 		return $RETVAL
57 	fi
58 
59 	echo -n $"Starting: phpdbg ${OPTIONS} on ${STDIN}/${STDOUT} "
60 	nohup ${PHPDBG} -l${STDIN}/${STDOUT} ${OPTIONS} 2>>${LOGFILE} 1>/dev/null </dev/null &
61 	PID=$!
62 	RETVAL=$?
63 	if [ $RETVAL -eq 0 ]; then
64 		echo $PID > $PIDFILE
65 		echo_success
66 	else
67 		echo_failure
68 	fi
69 	echo
70 	[ $RETVAL = 0 ] && touch ${LOCKFILE}
71 	return $RETVAL
72 }
73 
74 stop()
75 {
76 	insanity
77 
78 	if [ $? -eq 1 ]; then
79 		return $RETVAL
80 	fi
81 
82 	if [ -f ${LOCKFILE} ] && [ -f ${PIDFILE} ]
83 	then
84 		echo -n $"Stopping: phpdbg ${OPTIONS} on ${STDIN}/${STDOUT} "
85 		kill -s TERM $(cat $PIDFILE)
86 		RETVAL=$?
87 		if [ $RETVAL -eq 0 ]; then
88 			echo_success
89 		else
90 			echo_failure
91 		fi
92 		echo
93 		[ $RETVAL = 0 ] && rm -f ${LOCKFILE} ${PIDFILE}
94 	else
95 		echo -n $"Error: phpdbg not running"
96 		echo_failure
97 		echo
98 		[ $RETVAL = 1 ]
99 	fi
100 	return $RETVAL
101 }
102 ##################################################################
103 case "$1" in
104 	start)
105 	start
106 	;;
107 	stop)
108 	stop
109 	;;
110 	status)
111 	status $PHPDBG
112 	;;
113 	restart)
114 	$0 stop
115 	$0 start
116 	;;
117 	*)
118 	echo "usage: $0 start|stop|restart|status"
119 	;;
120 esac
121 ###################################################################
122 exit $RETVAL
123