Announcement

Collapse
No announcement yet.

How-To Start HS3 on Linux using systemd

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

  • How-To Start HS3 on Linux using systemd

    Startup with systemd

    Systemd:

    Systemd is the standard start-up, or initialization system (init for short) for modern Linux. It replaces SysV init and Upstart. Instructions for those two can be found elsewhere on the forums.

    Systemd provides a number of benefits, but there is an admitted learning curve. There is much documentation in the man pages (Do <tt class="docutils literal"># man systemd</tt>, <tt class="docutils literal"># man systemctl</tt>, and <tt class="docutils literal"># man journalct</tt> in your favorite terminal). You interact with systemd through the <tt class="docutils literal">systemctl</tt> commands. The basic commands, executed as superuser <tt class="docutils literal">root</tt>, are:

    Code:
    # systemctl start something.service
    # systemctl status something.service
    # systemctl stop something.service
    This will allow you to start some service, check it's status and stop it. Configuration options are stored in unit files - the <tt class="docutils literal">something.service</tt> file. These contain the actual commands needed to start any particular service. Not only can they start programs and services, they can also mount media, set up devices and do other system things.

    Basically, to get HomeSeer3 running, we need to create a new Service Unit file and some supporting scripts.

    Start Up:

    To get HomeSeer up and running, we need to first create the text file:

    Code:
    /etc/systemd/system/homeseer.service
    This is a custom addition to systemd's repertoire of start-up scripts. The <tt class="docutils literal">homeseer.service</tt> file will tell systemd that HomeSeer exists and how to start and stop it. Note that systemd keeps local configuration files in <tt class="docutils literal">/etc/systemd/system/</tt>. The files in this directory override default system files and so provide a place for custom configurations. Further, they are not overwritten during system updates, so we only have to do it once.

    Now put this code in it:

    Code:
    [Unit]
    Description=HomeSeer HS3 Home Automation Server
    After=network.target
    
    [Service]
    WorkingDirectory=/opt/HomeSeer
    ExecStart=/usr/bin/mono /opt/HomeSeer/HSConsole.exe --log
    ExecStop=/opt/HomeSeer/stop_homeseer.sh
    Restart=on-failure
    TimeoutStopSec=90
    
    [Install]
    WantedBy=multi-user.target
    A bit of an explanation:

    This assumes that HomeSeer is installed in <tt class="docutils literal">/opt/HomeSeer/</tt>.

    Lines 1 & 2 tell systemd about a new service - HomeSeer3.

    Line 3 says that HS3 should be started after the network is started - which usually means all basic system service are up and running. It is necessary if we want HomeSeer to communicate with other things via the network.

    The [Service] section describes the environment and commands that are used to run HS3.

    Line 5 is the HomeSeer working directory - the path to the HomeSeer files.

    Line 6 is the actual command executed to start HS3.

    Line 7 is the stop command.

    Line 8 tells systemd to restart HS3 if it stops running due to failure.

    Line 9 is how long systemd should wait for HS3 to stop - once this time passes systemd assumes that HS3 has hung, and will kill it should it still be running.

    Lines 10 & 11 say that HomeSeer should be started in the multi-user target - formerly know as runlevel 3 - and will cause HS3 to be started every normal bootup.

    You may want to use <tt class="docutils literal">Restart=always</tt> on line 8. This will cause HS3 to be restarted every time it exits by means other than <tt class="docutils literal">systemctl stop homeseer</tt>. This is useful if, say, someone accidentally shuts down HS3 from the web interface.

    Now enable the service:

    Code:
    # systemctl enable homeseer.service
    Enabling the service is not the same as starting it. Enabling tells systemd to create the appropriate links in the <tt class="docutils literal">/etc/systemd/system/*.wants/</tt> directories. Thus, when you restart the computer, HS3 will start. But to get it running right now you need to execute:

    Code:
    # systemctl start homeseer.service
    This will be enough to get HS3 running when you start up. But it won't cleanly shutdown because HS3 doesn't handle Unix signals. It involves a few more files to get a clean shutdown.

    Shutdown

    There are two ways to cleanly shutdown HomeSeer, you only need to use one.

    Using Linux Tools:

    It is possible to use the built-in Linux Tools menu to shutdown HomeSeer.

    First create:

    Code:
    /opt/HomeSeer/stop_homeseer.sh
    Add this code:

    Code:
    #!/bin/bash
    /usr/bin/curl --user username:password 'http://127.0.0.1/LinuxTools' -H 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8' --data 'ConfirmShutdownhs=Yes' --compressed
    sleep 10s
    If you don't require a password for local users, you should leave out the <tt class="docutils literal">--user</tt> option. Depending on what plug-ins you have enabled, you may need to increase the timeout delay.

    Using HS3 Scripts:


    A second method involves using a custom HS3 event and script to shutdown HomeSeer.

    First create:

    Code:
    /opt/HomeSeer/stop_homeseer.sh
    With this:

    Code:
    #!/bin/bash
    cd /opt/HomeSeer
    /usr/bin/curl --user username:password 'http://127.0.0.1:80/JSON?request=runevent&group=Admin&name=Shutdown'
    sleep 30s
    If you don't require a password for local users, you should leave out the <tt class="docutils literal">--user</tt> option.

    Then create:

    Code:
    /opt/HomeSeer/scripts/DoShutdown.vb
    With this code:

    Code:
    sub Main(parm as object)
      hs.WriteLog("DoShutdown", "Starting shutdown....")
      hs.Shutdown
    End Sub
    Now go into HS3 itself and create an event named <tt class="docutils literal">Shutdown</tt> in an <tt class="docutils literal">Admin</tt> group. Have it be <tt class="docutils literal">Manually Triggered</tt> and have it <tt class="docutils literal">Run a Script or Command</tt> and choose the <tt class="docutils literal">../scripts/DoShutdown.vb</tt> file.

    <hr class="docutils">
    In either case, executing:

    Code:
    # systemctl stop homeseer.service
    will stop the HomeSeer service. And this should be enough to give you a clean start and stop on reboots. It works on OpenSuSE and Ubuntu and I would expect it to work on Debian and Fedora. You will need to adjust the paths for your specific installation of course.

    Special thanks to jon102034050, whippersnapper and ZoRaC in http://board.homeseer.com/showthread.php?t=182156. From which most of this material was taken.

    -Alex

  • #2
    Thanks for posting this!
    HS3Pro Running on a Raspberry Pi3
    64 Z-Wave Nodes, 168 Events, 280 Devices
    UPB modules via OMNI plugin/panel
    Plugins: Z-Wave, BLRF, OMNI, HSTouch, weatherXML, EasyTrigger
    HSTouch Clients: 3 Android, 1 Joggler

    Comment


    • #3
      Not a Ubuntu Linux expert here but learning. Is there a difference in the way that HomeSeer runs using this method as opposed to launching it with the ./go command? I do see that there is no console window visible when Ubuntu reboots but does that matter?
      If it ain't broke, don't fix it!

      Comment


      • #4
        OP posted script is starting a service such that you can utilize these commands in a terminal session

        systemctl start name.service start
        systemctl start name.service stop
        systemctl start name.service restart

        This creats a PID.

        the ./go command is a start script to start Homeseer. Typically you would leave the terminal window open. That said you can test Homeseer starting this way and look at the dialog for errors.

        Another way is to use a boot up cron script which starts Homeseer on boot. I also utilize this command and the GUI shut down Homeseer command.

        Yet another way is to auto login a user on reboot and configure an autostart in the XWindows GUI (like in Windows).

        There is a lot of flexibility here.

        The original Homeseer Zee just put the start up command in the bootup script /etc/sysctl.conf and had HomeSeer installed in the /usr/local/HomeSeer directory. Personally here installed homeseer in the root directory /HomeSeer. ...easier to find and less typing for me.
        Other users put it in the /opt/HomeSeer directory. Just remember to change the hard scripts in the directory.

        What you do not want to do is start HomeSeer twice which I have seen done by accident. To check if Homeseer is running in a command line use the top command. You will see mono processes running telling you that Homeseer is running.

        I do see that there is no console window visible when Ubuntu reboots but does that matter?

        No. Personally I do look at the console window when testing a new plugin and do not enable console views when running stable.

        Using the Zoneminder box here always run it as a service and similiar to Apache2. If I want to make changes in Zoneminder or Apache2 I stop the service, make the changes and start the service or I just restart the services.

        There is no right or wrong way to do this. Over the years there are just more checks and balances relating to startup programs. IE: today with Ubuntu 16.04/10 you have programs/scripts which check programs/scripts which check programs/scripts. For just running the meat of Homeseer you do not need a desktop GUI and in fact it just adds resource utilization and doesn't really help in running Homeseer. IE: you do not see it running in the desktop and if you utilize the desktop browser you are just taking away resources from the main OS. Here I short cut SSH managment a bit using Webmin which is a web based management tool. It is light.
        Last edited by Pete; May 7th, 2017, 12:59 PM.
        - Pete

        Auto mator
        Homeseer 3 Pro - 3.0.0.534 (Linux) - Ubuntu 18.04/W7e 64 bit Intel Haswell CPU - Mono 6.00
        Homeseer Zee2 (Lite) - 3.0.0.534 (Linux) - Ubuntu 18.04/W7e - CherryTrail x5-Z8350 BeeLink 4Gb BT3 Pro - Mono 6.00

        X10, UPB, Zigbee, ZWave and Wifi MQTT automation.

        Comment


        • #5
          Originally posted by happnatious1 View Post
          Not a Ubuntu Linux expert here but learning. Is there a difference in the way that HomeSeer runs using this method as opposed to launching it with the ./go command? I do see that there is no console window visible when Ubuntu reboots but does that matter?
          Both the go script and the /etc/systemd/system/homeseer.service script exectute the same start command:
          Code:
          /usr/bin/mono /opt/HomeSeer/HSConsole.exe --log
          The main difference is that the mono log entries you see via go's console will now be written to Ubuntu's syslog (/var/log/syslog).

          Not a bad way to get a tail-able text version of the HS3 log database entries!!

          You can configure syslog as to what is put in syslog, different files for each service, or disable all together.

          Comment

          Working...
          X