Announcement

Collapse
No announcement yet.

HS3 Linux startup and shutdown

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

    HS3 Linux startup and shutdown

    Hi. I am setting up my HS server in Ubuntu and I am looking into how to automate startup and shutdown of homeseer.

    Startup:

    Startup is taking a REALLY long time
    It goes well until this command:
    1/24/2014 10:37:47 AM:[Startup]->Starting DDNS service...
    and then it stops for about 2 min before this messages shows up:
    _wapi_connect: error looking up socket handle 0xe
    Then another 2 minute delay and this message appears
    1/24/2014 10:41:47 AM:[Startup]->Running the startup script Startup.vb
    After that everything is fast again
    Any hints what might cause this? It is behind a very restrictive firewall that may not let it access the internet on non-standard ports? Would that cause it? Is there a way to disable the DDNS service since I don't need it?

    Shutdown:

    The only way I can see to shut it down safely is:
    1) run the ./go script using screen so I can connect to it later and issue the shutdown command
    2) use the web interface and manually issue a shutdown.

    Am I missing something or are there other ways to shut HS down once it has been started?
    I have a good Ubuntu script to automate reconnecting to screen and issuing the shutdown command. If that is the best way, I will get it running and post it later.

    Thanks

    #2
    The slow startup is caused by HS not being able to communicate to port 8245 at checkip-lax.dyndns.com. As soon as I allowed my HS server access to outgoing communication on that port, the startup was very fast.

    It would be nice to be able to disable that service if you don't need it so systems with limited or no internet access don't pay the 4 minute startup penalty

    Working on an clean automatic startup/shutdown script now.
    Last edited by PosterBoy; January 24, 2014, 10:50 PM. Reason: wording

    Comment


      #3
      I have the auto start stop script working under Ubuntu

      Here it is:

      Code:
      # --------------------------------------------------------
      #!/bin/bash
      ### BEGIN INIT INFO
      # Provides:          Homeseer
      # Required-Start:    $local_fs $syslog $time
      # Required-Stop:     $local_fs $syslog
      # Default-Start:     2 3 4 5
      # Default-Stop:      0 1 6
      # Short-Description: Start/Stop HomeSeer Server
      # Description:       Start/Stop HomeSeer Server
      ### END INIT INFO
      #
      
      NAME='HomeSeer'        # Server handle for the screen session
      DIR='/HomeSeer'
      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 "Cannot start $NAME.  Server is already running."
      else
      rm -rf /var/run/$NAME.pid
      service_start
      fi
      else
      cd $DIR
      /usr/bin/screen -S $NAME -d -m ./go
      cd $PWD
      sleep 1
      ps -ef | grep SCREEN | grep "$NAME" | grep -v grep | awk '{ print $2}' > /var/run/$NAME.pid
      echo "$NAME started."
      fi
      }
      
      service_stop() {
      if [ -f /var/run/$NAME.pid ]; then
      if [ "$(ps -ef | grep SCREEN | grep "$NAME" | grep -v grep | wc -l)" -ge 1 ]; then
      /usr/bin/screen -p 0 -S $NAME -X stuff 's'
      sleep 0.1
      /usr/bin/screen -p 0 -S $NAME -X stuff 'h'
      sleep 0.1
      /usr/bin/screen -p 0 -S $NAME -X stuff 'u'
      sleep 0.1
      /usr/bin/screen -p 0 -S $NAME -X stuff 't'
      sleep 0.1
      /usr/bin/screen -p 0 -S $NAME -X stuff 'd'
      sleep 0.1
      /usr/bin/screen -p 0 -S $NAME -X stuff 'o'
      sleep 0.1
      /usr/bin/screen -p 0 -S $NAME -X stuff 'w'
      sleep 0.1
      /usr/bin/screen -p 0 -S $NAME -X stuff 'n'
      sleep 0.1
      /usr/bin/screen -p 0 -S $NAME -X stuff '^M'
      sync
      sleep 1
      fi
      if [ "$(ps -p `cat /var/run/$NAME.pid` | wc -l)" -gt 1 ]; then
      echo -e "$NAME did not stop gacefully.  Killing it"
      kill `cat /var/run/$NAME.pid`
      fi
      rm -rf /var/run/$NAME.pid
      else
      echo -e "Cannot stop $NAME.  Server 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
      # --------------------------------------------------------
      The spelling out shutdown part is because for whatever reason, homeseer wont take the characters that fast. The sleeps make it work.
      You can use screen -r -S HomeSeer from another ssh shell to see it happen. Note the ^D is created by hitting Ctrl-V then Enter in vi in insert mode. It is not just a ^ and D

      The script should be created in /etc/init.d as root. It gets added to auto startup by issuing the command
      sudo update-rc.d homeseer defaults
      After that Homeseer will start and stop automatically when the server starts and stops

      command line Use:
      sudo service homeseer start
      sudo service homeseer stop
      sudo service homeseer restart

      Connect to the console at any time by issuing
      sudo screen -r -S HomeSeer
      Last edited by PosterBoy; January 25, 2014, 12:31 AM.

      Comment


        #4
        Great job

        Great job! I had some trouble getting it to work with Debian. I made some adjustments. I wanted it to run as non privileged user, now its working.
        Tested on Debian 7.

        Zigmund

        Code:
        #!/bin/bash
        ### BEGIN INIT INFO
        # Provides:          Homeseer
        # Required-Start:    $local_fs $syslog $time
        # Required-Stop:     $local_fs $syslog
        # Default-Start:     2 3 4 5
        # Default-Stop:      0 1 6
        # Short-Description: Start/Stop HomeSeer Server
        # Description:       Start/Stop HomeSeer Server
        ### 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 -S $NAME -d -m ./go" $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
        # --------------------------------------------------------
        when running as non-root user, please edit the file /usr/local/HomeSeer/go
        and remove the sudo command in the last line:
        Code:
        export LANG=en_US.UTF-8
        mono HSConsole.exe --log
        Last edited by zigmund; November 18, 2014, 02:50 PM. Reason: erorr in script

        Comment


          #5
          I kept it as root because in the linux installation instructions here:
          http://board.homeseer.com/showthread.php?t=162813
          Rich says you need to be root for the webserver to function. Is it working correctly as a non-root user? Can we get any clarification on the requirement to run as root?

          By the way, thanks for the for loop thing... my bash scripting skills are lacking

          Comment


            #6
            webserver port

            If you change the webserver port to 8080 (gWebSvrPort setting in settings.ini or use the setup gui when started as root) the homeseer webserver will run as non-root user.
            (you may choose a value from 1024 or higher)

            Comment


              #7
              I have just set up my HS3 Linux build to start doing some plugin work on, and I noticed the non-privileged user start script which I am trying to get working.

              I have installed this on Debian 7, copied and pasted the script and set up the hmsr user and so on, but can't get the script to execute. Would anyone have any idea's as to what I might be doing wrong?

              I have marked the script as executable etc, but get the below error.

              Cheers

              PHP Code:
              service homeseer start
              /etc/init.d/homeseerline 53syntax error near unexpected token `su'
              /etc/init.d/homeseer: line 53: 
              `                su -"/usr/bin/screen -p 0 -S $NAME -X stuff $char$USER
              HS3 PRO, Win10, WeatherXML, HSTouch, Pushover, UltraGCIR, Heaps of Jon00 Plugins, Just sold and about to move so very slim system.

              Facebook | Twitter | Flickr | Google+ | Website | YouTube

              Comment


                #8
                copy paste error

                Ow,

                I noticed 1 line in the script is incorrect, probably copy-paste error because of the ˆM characters. I changed line 43:

                Code:
                for char in $(printf "\\r s h u t d o w n \\r") ; do
                and when you configure the script to run homeseer as non-root user,
                please edit the file /usr/local/HomeSeer/go and remove the sudo command in the last line
                like this:
                Code:
                export LANG=en_US.UTF-8
                mono HSConsole.exe --log
                I tested it, it should work now

                Comment


                  #9
                  Great info guys. Have you had problems with mono crashing? I've had it crash a couple of times now and I've thought about writing a standalone watchdog to ensure mono is running by restarting if the mono pid is not found.
                  HS4Pro on a Raspberry Pi4
                  54 Z-Wave Nodes / 21 Zigbee Devices / 108 Events / 767 Devices
                  Plugins: Z-Wave / Zigbee Plus / EasyTrigger / AK Weather / OMNI

                  HSTouch Clients: 1 Android

                  Comment


                    #10
                    Newbie Linux User

                    I am a very technical user when it comes to Windows and Mac OS/X, but a novice when it comes to Linux. Up until yesterday, I had a windows PC for the sole purpose of running HS3 Pro. I finally took the plunge and installed Ubuntu on that workstation and I actually have HS3 up and running with a couple of devices added to my AEON usb stick.

                    Now I want to make sure that HS3 runs when my machine starts up. I am assuming that the scripts in MSG #3 or MSG #5 would be installed under /etc/inet.d/homeseer. As I am relatively new to Linux, I have what may be silly questions:

                    For MSG #3, can I assume that my homeseer directory be copied to "/homeseer" ?
                    For MSG #5, can I assume that my homeseer directory be copied to "/usr/local/Homeseer" ?

                    Can I also assume that if I really wanted to, I can just change the DIR variable to the location where my files are located now?

                    One of the hardest things for me to grasp is the chmod statement. If I create move my files to one of the other directories, what CHMOD statement would I use.

                    Thanks,
                    George

                    Comment


                      #11
                      /usr/local/homeseer

                      Code:
                      sudo chmod -R 755 /usr/local/HomeSeer
                      or

                      Code:
                      sudo chmod -R 755 /HomeSeer
                      you can change the DIR variable to the HomeSeer location.

                      please note:

                      to enable the startup script you have to use the following command

                      Code:
                      sudo update-rc.d homeseer defaults

                      Comment


                        #12
                        Where did you find the download? I have searching now for more than one hour on this .... site.

                        Comment


                          #13
                          link to download hs3

                          http://board.homeseer.com/showpost.p...81&postcount=1

                          Comment


                            #14
                            Can someone help? I am using the script in #5 and this is the output.

                            root@gblinux:/etc/init.d# ./homeseer start
                            error: list of process IDs must follow -p

                            Usage:
                            ps [options]

                            Try 'ps --help <simple|list|output|threads|misc|all>'
                            or 'ps --help <s|l|o|t|m|a>'
                            for additional help text.

                            For more details see ps(1).
                            bash: /usr/bin/screen: No such file or directory
                            root@gblinux:/etc/init.d#

                            Comment


                              #15
                              install screen package

                              First install the screen package with the following command

                              Code:
                              sudo apt-get install screen
                              and try again please

                              Zigmund

                              Comment

                              Working...
                              X