Start/stop actions init.d
authorJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Wed, 19 Dec 2012 14:08:06 +0000 (14:08 +0000)
committerJean-Michel Nirgal Vourgère <jmv@nirgal.com>
Wed, 19 Dec 2012 14:08:06 +0000 (14:08 +0000)
Droped sudo usage

INSTALL
bin/inputs/run.py
debian/control
debian/install
debian/pyversions [new file with mode: 0644]
etc/init.sh

diff --git a/INSTALL b/INSTALL
index 3a47c855fafa4ba092b06392d9ae6cc890e98e46..d199b17c33c7979a713f9478985ebfafe7193580 100644 (file)
--- a/INSTALL
+++ b/INSTALL
@@ -3,9 +3,9 @@ It has been tested on architectures i386 and amd64.
 
 = Required packages
 ===================
-libgps-dev, postgresql, python (>= 2.5), python-serial, python-rrdtool, python-psycopg2, python-cracklib, libjs-jquery, apache2, libapache2-mod-python, python-django, xz-utils, python-daemon, ntp, python-daemon, sudo
+libgps-dev, postgresql, python (>= 2.5), python-serial, python-rrdtool, python-psycopg2, python-cracklib, libjs-jquery, apache2, libapache2-mod-python, python-django, xz-utils, python-daemon, ntp, python-daemon
 
-libgps-dev postgresql python-serial python-rrdtool python-psycopg2 python-cracklib libjs-jquery apache2 libapache2-mod-python python-django xz-utils python-daemon ntp python-daemon sudo
+libgps-dev postgresql python-serial python-rrdtool python-psycopg2 python-cracklib libjs-jquery apache2 libapache2-mod-python python-django xz-utils python-daemon ntp python-daemon
 
 python-decoratedstr (from nirgal.com)
 python-htmlentities (from nirgal.com)
index b3377bdaad29315837fd6fa8c9e29df307278a3b..a1c6e54aa95ab24921c19b7a7f626c410dd84e57 100644 (file)
@@ -31,8 +31,6 @@ def mainloop(options, args):
     rootlogger.setLevel(loglevel)
     
     # create file handler which logs even debug messages
-    #utc=True is python 2.6 specific
-    #fh = logging.handlers.TimedRotatingFileHandler('/var/log/ais/daemon', when='D', backupCount=7, utc=True)
     fh = logging.handlers.TimedRotatingFileHandler('/var/log/ais/daemon', when='D', backupCount=7, utc=True)
     #fh.setLevel(logging.DEBUG)
 
index edb52b0b10ec01917e2199995666121f46c20b11..eee89d6882dc019b7731fbbb3c6b114655cd40ff 100644 (file)
@@ -8,7 +8,7 @@ Vcs-Svn: svn://svn.nirgal.com/ais
 
 Package: ais
 Architecture: all
-Depends: ${misc:Depends}, ${python:Depends}, postgresql, python (>= 2.6), python-serial, python-rrdtool, python-psycopg2, python-cracklib, libjs-jquery, apache2, libapache2-mod-python, python-django, xz-utils, python-daemon, ntp, python-daemon, sudo, python-decoratedstr, python-htmlentities, adduser
+Depends: ${misc:Depends}, ${python:Depends}, postgresql, python (>= 2.6), python-serial, python-rrdtool, python-psycopg2, python-cracklib, libjs-jquery, apache2, libapache2-mod-python, python-django, xz-utils, python-daemon, ntp, python-daemon, python-decoratedstr, python-htmlentities, adduser
 Description: Nirgal's Ais server
  Handles AIS data, storing locally both for real time usage and for archive.
  .
index d5561a0f2e404db1603768c1bcd2ab00c1c9334d..0da6202d1d331218f4510735b41f3a564e004a3a 100644 (file)
@@ -1,11 +1,11 @@
 /etc/config.SAMPLE              /etc/ais/
 /etc/database.SAMPLE            /etc/ais/
 /etc/hidden.SAMPLE              /etc/ais/
