We have moved at community.getvera.com

Author Topic: openLuup: init.d script  (Read 2586 times)

Offline martynwendon

  • Full Member
  • ***
  • Posts: 120
  • Karma: +15/-1
openLuup: init.d script
« on: January 09, 2016, 04:56:11 am »
So I whipped up a quick init.d script for openLuup, it works well for me on debian based systems.

To use it (some knowledge of Linux is assumed with the below commands):

create a file "openLuup" in /etc/init.d using your editor of choice
copy / paste script from below & save the file
make the file executable
test it, make sure you're happy with it (/etc/init.d/openLuup start)
execute "update-rc.d openLuup defaults" to activate it on start / stop of Linux

It supports "start/stop/restart/reload/kill"

Couple of notes:

I don't think openLuup is Linux "signal" aware (at least it didn't exit / restart cleanly when the process was sent signals).  So it's not possible to use traditional stop / start / reload methods (as I understand it, it's very difficult to make lua stuff signal aware, so this likely won't change).  I used wget to call the exit / reload urls on localhost instead.

I like to run things like openLuup under a "screen" session as it means if they bomb out you should still be able to access the screen session and see any stdout / stderr fallout that may not make it into any log files.  To resume the screen session use "screen -R -d -r openLuup" (will likely be a blank screen unless openLuup is outputting anything to stdout / stderr at the time).

Tail your log file using "tail -F /etc/cmh-ludl/LuaUPnP.log" - capital "F" makes tail follow the log file continuously and also re-open the file if it get's rotated.

Code: [Select]
#! /bin/sh
# Starts and stops openLuup
# /etc/init.d/openLuup
### BEGIN INIT INFO
# Provides:     openLuup
# Required-Start:       $syslog
# Required-Stop:        $syslog
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description:    openLuup
### END INIT INFO

#Load up openLuup when called
case "$1" in
start)
        echo "Starting openLuup.."
        cd /etc/cmh-ludl
        sudo screen -dmS openLuup Utilities/openLuup_reload
        echo "ok"
;;
stop)
        echo "Stopping openLuup.."
        sudo wget -q -t 1 -T 5 http://127.0.0.1:3480/data_request?id=exit
        echo "ok"
;;
kill)
        echo "Killing openLuup.."
        sudo screen -S openLuup -X quit
        echo "ok"
;;
restart)
        echo "Restarting openLuup.."
        $0 stop
        $0 start
;;
reload)
        echo "Reloading openLuup.."
        sudo wget -q -t 1 -T 5 http://127.0.0.1:3480/data_request?id=reload
        echo "ok"
;;
*)
        echo "Usage: $0 {start|stop|reload|restart|kill}"
        exit 1
esac

Screenshot of it in action attached!

If you're lucky, akbooer might include this in the official download / manual, removing some of the manual steps above :)

Offline CudaNet

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1401
  • Karma: +42/-11
  • Chimichanga !
Re: openLuup: init.d script
« Reply #1 on: January 10, 2016, 11:12:47 am »
Thanks @martynwendon

I'd love to incorporate this into the step-by-step guides I've been giving out which supplements Akbooer's guide. When I get some time I'd like to try this out and I might have some questions although you've done a great job of describing everything.
openLuup, AltUI, Zway and HomeWave, enough said...

Offline akbooer

  • Moderator
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +292/-70
  • "Less is more"
Re: openLuup: init.d script
« Reply #2 on: January 10, 2016, 11:47:04 am »
Certainly no problem to include this, or similar, in the distribution, although it would not work on my Yun which doesn't out-of-the-box have the screen command.
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline jswim788

  • Hero Member
  • *****
  • Posts: 809
  • Karma: +58/-2
Re: openLuup: init.d script
« Reply #3 on: February 26, 2017, 10:13:46 pm »
I'm trying to use this with the Z way server, but the problem is that this starts too quickly - before the Z way server has started up.  Any idea how to make this dependent on the Z way server starting up?  I believe systemd may handle dependencies, but I haven't looked at it much.  Is that a better approach?

Offline akbooer

  • Moderator
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +292/-70
  • "Less is more"
Re: openLuup: init.d script
« Reply #4 on: February 27, 2017, 03:10:49 am »
A simple fix might be to add a delay in the ZWay plugin' startup code.
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline jswim788

  • Hero Member
  • *****
  • Posts: 809
  • Karma: +58/-2
Re: openLuup: init.d script
« Reply #5 on: February 28, 2017, 12:31:27 am »
This worked for me.  I added the z-way-server to the dependencies and added a sleep.  I also added a variable for the openLuup location.  And I made it run as 'pi' instead of root.
Code: [Select]
#! /bin/sh
# Starts and stops openLuup
# /etc/init.d/openLuup
### BEGIN INIT INFO
# Provides:     openLuup
# Required-Start:       $syslog z-way-server
# Required-Stop:        $syslog
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description:    openLuup
### END INIT INFO

OPENLUUP_HOME="/home/pi/LuaDevZway"

#Load up openLuup when called
case "$1" in
start)
        echo "Starting openLuup in 10 seconds..."
# sleep 10 in order to let Z way server startup
sleep 10
        # cd /etc/cmh-ludl
        cd $OPENLUUP_HOME
        # sudo screen -dmS openLuup ./openLuup_reload
