Proposal for replacing Upstart with init.d script.

Change-Id: I22ad1faac713bb50f0b7ad3dde132363a6588723
diff --git a/tools/package/bin/onos-service b/tools/package/bin/onos-service
index 5cc2009..d14983e 100755
--- a/tools/package/bin/onos-service
+++ b/tools/package/bin/onos-service
@@ -50,4 +50,4 @@
   fi
 done
 
-exec ${ONOS_HOME}/apache-karaf-$KARAF_VERSION/bin/karaf $KARAF_ARGS
+exec ${ONOS_HOME}/apache-karaf-$KARAF_VERSION/bin/start $KARAF_ARGS
diff --git a/tools/package/init/onos.initd b/tools/package/init/onos.initd
new file mode 100755
index 0000000..7d67ccc
--- /dev/null
+++ b/tools/package/init/onos.initd
@@ -0,0 +1,58 @@
+#! /bin/bash
+# -----------------------------------------------------------------------------
+# init.d script to run ONOS.
+# -----------------------------------------------------------------------------
+
+start () {
+    # TODO check if ONOS is already running first
+    
+    [ -f /opt/onos/options ] && . /opt/onos/options
+    ONOS_USER=${ONOS_USER:-root}
+
+    # Ensure that the environment is initialized
+    [ -d /opt/onos ] && mkdir /opt/onos/var 2>/dev/null && chown $ONOS_USER.$ONOS_USER /opt/onos/var
+    [ -d /opt/onos ] && mkdir /opt/onos/config 2>/dev/null && chown $ONOS_USER.$ONOS_USER /opt/onos/config
+    [ -d /opt/onos ] && [ ! -h /opt/onos/log ] \
+         && ln -s /opt/onos/karaf/data/log /opt/onos/log || :
+    
+    [ -f /opt/onos/options ] && . /opt/onos/options
+  start-stop-daemon --signal INT --start --chuid ${ONOS_USER:-root} \
+    --exec /opt/onos/bin/onos-service -- ${ONOS_OPTS:-server} \
+        >/opt/onos/var/stdout.log 2>/opt/onos/var/stderr.log
+}
+
+stop () {
+    /opt/onos/karaf/bin/stop
+}
+
+restart () {
+        stop
+        start
+}
+
+status () {
+    /opt/onos/karaf/bin/status
+}
+
+case $1 in
+    start)
+        start
+	    ;;
+    stop | force-stop)
+        stop
+        ;;
+    restart)
+        shift
+        restart "$@"
+        ;;
+    status)
+        status
+        exit $?
+        ;;
+    *)
+        echo "Usage: $0 {start|stop|restart|status}" >&2
+        exit 1
+        ;;
+esac
+
+exit 0