-/bin/*.py                       /usr/share/python-support/ais/
-/bin/djais/*.py                 /usr/share/python-support/ais/djais/
-/bin/djais/templatetags/*.py    /usr/share/python-support/ais/djais/templatetags/
-/bin/extras/*.py                /usr/share/python-support/ais/extras/
-/bin/inputs/*.py                /usr/share/python-support/ais/inputs/
+/bin/*.py                       /usr/share/python-support/ais/ais/
+/bin/djais/*.py                 /usr/share/python-support/ais/ais/djais/
+/bin/djais/templatetags/*.py    /usr/share/python-support/ais/ais/djais/templatetags/
+/bin/extras/*.py                /usr/share/python-support/ais/ais/extras/
+/bin/inputs/*.py                /usr/share/python-support/ais/ais/inputs/
 /kmz_icons                      /usr/share/ais/
 /www                            /usr/share/ais/
 /www_templates                  /usr/share/ais/
diff --git a/debian/pyversions b/debian/pyversions
new file mode 100644 (file)
index 0000000..0c043f1
--- /dev/null
@@ -0,0 +1 @@
+2.6-
index aeb606be1e14865e5df9c44513109e0e919b4ea7..69e6a68ddf2dfc1d4ecb5e3159156655a756f7d4 100755 (executable)
@@ -1,32 +1,39 @@
 #!/bin/sh
 ### BEGIN INIT INFO
 # Provides:          ais
-# Required-Start:    apache2 postgresql
-# Required-Stop:     apache2 postgresql
+# Required-Start:    remote_fs apache2 postgresql
+# Required-Stop:     remote_fs apache2 postgresql
 # Default-Start:     2 3 4 5
 # Default-Stop:      0 1 6
 # Short-Description: AIS server
 # Description:       Start/stop the AIS aquisition daemon and the job runner
 ### END INIT INFO
 
+PATH=/bin:/usr/bin:/sbin:/usr/sbin
+INPUTPIDFILE=/var/run/ais/input.pid
+RUNNERPIDFILE=/var/run/ais/runner.pid
+
 set -e
 
 . /lib/lsb/init-functions
 
-case $1 in
-    start)
+d_start () {
                [ -r /etc/ais/database ] && RUN_PARAMS=--db
+               RUN_PARAMS="$RUN_PARAMS --foreground"
+
                log_daemon_msg "Starting AIS acquisition"
-               if sudo -u ais python -m ais.inputs.run $RUN_PARAMS
+               [ -e /var/run/ais ] || mkdir -p /var/run/ais && chown ais:ais /var/run/ais
+               if start-stop-daemon --start --quiet --background --exec /usr/bin/python --user ais --pidfile $INPUTPIDFILE --chuid ais:ais --umask 002 --make-pidfile -- -m ais.inputs.run $RUN_PARAMS
                then
                        log_success_msg ais.inputs.run
                else
                        log_failure_msg failed
                fi
+
                log_daemon_msg "Starting AIS job runner"
                if [ -r /etc/ais/database ]
                then
-                       if sudo -u ais python -m ais.jobrunner --debug
+                       if start-stop-daemon --start --quiet --background --exec /usr/bin/python --user ais --pidfile $RUNNERPIDFILE --chuid ais:ais --umask 002 --make-pidfile -- -m ais.jobrunner --debug
                        then
                                log_success_msg ais.jobrunner
                        else
@@ -35,10 +42,44 @@ case $1 in
                else
                        log_warning_msg "Disabled because there is no /etc/ais/database"
                fi
+}
+
+d_stop () {
+               [ -r /etc/ais/database ] && RUN_PARAMS=--db
+               RUN_PARAMS="$RUN_PARAMS --foreground"
+
+               log_daemon_msg "Stopping AIS acquisition"
+               if start-stop-daemon --stop --quiet --exec /usr/bin/python --user ais --pidfile $INPUTPIDFILE -- -m ais.inputs.run $RUN_PARAMS
+               then
+                       log_success_msg ais.inputs.run
+               else
+                       log_failure_msg failed
+               fi
+               
+               log_daemon_msg "Stopping AIS job runner"
+               if [ -r /etc/ais/database ]
+               then
+                       if start-stop-daemon --start --quiet --background --exec /usr/bin/python --user ais --pidfile $RUNNERPIDFILE --chuid ais:ais --umask 002 --make-pidfile -- -m ais.jobrunner --debug
+                       then
+                               log_success_msg ais.jobrunner
+                       else
+                               log_failure_msg failed
+                       fi
+               else
+                       log_success_msg "Disabled because there is no /etc/ais/database"
+               fi
+}
+
+case $1 in
+    start)
+               d_start
     ;;
-    stop|restart|force-reload)
-        log_success_msg "Not implemented"
-        exit 1
+    stop)
+               d_stop
+    ;;
+    restart|force-reload)
+               d_stop
+               d_start
     ;;
     *)
         log_success_msg "Usage: ais.sh {start|stop}"