Browse Source

Disable daemon on init install, add enable/disable/restart commands

Joachim M. Giæver 3 years ago
parent
commit
68b891741b
4 changed files with 31 additions and 14 deletions
  1. 8 0
      snap/snapcraft.yaml
  2. 19 12
      src/bin/env-wrapper
  3. 2 2
      src/hooks/configure
  4. 2 0
      src/hooks/install

+ 8 - 0
snap/snapcraft.yaml

@@ -8,10 +8,12 @@ description: |
   This snap contains only the ozwdaemon application and none of the management tools. Use Home Assistant or OZW Admin to connect to it.
 
   NOTE! To add secure devices through Home Assistant, you have to make service calls, with the payload:
+  ```
   {
     "secure": true,
     "instance_id": <id given in configuration>
   }
+  ```
   This is an issue with the OpenZWave integration of Home Assistant and will hopefully be fixed in the future.
 
   See `snap get ozwdaemon -d` for configuration options.
@@ -34,6 +36,12 @@ apps:
       - network
       - network-bind
       - raw-usb
+  enable:
+    command: bin/daemonize
+  disable:
+    command: bin/de-daemonize
+  restart:
+    command: bin/restart
   exec:
     command: usr/local/bin/ozwdaemon --exec
     command-chain:

+ 19 - 12
src/bin/env-wrapper

@@ -45,7 +45,7 @@ OPT_HELP=false
 ARGV=( "$@" )
 for ((i = 0; i < $#; i++)); do
     OPT="${ARGV[$i]}"
-    if [ "${OPT}" = "--help" ]; then
+    if [ "${OPT}" = "--help" -o "${OPT}" = '-h' ]; then
         OPT_HELP=true
     fi
 done
@@ -69,8 +69,7 @@ fi
 
 if [ ${OPT_HELP} = false ]; then
     if [ ! -c "${USB_PATH}" ]; then 
-        lprint "usb-path (${USB_PATH}) does not exist,"
-        lprint "or is not a Character Device"
+        lprint "usb-path (${USB_PATH}) does not exist, or is not a Character Device."
         lprint "See: snap get ${SNAP_NAME} -d usb-path"
         exit 1
     fi
@@ -124,12 +123,19 @@ if [ ${OPT_HELP} = false ]; then
         lprint "Could not connect to MQTT on ${MQTT_SERVER}:${MQTT_PORT} after 30 seconds"; 
         exit 1;
     fi
-    lprint "MQTT seems to be up on ${MQTT_SERVER}:${MQTT_PORT}"
-
     set -- "$@" "${OZW_ARGS[@]}"
 else
     echo "QT OpenZWave Remote Daemon ($($1 --version))"
     echo ""
+    echo "IMPORTANT! The DAEMON/SERVICE is disabled by default after installation." 
+    echo "You have to manually 'daemonize' OpenZWave Daemon with executing the command"
+    echo ""
+    echo "$ ozwdaemon.enable"
+    echo ""
+    echo "But first set your configuration as descrived below and run ${SNAP_NAME}.exec"
+    echo "until ${SNAP_NAME} boots and runs successfully. "
+    echo ""
+    echo "Base configuration values:"
     echo "- usb-path:               $(snapctl get "usb-path")"
     echo "- stop-on-failure:        $(snapctl get "stop-on-failure")"
     echo ""
@@ -152,17 +158,18 @@ else
     echo "                          DO NOT LOSE THIS KEY OTHERWISE YOU WILL HAVE TO REINCLUDE YOUR SECURED DEVICES."
     echo "                          The default key is auto-generated on installation, and is unique."
     echo ""
-    echo "Set options with:     snap set ${SNAP_NAME} param=key"
-    echo "For example:          snap set ${SNAP_NAME} mqtt.server=localhost"
+    echo "Set options with:         $ snap set ${SNAP_NAME} param=key"
+    echo "For example:              $ snap set ${SNAP_NAME} mqtt.server=localhost"
     echo ""
     echo "Also see 'snap info ${SNAP_NAME}' for information about secure devices."
     echo ""
-    echo "Follow log with"
-    echo "'sudo journalctl -xef --identifier=${SNAP_NAME}.${SNAP_NAME}'"
+    echo "Follow the log with"
+    echo "$ snap logs ozwdaemon"
+    echo ""
+    echo "Other commands"
+    echo "Disable the daemon:       $ ozwdaemon.disable"
+    echo "Restart the daemon:       $ ozwdaemon.restart"
     exit 0
 fi
 
-
-lprint "Exec: $@"
-
 exec "$@"

+ 2 - 2
src/hooks/configure

@@ -24,7 +24,7 @@ if [ ! -d "${USER_DIR}" -a ! -w "${USER_DIR}" ]; then
     exit 1
 fi
 
-RUNNING=$(snapctl services | grep "${SNAP_NAME}" | wc -l)
-if [ ${RUNNING} -gt 0 ]; then
+RUNNING=$(snapctl services | grep "${SNAP_NAME}" | grep inactive | wc -l)
+if [ ${RUNNING} -eq 0 ]; then
     snapctl restart "${SNAP_NAME}"
 fi

+ 2 - 0
src/hooks/install

@@ -20,3 +20,5 @@ snapctl set ozw.auth-key=""
 
 mkdir "${SNAP_DATA}/config"
 mkdir "${SNAP_DATA}/user"
+
+snapctl stop --disable "${SNAP_NAME}.${SNAP_NAME}"