Announcement

Collapse
No announcement yet.

HS will not upgrade after the application was started as a service

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

    HS will not upgrade after the application was started as a service

    zwolfpack you requested SteveW in this post https://forums.homeseer.com/forum/hs...99#post1494999 to start a new thread. As I did populate the hypothesis I will starting this thread.

    I found the root cause for my system (during extensive testing 0n 4.2.0.0). Although I have no idea to fix.

    I repeated the steps in this post

    https://forums.homeseer.com/forum/ho...01#post1491401

    also on 4.2.0.5 with identical results.

    So the behavior of situation 1 and 2 differs

    1. Upgrade after starting HomeSeer usig ./go PASS
    2. Upgrade after starting Homeseer as a service FAIL (starting as a service following these directions: https://forums.homeseer.com/forum/ho...45#post1306645)

    By the way In case of situation 1 when I do a reinstall of HomeSeer after the first successful upgrade it will alos fail. So my hypothesis is that during the upgrade process the instance is rebooted. In case you can confirm this we will know the root cause for sure.

    Any idea how to fix?

    ---
    John

    #2
    Please post contents of your systemd unit file, i.e. /etc/systemd/system/homeseer.service

    Not clear on what you mean in your 'By the way ... ' can you provide more details of what you are doing and what is the result?

    Comment


      #3
      Another user here with the same problem. Here is my homeseer.service file contents:

      [Unit]
      Description=HomeSeer HS4 Home Automation Server
      After=network.target

      [Service]
      WorkingDirectory=/usr/local/HomeSeer
      ExecStart=/usr/bin/mono /usr/local/HomeSeer/HSConsole.exe --log
      ExecStop=/usr/local/HomeSeer/stop_homeseer.sh
      Restart=on-failure
      TimeoutStopSec=90

      [Install]
      WantedBy=multi-user.target

      Comment


        #4
        I cloned my test HS4-Linux (on rpi4) system so I could run some tests. I was successful in updating from 4.2.0.0 to beta 4.2.0.5, and back again. Ran the cycle three times to be sure.

        I then substituted in @avpman's unit file, and things went sideways fast. After some thought it came back that, under systemd, default behavior is as soon as the main process terminates, systemd immediately clobbers all child processes. So when the HSConsole process ends, the update.sh script gets clobbered before it can do it's thing. There are some additional directives needed in the unit file to make this work as we want.

        Below is my unit file (homeseer.service), with "/usr/local/HomeSeer" as the HS root. After editing files in /etc/systemd/system, you want to run
        Code:
        sudo systemctl daemon-reload
        to prevent systemd from bellyaching about changed unit files.

        Code:
        [Unit]
        Description=HomeSeer Home Automation
        Documentation=https://homeseer.com/support-home/
        After=network-online.target remote-fs.target time-sync.target
        Before=multi-user.target
        
        [Service]
        WorkingDirectory=/usr/local/HomeSeer
        ExecStart=/usr/bin/mono HSConsole.exe --log
        SyslogIdentifier=HSConsole
        StandardOutput=null
        Restart=on-failure
        RestartSec=30
        KillMode=none
        TimeoutStopSec=300
        ExecStop=/usr/local/HomeSeer/hsstop.sh
        
        [Install]
        WantedBy=multi-user.target
        Here is the hsstop.sh, which lives in the HS root. Presume this is similar to @avpman's "stop_homeseer.sh". Remember to make this executable.
        Code:
        #!/bin/bash
        # hsstop.sh - stop the HS application
        # supports: systemd service shutdown
        
        # import login credentials used to login to web server
        # these are ignored if password not required
        inifile=$(dirname $0)/Config/$(basename $0 .sh).ini
        login=
        test -r $inifile && . $inifile
        
        # extract web server port from settings.ini
        hsroot=$(dirname $0)  # where this script lives
        webport=$(awk -F= '\
        {
            gsub("\015", "") # remove CR character
            if ($1 == "gWebSvrPort") print $2
        }
        ' $hsroot/Config/settings.ini)
        
        # send application shutdown command
        for i in $(seq 1 5)
        do
            curl -f -s -o /dev/null ${login:+-u} $login --data 'ConfirmShutdownhs=Yes' "http://localhost:$webport/LinuxTools"
            rc=$?
            test $rc -eq 0 && break
            curl -f -s -o /dev/null ${login:+-u} $login --data 'action=shutdown_hs' "http://localhost:$webport/system.html"
            rc=$?
            test $rc -eq 0 && break
            sleep 2
        done
        
        killmain()
        {
            test -n "$MAINPID" && kill -0 $MAINPID && kill $MAINPID
        }
        
        trap killmain EXIT
        
        # if curl cmd unsuccessful, terminate main process
        test $rc -ne 0 && killmain
        
        # wait until all HomeSeer mono processes terminate, with timeout
        maxwait=300
        polltime=5
        mono=$(which mono) || exit
        for (( t=0; t<$maxwait; t+=$polltime ))
        do
            pgrep -afi $mono.'*'\(HSConsole\|HSPI_\) || break
            sleep $polltime
        done

        Comment


          #5
          Originally posted by zwolfpack View Post
          Please post contents of your systemd unit file, i.e. /etc/systemd/system/homeseer.service

          Not clear on what you mean in your 'By the way ... ' can you provide more details of what you are doing and what is the result?
          This is my file, looks the same as avp.
          Click image for larger version

Name:	service.PNG
Views:	647
Size:	12.6 KB
ID:	1495525
          ---
          John

          Comment


            #6
            Originally posted by John245 View Post
            This is my file, looks the same as avp.
            Did you see my subsequent post? This unit file is the source of your issue.

            Comment


              #7
              Originally posted by zwolfpack View Post
              Did you see my subsequent post? This unit file is the source of your issue.
              I changed my homeseer.service file to

              Click image for larger version

Name:	Service3.PNG
Views:	643
Size:	21.9 KB
ID:	1495533

              and did put the hsstop file in the root. No success.



              ---
              John

              Comment


                #8
                Did you restart the service?

                PS. you missed changing the path on the ExecStop directive.

                Comment


                  #9
                  Originally posted by zwolfpack View Post
                  Did you restart the service?

                  PS. you missed changing the path on the ExecStop directive.
                  Corrected. Did even a reboot. No success
                  Click image for larger version

Name:	Service4.PNG
Views:	640
Size:	81.1 KB
ID:	1495539

                  ---
                  John

                  Comment


                    #10
                    Ok, looks like we'll need to dig deeper. First of all, what OS are you running on?
                    Code:
                    more /etc/os-release
                    Next, paste this line in a command window and let it run. It will output a list of the running mono processes once every five seconds. As written it will run 200 times (about 17 minutes); change the 200 near the end to run longer.
                    Code:
                    seq -f "echo pass %g; pgrep -af mono; sleep 5" 1 200 | sh
                    On my system this shows
                    Code:
                    pass 1
                    822 /usr/bin/mono HSConsole.exe --log
                    893 /usr/bin/mono /opt/HomeSeer/HSPI_Sonos.exe
                    905 /usr/bin/mono /opt/HomeSeer/HSPI_SDJHealth.exe
                    921 /usr/bin/mono /opt/HomeSeer/HSPI_ZWave.exe
                    945 /usr/bin/mono /opt/HomeSeer/HSPI_ZWaveGui.exe
                    954 /usr/bin/mono /opt/HomeSeer/HSPI_BLLAN.exe
                    pass 2
                    822 /usr/bin/mono HSConsole.exe --log
                    893 /usr/bin/mono /opt/HomeSeer/HSPI_Sonos.exe
                    905 /usr/bin/mono /opt/HomeSeer/HSPI_SDJHealth.exe
                    921 /usr/bin/mono /opt/HomeSeer/HSPI_ZWave.exe
                    945 /usr/bin/mono /opt/HomeSeer/HSPI_ZWaveGui.exe
                    954 /usr/bin/mono /opt/HomeSeer/HSPI_BLLAN.exe
                    One line for the HSConsole, one for each running plugin. The number on the left is the process id.

                    With this running, try the update and see if the output changes.

                    Comment


                      #11
                      Originally posted by zwolfpack View Post
                      Ok, looks like we'll need to dig deeper. First of all, what OS are you running on?
                      Code:
                      more /etc/os-release
                      Next, paste this line in a command window and let it run. It will output a list of the running mono processes once every five seconds. As written it will run 200 times (about 17 minutes); change the 200 near the end to run longer.
                      Code:
                      seq -f "echo pass %g; pgrep -af mono; sleep 5" 1 200 | sh
                      On my system this shows
                      Code:
                      pass 1
                      822 /usr/bin/mono HSConsole.exe --log
                      893 /usr/bin/mono /opt/HomeSeer/HSPI_Sonos.exe
                      905 /usr/bin/mono /opt/HomeSeer/HSPI_SDJHealth.exe
                      921 /usr/bin/mono /opt/HomeSeer/HSPI_ZWave.exe
                      945 /usr/bin/mono /opt/HomeSeer/HSPI_ZWaveGui.exe
                      954 /usr/bin/mono /opt/HomeSeer/HSPI_BLLAN.exe
                      pass 2
                      822 /usr/bin/mono HSConsole.exe --log
                      893 /usr/bin/mono /opt/HomeSeer/HSPI_Sonos.exe
                      905 /usr/bin/mono /opt/HomeSeer/HSPI_SDJHealth.exe
                      921 /usr/bin/mono /opt/HomeSeer/HSPI_ZWave.exe
                      945 /usr/bin/mono /opt/HomeSeer/HSPI_ZWaveGui.exe
                      954 /usr/bin/mono /opt/HomeSeer/HSPI_BLLAN.exe
                      One line for the HSConsole, one for each running plugin. The number on the left is the process id.

                      With this running, try the update and see if the output changes.
                      OS:
                      NAME="Ubuntu"
                      VERSION="20.04.3 LTS (Focal Fossa)"
                      ID=ubuntu
                      ID_LIKE=debian
                      PRETTY_NAME="Ubuntu 20.04.3 LTS"
                      VERSION_ID="20.04"
                      HOME_URL="https://www.ubuntu.com/"
                      SUPPORT_URL="https://help.ubuntu.com/"
                      BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
                      PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-poli
                      cy"
                      VERSION_CODENAME=focal
                      UBUNTU_CODENAME=focal

                      Running processes:
                      pass 66
                      644 /usr/bin/mono /home/dunnenj/HomeSeer/HSConsole.exe --log
                      727 /usr/bin/mono /usr/lib/mono/4.5/xsp4.exe --port 8084 --address 0.0.0.0 --appconfigdir /etc/xsp4 --nonstop
                      1194 /usr/bin/mono /home/dunnenj/HomeSeer/HSPI_EasyTrigger.exe
                      1211 /usr/bin/mono /home/dunnenj/HomeSeer/HSPI_Chromecast.exe
                      1226 /usr/bin/mono /home/dunnenj/HomeSeer/HSPI_SKWARE_DEVICE_HISTORY.exe
                      1267 /usr/bin/mono /home/dunnenj/HomeSeer/HSPI_ZWave.exe
                      1302 /usr/bin/mono /home/dunnenj/HomeSeer/HSPI_ZWaveGui.exe
                      1332 /usr/bin/mono /home/dunnenj/HomeSeer/HSPI_ULTRANETATMO3.exe
                      1347 /usr/bin/mono /home/dunnenj/HomeSeer/HSPI_Unifi.exe
                      1368 /usr/bin/mono /home/dunnenj/HomeSeer/HSPI_Worx.exe
                      1385 /usr/bin/mono /home/dunnenj/HomeSeer/HSPI_Tuya.exe
                      1404 /usr/bin/mono /home/dunnenj/HomeSeer/HSPI_SmartThings.exe
                      1414 /usr/bin/mono /home/dunnenj/HomeSeer/HSPI_SmartMeter.exe
                      1444 /usr/bin/mono /home/dunnenj/HomeSeer/HSPI_BLPlex.exe

                      I see no changes before during or after the update. The big difference compared with your output is in red.

                      ---
                      John

                      Comment


                        #12
                        zwolfpack, excellent information! Thanks.

                        rjh, to your questions in another thread: personally, since I run HS4 on a dedicated RPi 4, I don't care how the software is started; as a task or as a service, and I don't mind having the upgrade procedure reboot the system. Of course, others will have different needs and preferences.

                        IMO, one long-time issue with HS for Linux is that the installation procedure is not thoroughly documented, and it assumes some specific Linux concepts and commands that may be ambiguous or unclear to non Linux experts. Going back to 2019 or earlier, there are various long threads with various posters adding their own sets of commands, and some have typos, are incomplete, or are unclear. To the poster (you know who you are) who may reply with the typical Linux arrogance that if you don't know what you are doing, then don't use Linux (or "RTFM"), that's unhelpful. Linux is for everyone, and helping users learn is part of the fun of it.

                        Comment


                          #13
                          The item in red is due to having installed mono via 'mono-complete' rather than 'mono-devel'. (mono-devel is what is directed in the HS install documentation).

                          In previous versions of the update.sh this would cause an issue. However recently HS took a suggestion from me and made a change which should ignore this.

                          In your HS root, please verify that update.sh looks like this:
                          Code:
                          #!/bin/bash
                          # first make sure HS is shut down
                          while pgrep -af mono.'*'\(HSConsole\)
                          do
                              sleep 5
                          done
                          
                          # extract the update files and reboot
                          echo extracting $1
                          tar xvf $1
                          rm $1
                          echo "Update complete"
                          reboot
                          xsp4.exe is a documentation server which has no use in this application. You can safely remove it via
                          Code:
                          sudo apt remove mono-xsp --auto-remove
                          This begs the question though, as to why HomeSeer continues to run once the update is commanded. Can you check if the process id of the HSConsole process stays constant?

                          Comment


                            #14
                            Originally posted by zwolfpack View Post
                            The item in red is due to having installed mono via 'mono-complete' rather than 'mono-devel'. (mono-devel is what is directed in the HS install documentation).

                            In previous versions of the update.sh this would cause an issue. However recently HS took a suggestion from me and made a change which should ignore this.

                            In your HS root, please verify that update.sh looks like this:
                            Code:
                            #!/bin/bash
                            # first make sure HS is shut down
                            while pgrep -af mono.'*'\(HSConsole\)
                            do
                            sleep 5
                            done
                            
                            # extract the update files and reboot
                            echo extracting $1
                            tar xvf $1
                            rm $1
                            echo "Update complete"
                            reboot
                            xsp4.exe is a documentation server which has no use in this application. You can safely remove it via
                            Code:
                            sudo apt remove mono-xsp --auto-remove
                            This begs the question though, as to why HomeSeer continues to run once the update is commanded. Can you check if the process id of the HSConsole process stays constant?
                            I found the issue. Although I followed all directions the homeseer.service file did not change in Webmin. I deleted it from Webmin and did set-up a new service. This solved the issue.

                            Thanks for all the help, much appreciated.

                            This should be part of HomeSeer's standard instruction on how to install Linux.

                            ---
                            John

                            Comment


                              #15
                              Originally posted by John245 View Post

                              I found the issue.
                              ...
                              ---
                              John
                              Awesome! I'll sleep better now - it's getting late here

                              Comment

                              Working...
                              X