Announcement

Collapse
No announcement yet.

Linux Shutdown and Restart commands don't work

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    Originally posted by ramans View Post
    Again, thanks - the controller shutdown and restart are now working fine. I added the hs3stop.sh to the homeseer.service file as suggested also.
    Greatly appreciated ...
    Can you post the changes you made in the homeseer.service file?

    Comment


    • #17
      Yep - I think all of this came from zwolfpack and his work for a similar issue on the Rpi3

      I uncommented the ExecStop command in my homeseer.service file (above) and changed the script reference to HS3stop.sh from stop_homeseer.sh as noted by zwolfpack.
      My HS3Stop is:

      !/bin/sh
      # hs3stop.sh - stop the HS3 application
      # supports: systemd service shutdown

      # login credentials used to login to web server; ignored if password not required
      # login=usernameassword

      # extract web server port from settings.ini
      hs3root=$(dirname $0) # where this script lives
      webport=$(awk -F= '\
      {
      gsub("\015", "") # remove CR character
      if ($1 == "gWebSvrPort") print $2
      }
      ' $hs3root/Config/settings.ini)

      # send application shutdown command
      for i in $(seq 1 5)
      do
      curl -s -o /dev/null ${login:+-u} $login -X POST -F 'scriptcmd=hs.shutdown()' -F 'runscript=Execute Command' "http:$
      sleep 2
      done

      # delay until all mono processes terminate
      mono=$(which mono) || exit
      while pgrep -af $mono
      do
      sleep 5
      done

      Comment


      • #18
        The main problem of not executing tools commands is in the startup script (screen must be runned while homeseer service is down).

        Here is my correction of this ( [ -f $DIR/go ] && cd $DIR && su -c "/usr/bin/screen -dmS $NAME" $USER && su -c "/usr/bin/screen -S $NAME -X stuff '$DIR/go^M'" $USER &&):

        #!/bin/bash
        ### BEGIN INIT INFO
        # Provides: HomeSeer
        # Required-Start: $local_fs $network
        # Required-Stop: $local_fs
        # Default-Start: 2 3 4 5
        # Default-Stop: 0 1 6
        # Short-Description: HomeSeer
        # Description: HomeSeer daemon
        ### END INIT INFO

        NAME='HomeSeer' # Server handle for the screen session
        DIR='/usr/local/HomeSeer'
        USER='root' # Start HomeSeer as root. You may use a non privileged user
        # Note: if homeseer is running as non-root user
        # remove 'sudo' command in file 'go' in HomeSeer folder
        # and change setting gWebSvrPort to value > 1024 in settings.ini
        PWD=`pwd`
        RETVAL=0

        service_start() {

        if [ -f /var/run/$NAME.pid ]; then
        if [ "$(ps -p `cat /var/run/$NAME.pid` | wc -l)" -gt 1 ]; then
        echo -e "$NAME is already running (pidfile exists)."
        return 1
        else
        rm -f /var/run/$NAME.pid
        fi
        fi
        [ -f $DIR/go ] && cd $DIR && su -c "/usr/bin/screen -dmS $NAME" $USER && su -c "/usr/bin/screen -S $NAME -X stuff '$DIR/go^M'" $USER &&
        cd $PWD
        sleep 5
        ps -ef | egrep "[S]CREEN.+${NAME}" | awk '{ print $2 }' > /var/run/$NAME.pid
        [ -s /var/run/$NAME.pid ] && echo "$NAME started."
        }

        service_stop() {
        if [ -f /var/run/$NAME.pid ]; then
        if [ $(ps -ef | egrep -c "[S]CREEN.+$NAME") -ge 1 ]; then
        #invoke shutdown command to homeseer...
        for char in $(printf "\\r s h u t d o w n \\r") ; do
        su -c "/usr/bin/screen -p 0 -S $NAME -X stuff $char" $USER
        sleep 0.1
        done
        sleep 15
        fi
        if [ "$(ps -p `cat /var/run/$NAME.pid` | wc -l)" -gt 1 ]; then
        echo -e "$NAME did not stop gacefully. Killing it"
        [ -s /var/run/$NAME.pid ] && kill `cat /var/run/$NAME.pid`
        fi
        rm -f /var/run/$NAME.pid
        else
        echo -e "$NAME is not running."
        fi
        }

        case "$1" in
        'start')
        service_start
        ;;
        'stop')
        service_stop
        ;;
        'restart')
        service_stop
        sleep 5
        service_start
        ;;
        *)
        echo "Usage $0 start|stop|restart"
        esac
        # --------------------------------------------------------

        Comment

        Working...
        X