First version that works with Debian 9.. kind of
[ais.git] / etc / init.sh
1 #!/bin/sh
2 ### BEGIN INIT INFO
3 # Provides:          ais
4 # Required-Start:    $remote_fs apache2 postgresql
5 # Required-Stop:     $remote_fs apache2 postgresql
6 # Default-Start:     2 3 4 5
7 # Default-Stop:      0 1 6
8 # Short-Description: AIS server
9 # Description:       Start/stop the AIS aquisition daemon and the job runner
10 ### END INIT INFO
11
12 PATH=/bin:/usr/bin:/sbin:/usr/sbin
13 INPUTPIDFILE=/var/run/ais/input.pid
14 RUNNERPIDFILE=/var/run/ais/runner.pid
15
16 set -e
17
18 . /lib/lsb/init-functions
19
20 d_start () {
21                 [ -r /etc/ais/database ] && RUN_PARAMS=--db
22                 RUN_PARAMS="$RUN_PARAMS --foreground"
23
24                 log_daemon_msg "Starting AIS acquisition"
25                 [ -e /var/run/ais ] || mkdir -p /var/run/ais && chown ais:ais /var/run/ais
26                 if start-stop-daemon --start --quiet --background --exec /usr/bin/python3 --user ais --pidfile $INPUTPIDFILE --chuid ais:ais --umask 002 --make-pidfile -- -m ais.inputs.run $RUN_PARAMS
27                 then
28                         log_success_msg ais.inputs.run
29                 else
30                         log_failure_msg failed
31                 fi
32
33                 log_daemon_msg "Starting AIS job runner"
34                 if [ -r /etc/ais/database ]
35                 then
36                         if start-stop-daemon --start --quiet --background --exec /usr/bin/python3 --user ais --pidfile $RUNNERPIDFILE --chuid ais:ais --umask 002 --make-pidfile -- -m ais.jobrunner --debug
37                         then
38                                 log_success_msg ais.jobrunner
39                         else
40                                 log_failure_msg failed
41                         fi
42                 else
43                         log_warning_msg "Disabled because there is no /etc/ais/database"
44                 fi
45 }
46
47 d_stop () {
48                 [ -r /etc/ais/database ] && RUN_PARAMS=--db
49                 RUN_PARAMS="$RUN_PARAMS --foreground"
50
51                 log_daemon_msg "Stopping AIS acquisition"
52                 if start-stop-daemon --stop --quiet --exec /usr/bin/python3 --user ais --pidfile $INPUTPIDFILE -- -m ais.inputs.run $RUN_PARAMS
53                 then
54                         log_success_msg ais.inputs.run
55                 else
56                         log_failure_msg failed
57                 fi
58                 
59                 log_daemon_msg "Stopping AIS job runner"
60                 if [ -r /etc/ais/database ]
61                 then
62                         if start-stop-daemon --start --quiet --background --exec /usr/bin/python3 --user ais --pidfile $RUNNERPIDFILE --chuid ais:ais --umask 002 --make-pidfile -- -m ais.jobrunner --debug
63                         then
64                                 log_success_msg ais.jobrunner
65                         else
66                                 log_failure_msg failed
67                         fi
68                 else
69                         log_success_msg "Disabled because there is no /etc/ais/database"
70                 fi
71 }
72
73 case $1 in
74     start)
75                 d_start
76     ;;
77     stop)
78                 d_stop
79     ;;
80     restart|force-reload)
81                 d_stop
82                 d_start
83     ;;
84     *)
85         log_success_msg "Usage: $(basename $0) {start|stop|restart}"
86         exit 1
87     ;;
88 esac