# run as pi
        su -c 'screen -dmS openLuup ./openLuup_reload' pi
        echo "ok"
;;
stop)
        echo "Stopping openLuup.."
        # sudo wget -q -t 1 -T 5 http://127.0.0.1:3480/data_request?id=exit
        wget -q -t 1 -T 5 http://127.0.0.1:3480/data_request?id=exit
        echo "ok"
;;
kill)
        echo "Killing openLuup.."
        # sudo screen -S openLuup -X quit
        screen -S openLuup -X quit
        echo "ok"
;;
restart)
        echo "Restarting openLuup.."
        $0 stop
        $0 start
;;
reload)
        echo "Reloading openLuup.."
        # sudo wget -q -t 1 -T 5 http://127.0.0.1:3480/data_request?id=reload
        wget -q -t 1 -T 5 http://127.0.0.1:3480/data_request?id=reload
        echo "ok"
;;
*)
        echo "Usage: $0 {start|stop|reload|restart|kill}"
        exit 1
esac

Offline akbooer

  • Moderator
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +292/-70
  • "Less is more"
Re: openLuup: init.d script
« Reply #6 on: March 01, 2017, 05:40:48 am »
Thanks for this update.  To be honest, I hardly ever reload or reboot my openLuup systems, so a hard-wired startup in rc.local works fine.

On the day that all my Vera systems reloaded together (ie. the start of the month) I just checked the uptime of the openLuup systems... my RPi one has been running without a reload for just 100 days!  See attached.

Having reached this significant milestone I now do need to take it down to install a MySensors radio gateway since my Arduino Yun system bit the dust (down forever!) so maybe I'll try out this script anyway.

 
3x Vera Lite-UI5/Edge-UI7, 25x Fibaro, 23x TKB, 9x MiniMote, 2x NorthQ Power, 2x Netatmo, 1x Foscam FI9831P, 9x Philips Hue,
Razberry, MySensors Arduino, HomeWave, AltUI, AltHue, DataYours, Grafana, openLuup, ZWay, ZeroBrane Studio.

Offline CudaNet

  • Beta Testers
  • Hero Member
  • *****
  • Posts: 1401
  • Karma: +42/-11
  • Chimichanga !
Re: openLuup: init.d script
« Reply #7 on: March 01, 2017, 08:59:59 am »
Yes, much appreciated @jswim788... Once I get some bandwidth I'd like to add this to the turn-key's. I too hardly ever operate openLuup at the CLI anymore (load and go right !). I still smile every time I get into the UI and discover I've been up for weeks or months. It's a wonderful thing !

This worked for me.  I added the z-way-server to the dependencies and added a sleep.  I also added a variable for the openLuup location.  And I made it run as 'pi' instead of root.
Code: [Select]
#! /bin/sh
# Starts and stops openLuup
# /etc/init.d/openLuup
### BEGIN INIT INFO
# Provides:     openLuup
# Required-Start:       $syslog z-way-server
# Required-Stop:        $syslog
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description:    openLuup
### END INIT INFO

OPENLUUP_HOME="/home/pi/LuaDevZway"

#Load up openLuup when called
case "$1" in
start)
        echo "Starting openLuup in 10 seconds..."
# sleep 10 in order to let Z way server startup
sleep 10
        # cd /etc/cmh-ludl
        cd $OPENLUUP_HOME
        # sudo screen -dmS openLuup ./openLuup_reload
# run as pi
        su -c 'screen -dmS openLuup ./openLuup_reload' pi
        echo "ok"
;;
stop)
        echo "Stopping openLuup.."
        # sudo wget -q -t 1 -T 5 http://127.0.0.1:3480/data_request?id=exit
        wget -q -t 1 -T 5 http://127.0.0.1:3480/data_request?id=exit
        echo "ok"
;;
kill)
        echo "Killing openLuup.."
        # sudo screen -S openLuup -X quit
        screen -S openLuup -X quit
        echo "ok"
;;
restart)
        echo "Restarting openLuup.."
        $0 stop
        $0 start
;;
reload)
        echo "Reloading openLuup.."
        # sudo wget -q -t 1 -T 5 http://127.0.0.1:3480/data_request?id=reload
        wget -q -t 1 -T 5 http://127.0.0.1:3480/data_request?id=reload
        echo "ok"
;;
*)
        echo "Usage: $0 {start|stop|reload|restart|kill}"
        exit 1
esac
openLuup, AltUI, Zway and HomeWave, enough said...

Offline martynwendon

  • Full Member
  • ***
  • Posts: 120
  • Karma: +15/-1
Re: openLuup: init.d script
« Reply #8 on: March 02, 2017, 06:09:47 pm »
my RPi one has been running without a reload for just 100 days!

One of my RPi has over 4 years uptime, they're resilient to say the least  8)

Code: [Select]
root@incrediblepbx:~# uptime
 23:04:19 up 1578 days,  6:19,  1 user,  load average: 0.00, 0.01, 0.05

This one runs my phone system ....... Linux, even if it's broke, 99.99% of the time there's no need to reboot it  ;D

Suck on that Micro$oft!