Version 1.1.15 released

I’m probably not the best prrson to answer as I’ve only used Mosquitto. I think David and Gene were talking about it at the time, so maybe he can be a better guide.

I use it :slight_smile:

looking at the github repo - this is recommended as the replacement and looks worth a shot: https://github.com/chkr1011/MQTTnet also supports .net core which is a must for any new component Imho.

Issue 40 raised: https://github.com/Bounz/HomeGenie-BE/issues/40

1 Like

This may be a bit off topic, but I figure someone may have a thought. I have a Stretch installation that has been working ok for around a week. I just tried to restart it and it basically refused. Running either “sudo halt” or “sudo reboot” didn’t do anything. The system waited for a while but the prompt came right back eventually. I haven’t tried anything yet because I’m not sure how to fix this. I could start over, but I’m trying to be smarter rather than just start over.

Don’t know if it the same in the end. But I usually use “sudo shutdown -r now” when I reboot. Or -h if you want it to turn off. But maybe it is the same thing happening in the background?

Are you starting/stopping HG using Systemd.

Check out this link https://www.raspberrypi.org/documentation/linux/usage/systemd.md

This is the simplest way to manage the starting/stopping/enabling/disabling of HG.

The system is SUPER laggy now. I checked TOP and don’t see anything using CPU, but the load is really high (51.00). Man says that that means I’m using many times more than the resources the CPU can handle, even though the CPU isn’t doing anything. That may not directly be the issue, but I think it’s related.

I don’t see HG in the top list and I can’t do anything with the service either:

pi@RPi3:~ $ sudo service homegenie status
Failed to retrieve unit: Connection timed out
Failed to get properties: Connection timed out

I don’t know how to kill the service if that’s what’s hanging things up and I can’t reboot or shut down, so I currently only have the plug as an option. I know I could do that, but, like I said, I’m trying to learn the smarter way. Any other suggestions?

Did you have that problem running v526. Seems very strange indeed. Do you have logging turned on in HG. If so what are they reporting.

I suggest that in this case “pull the plug” restart the Pi and stop the service running. From there launch HG manually from a terminal in debug mode and leave it running to examine any possible faults that may arise.

As far as I know the HG service could only ever be restarted from within HG and never had a shutdown option. I suppose you could create a script from within HG to do that.

The Systemd route would really be the way to go.

Can’t you just find the PID and kill HG? Or probably the mono process.

ps -ef | grep homegenie.exe (or something similar, don’t remember exactly)
And then kill -9 for the PID you get.

ps -ef | grep …

That was my first thought actually. I also tried top to see if anything was obvious since ps just hung. I tried pkill -9 homegenie but it also just hung.

As a last resort, I googled the error I get when I try to shutdown. It appears the best I could locate was a Linux forum bashing on systemd as it apparently has a lot of problems. They indicated that this is just something that happens sometimes when using systemd. If so, I guess I’ll just reboot by pulling the plug and hope it doesn’t happen again. If so, I might just start a new image.

After hard cycling the power, I tried software reboot “sudo reboot” and it worked correctly. I looked at top right away and load average was 0.84 in the first column. After watching for a few minutes, that number has steadily increased to 1.05. I’ll keep watching, but I suspect there is a process that is a problem. I’ve read that I should have a very low number for the load average since 1 indicates 100% utilization.

Mono is at close to 100% though, so perhaps it’s true. I’m not sure why mono is pulling so much cpu time though.

EDIT:
After stopping the service and starting it in debug mode, the listing in top is more reasonable (peak of 50% or so) and the load is realistic (0.02 currently). I’ll keep it running in debug mode for now to see if I can spot an issue. All of this is very strange and not something I ever saw with Gene’s code on Jessie. I don’t know if this is a Stretch issue or maybe something that’s changed in the new version.

EDIT 2:
I think there is an issue with the service for HG but not HG itself. I launched the service and it’s consistently showing as using very high cpu loads in top (over 200% at the moment). If I stop the service and run /usr/local/bin/homegenie/startup.sh (the same file the service is launching) HG only uses around 1% cpu.

If you create a simple Systemd I imagine it will solve that problem

This basic link might help https://www.raspberrypi.org/documentation/linux/usage/systemd.md

HG already runs as a service. Does that mean I should dissable it somehow ib order to switch service implenentations?

/etc/init.d/homegenie:

#!/bin/bash
### BEGIN INIT INFO
# Provides:          homegenie
# Required-Start:    $all
# Required-Stop:
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Run HomeGenie
### END INIT INFO

