add initscript, postinstall
Scott Baker [Tue, 30 Sep 2014 06:53:05 +0000 (23:53 -0700)]
opencloud-net/Makefile
opencloud-net/debian/changelog
opencloud-net/debian/postinst [new file with mode: 0644]
opencloud-net/debian/rules
opencloud-net/opencloud-net.init [new file with mode: 0644]

index 1e475ae..1d519b0 100644 (file)
@@ -1,4 +1,4 @@
-BUILDDIR=build/opencloud-plugin-1.0
+BUILDDIR=build/opencloud-net-1.0
 
 opencloud-net-plugin:
        # it's python. There's nothing to build
@@ -12,13 +12,16 @@ install:
        install -d $(DESTDIR)/etc/init.d
        install opencloud-net.py $(DESTDIR)/usr/local/sbin/
        install opencloud-net-watcher.py $(DESTDIR)/usr/local/sbin/
+       install opencloud-net.init $(DESTDIR)/etc/init.d/opencloud-net
 deb: 
+       chmod a+x opencloud-net.py
+       chmod a+x opencloud-net-watcher.py
        rm -rf build
        mkdir -p $(BUILDDIR)
-       cp Makefile *.py $(BUILDDIR)/
+       cp Makefile *.py *.init $(BUILDDIR)/
        mkdir $(BUILDDIR)/debian        
        mkdir $(BUILDDIR)/debian/source
-       cp debian/changelog debian/control debian/rules debian/compat debian/copyright $(BUILDDIR)/debian/
+       cp debian/changelog debian/control debian/rules debian/compat debian/copyright debian/postinst $(BUILDDIR)/debian/
        cp debian/source/format $(BUILDDIR)/debian/source/
        cd $(BUILDDIR); debuild -i -us -uc -A
 
index 934754b..77bfa23 100644 (file)
@@ -1,4 +1,4 @@
-opencloud-net (1.0-1) UNRELEASED; urgency=low
+opencloud-net (1.0-2) UNRELEASED; urgency=low
 
   * Initial release. (Closes: #XXXXXX)
 
diff --git a/opencloud-net/debian/postinst b/opencloud-net/debian/postinst
new file mode 100644 (file)
index 0000000..adbd017
--- /dev/null
@@ -0,0 +1,3 @@
+#! /bin/bash
+update-rc.d opencloud-net defaults
+service opencloud-net restart
index cbe925d..2a2cba6 100755 (executable)
@@ -1,3 +1,4 @@
 #!/usr/bin/make -f
 %:
        dh $@
+override_dh_usrlocal:
diff --git a/opencloud-net/opencloud-net.init b/opencloud-net/opencloud-net.init
new file mode 100644 (file)
index 0000000..6c38d8b
--- /dev/null
@@ -0,0 +1,116 @@
+#!/bin/bash
+#
+# opencloud-net  sets up opencloud-net and watcher
+#
+# chkconfig: 2345 4 99
+#
+# description:  sets up opencloud-net and watcher
+#
+# $Id:$
+#
+### BEGIN INIT INFO
+# Provides: $opencloud-net
+# Required-Start: $opencloud-net
+# Required-Stop: $opencloud-net
+# Default-Stop: 0 1 2 3 4 5 6
+# Default-Start: 2 3 4 5
+### END INIT INFO
+
+. /lib/lsb/init-functions
+
+# Verbosity
+verbose=0
+
+start (){
+    python /usr/local/sbin/opencloud-net-watcher.py -d
+}
+
+stop (){
+    pkill -f "python.*opencloud-net-watcher.py"
+}
+
+usage(){
+    echo "Usage: $0 [OPTION]... COMMAND"
+    echo "      -v              Be verbose"
+    echo "      -h              This message"
+    exit 1
+}
+
+# Get options
+while getopts "vh" opt ; do
+    case $opt in
+        v)
+            verbose=1
+            ;;
+        h|*)
+            usage
+            ;;
+    esac
+done
+
+# Redirect stdout and stderr of each step to /var/log/boot.log
+if [ $verbose -eq 0 ] ; then
+    touch /var/log/boot.log
+    chmod 600 /var/log/boot.log
+    exec 1>>/var/log/boot.log
+    exec 2>>/var/log/boot.log
+fi
+
+# Get command
+shift $(($OPTIND - 1))
+if [ -z "$1" ] ; then
+    usage
+fi
+command=$1
+
+RETVAL=0
+
+case "$command" in
+    start)
+    (
+        echo `/bin/date` "starting opencloud-net-watcher"
+        if flock -n -o 201; then
+        (
+            exec 201>&-
+
+            start
+        )
+        else
+            echo "another restart is already in progress, nothing to do"
+        fi
+    ) 201>/var/run/opencloud-net-watcher.lock
+    ;;
+
+    restart)
+    (
+        echo `/bin/date` "restarting opencloud-net-watcher"
+        if flock -n -o 201; then
+        (
+            exec 201>&-
+
+            stop
+            start
+        )
+        else
+            echo "another restart is already in progress, nothing to do"
+        fi
+    ) 201>/var/run/opencloud-net-watcher.lock
+    ;;
+
+    stop)
+        echo `/bin/date` "stopping opencloud-net-watcher service"
+        stop
+        ;;
+
+    status)
+        echo "not implemented"
+        RETVAL=0
+        ;;
+
+    *)
+        usage >&3
+        RETVAL=1
+        ;;
+esac
+
+exit $RETVAL