OLD | NEW |
1 #! /bin/sh | 1 #! /bin/sh |
2 | 2 |
3 # Installation | 3 #The thread which is taking data from the cache and put it into the database is
working like a daemon module |
4 # - Move this to /etc/init.d/myservice | |
5 # - chmod +x this | |
6 # | |
7 # Starting and stopping | 4 # Starting and stopping |
8 # - Start: `service myservice start` or `/etc/init.d/myservice start` | 5 # - Start: `service daemon_DB start`· |
9 # - Stop: `service myservice stop` or `/etc/init.d/myservice stop` | 6 # - Stop: `service daemon_DB stop`· |
10 | 7 |
11 #ref http://till.klampaeckel.de/blog/archives/94-start-stop-daemon,-Gearman-and-
a-little-PHP.html | 8 #ref http://till.klampaeckel.de/blog/archives/94-start-stop-daemon,-Gearman-and-
a-little-PHP.html |
12 #ref http://unix.stackexchange.com/questions/85033/use-start-stop-daemon-for-a-p
hp-server/85570#85570 | 9 #ref http://unix.stackexchange.com/questions/85033/use-start-stop-daemon-for-a-p
hp-server/85570#85570 |
13 #ref http://serverfault.com/questions/229759/launching-a-php-daemon-from-an-lsb-
init-script-w-start-stop-daemon | 10 #ref http://serverfault.com/questions/229759/launching-a-php-daemon-from-an-lsb-
init-script-w-start-stop-daemon |
14 | 11 |
| 12 #Here we define our damon. Its name, its description, the location of its log an
d pid. |
15 NAME=daemon_db | 13 NAME=daemon_db |
16 DESC="Daemon for my magnificent PHP CLI script" | 14 DESC="Daemon for my magnificent PHP CLI script" |
17 PIDFILE="/var/run/${NAME}.pid" | 15 PIDFILE="/var/run/${NAME}.pid" |
18 LOGFILE="/var/log/${NAME}.log" | 16 LOGFILE="/var/log/${NAME}.log" |
19 | 17 |
| 18 #now we define wich program the daemon will run. It will use php7.0 to run the s
cript thread_database.php |
20 DAEMON="/usr/bin/php7.0" | 19 DAEMON="/usr/bin/php7.0" |
21 DAEMON_OPTS="/var/www/html/API_REST/thread_database.php" | 20 DAEMON_OPTS="/var/www/html/API_REST/thread_database.php" |
22 | 21 |
| 22 #options to start and stop the daemon like a service |
23 START_OPTS="--start --background --make-pidfile --pidfile ${PIDFILE} --exec ${DA
EMON} ${DAEMON_OPTS}" | 23 START_OPTS="--start --background --make-pidfile --pidfile ${PIDFILE} --exec ${DA
EMON} ${DAEMON_OPTS}" |
24 STOP_OPTS="--stop --pidfile ${PIDFILE}" | 24 STOP_OPTS="--stop --pidfile ${PIDFILE}" |
25 | 25 |
26 test -x $DAEMON || exit 0 | 26 test -x $DAEMON || exit 0 |
27 | 27 |
28 set -e | 28 set -e |
29 | 29 |
| 30 #usual daemon option (start, stop,restart ...) |
| 31 #store information into its log file |
30 case "$1" in | 32 case "$1" in |
31 start) | 33 start) |
32 echo -n "Starting ${DESC}: " | 34 echo -n "Starting ${DESC}: " |
33 start-stop-daemon $START_OPTS >> $LOGFILE | 35 start-stop-daemon $START_OPTS >> $LOGFILE |
34 echo "$NAME." | 36 echo "$NAME." |
35 ;; | 37 ;; |
36 stop) | 38 stop) |
37 echo -n "Stopping $DESC: " | 39 echo -n "Stopping $DESC: " |
38 start-stop-daemon $STOP_OPTS | 40 start-stop-daemon $STOP_OPTS |
39 echo "$NAME." | 41 echo "$NAME." |
40 rm -f $PIDFILE | 42 rm -f $PIDFILE |
41 ;; | 43 ;; |
42 restart|force-reload) | 44 restart|force-reload) |
43 echo -n "Restarting $DESC: " | 45 echo -n "Restarting $DESC: " |
44 start-stop-daemon $STOP_OPTS | 46 start-stop-daemon $STOP_OPTS |
45 sleep 1 | 47 sleep 1 |
46 start-stop-daemon $START_OPTS >> $LOGFILE | 48 start-stop-daemon $START_OPTS >> $LOGFILE |
47 echo "$NAME." | 49 echo "$NAME." |
48 ;; | 50 ;; |
49 *) | 51 *) |
50 N=/etc/init.d/$NAME | 52 N=/etc/init.d/$NAME |
51 echo "Usage: $N {start|stop|restart|force-reload}" >&2 | 53 echo "Usage: $N {start|stop|restart|force-reload}" >&2 |
52 exit 1 | 54 exit 1 |
53 ;; | 55 ;; |
54 esac | 56 esac |
55 | 57 |
56 exit 0 | 58 exit 0 |
OLD | NEW |