# Load the VERBOSE setting and other rcS variables
. /lib/init/vars.sh

# Define LSB log_* functions.
# Depend on lsb-base (>= 3.0-6) to ensure that this file is present
. /lib/lsb/init-functions

NAME="homegenie"
SCRIPTNAME=/etc/init.d/$NAME
USER="root"
PID_FILE="/tmp/homegenie.pid"
INSTALL_PATH="/usr/local/bin"  # <------ CHANGE INSTALL PATH HERE IF NEEDED
HOMEGENIE_FOLDER=$INSTALL_PATH/homegenie
HOMEGENIESH=$HOMEGENIE_FOLDER/startup.sh

# Wait for encrypted folder to be mounted
#cat /etc/mtab | grep -q $INSTALL_PATH
#while [ $? -ne 0 ] ; do
#        sleep 5
#        cat /etc/mtab | grep -q $INSTALL_PATH
#done

case "$1" in

start)

    start-stop-daemon --start --background --make-pidfile --pidfile $PID_FILE \
                      --chuid $USER --exec $HOMEGENIESH -- $HOMEGENIE_FOLDER
    log_success_msg "$NAME started"
    ;;

stop)

    start-stop-daemon --stop --pidfile $PID_FILE \
                      --retry 5
    kill -s SIGINT $(ps aux | grep -v grep | grep HomeGenie.exe | awk '{print $2}')
    log_success_msg "$NAME stopped"
    ;;

status)

    ps -ef | grep -v grep | grep HomeGenie.exe
    if [ $? -eq 1 ]
    then
        log_success_msg "$NAME not running"
        exit 3
    else
        log_success_msg "$NAME is running"
    fi

    ;;

restart)

    $0 stop
    $0 start
    ;;


*)

    log_action_msg "Usage: $SCRIPTNAME {start|stop|status|restart}"
    exit 2
    ;;

esac
exit 0

/usr/local/bin/homegenie/startup.sh

#!/bin/sh
#
# Usage: startup_debug.sh <homegenie_folder_path>
# Example: ./startup_debug.sh /usr/local/bin/homegenie
#
cd "`dirname \"$0\"`"
ENCFIX=""
#ENCFIX="LC_NUMERIC=en_US LC_MONETARY=en_US LC_MEASUREMENT=en_US "
# !!!NOTE!!!
# "LC_NUMERIC=en_US LC_MONETARY=en_US LC_MEASUREMENT=en_US" was added as a work-around 
# for some buggy mono installations, uncomment if you're experiencing problems with decimal number parsing
if [ -f /usr/bin/mono ]
then
    MONO="$ENCFIX/usr/bin/mono"
else
    MONO="$ENCFIX/usr/local/bin/mono"
fi

EXITCODE="1"
while [ "$EXITCODE" = "1" ]; do
    if [ -z "$1" ]
    then
        sudo $MONO HomeGenie.exe 
    else
        cd $1
        sudo $MONO HomeGenie.exe >/dev/null  2>&1 
    fi
    EXITCODE="$?"
    echo "Exit code: $EXITCODE"
done

The only real difference between running the service and startup.sh directly is possibly the user. I think the service starts with root and when I launch startup.sh i run as pi.

Systemd manages your system a lot more efficiently than init particularly when you experience problems. It’s worth reading up on it a little more. They are quite easy to create too. This article is worth a read http://www.linux-magazine.com/Issues/2017/200/Tutorials-Systemd

As far as I know you can install HG without any startup scripts and then create your own Systemd

When I install HG, it automatically creates the init.d service. How do you install so that’s not the case?

wget https://github.com/genielabs/HomeGenie/releases/download/v1.1-beta.526/homegenie_1_1_beta_r526.tgz
tar xzvf homegenie_1_1_beta_r526.tgz

That should install the basic package without startup scripts.

A vanilla version of Stretch Lite plus the above and any other dependencies should get you going.

That wont install… that will just unzip…

Have you tried it David. HomeGenie.exe is there

Actually, unzipping archive is some kind of installation for HomeGenie :slight_smile:
I played a little bit with systemd on my Pi, here you can find file with service description: https://github.com/Bounz/HomeGenie-BE/blob/HGBE-38/BaseFiles/Common/homegenie.svc

After copying it somewhere on your system you can execute following commands to setup the service:

sudo cp homegenie.svc /etc/systemd/system/homegenie.service
sudo systemctl daemon-reload

and use it:

sudo systemctl start homegenie
sudo systemctl stop homegenie
1 Like