Last active
March 15, 2025 16:24
-
-
Save avargaskun/4d7b6ba64d0de56682a54f52e43aebf8 to your computer and use it in GitHub Desktop.
Systemd unit file for HomeSeer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=HomeSeer | |
After=network-online.target | |
Wants=network-online.target | |
[Service] | |
WorkingDirectory=/usr/local/HomeSeer | |
ExecStart=/bin/bash -lc ./go | |
ExecStop=/bin/bash ./stop | |
Restart=on-failure | |
RestartSec=30 | |
TimeoutStopSec=90 | |
[Install] | |
WantedBy=multi-user.target |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# stop - stop the HS application | |
# supports: HS application shutdown | |
hsroot=$(dirname $0) # where this script lives | |
# import login credentials used to login to web server | |
# these are ignored if password not required | |
inifile=$hsroot/Config/$(basename $0 .sh).ini | |
login= | |
test -r $inifile && . $inifile | |
# extract web server port from settings.ini | |
webport=$(awk -F= '\ | |
{ | |
gsub("\015", "") # remove CR character | |
if ($1 == "gWebSvrPort") print $2 | |
} | |
' $hsroot/Config/settings.ini) | |
# extract web server address binding, if specified | |
binding=$(awk -F= '\ | |
{ | |
gsub("\015", "") # remove CR character | |
if ($1 == "gServerAddressBind" && $2 ~ /^[0-9]*\.[0-9]*\.[0-9]*\.[0-9]*$/) print $2 | |
} | |
' $hsroot/Config/settings.ini) | |
# send application shutdown command | |
for i in $(seq 1 3) | |
do | |
curl -f -s -m 5 -o /dev/null ${login:+-u} $login --data 'ConfirmShutdownhs=Yes' "http://${binding:-localhost}${webport:+:}$webport/LinuxTools" | |
rc=$? | |
test $rc -eq 0 && break | |
curl -f -s -m 5 -o /dev/null ${login:+-u} $login --data 'action=shutdown_hs' "http://${binding:-localhost}${webport:+:}$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 | |
echo "Homeseer service successfully shut down." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment