We have moved at community.getvera.com

Author Topic: openLuup Start on Bootup using Systemctl on Raspberry Pi  (Read 1819 times)

Offline groundglass

  • Newbie
  • *
  • Posts: 15
  • Karma: +1/-3
openLuup Start on Bootup using Systemctl on Raspberry Pi
« on: March 25, 2017, 05:53:30 pm »
Another way to auto start openLuup on reboots using systemctl on a Raspberry Pi 3

I've had various degrees of successes (mainly unpredictable problems) with other projects on Raspberry Pi's with restarting programs with rc.local and crontabs. Typically it has related to when the network becomes available during the boot process. systemd has been more predictable for me. Here is how I set it up for openluup on a raspberry pi 3.

This assumes you installed openLuup at:  /etc/cmh-ludl

Create a bash script to run openLuup in the background:
Code: [Select]
sudo nano /etc/cmh-ludl/run_openLuup.sh
Code: [Select]
#!/bin/bash
echo "Starting openLuup server"
echo "To see tail of logfile: tail -f ./out.log"
cd /etc/cmh-ludl
sudo rm ./out.log
nohup ./openLuup_reload >> out.log 2>&1 &

Code: [Select]
sudo chmod +x run_openLuup.sh
Next create the systemd service for openLuup setting it up to wait for network before starting
Code: [Select]
sudo nano /etc/systemd/system/openluup.service
Code: [Select]
[Unit]
Description=openLuup and AltUI Server for Vera 3
Wants=network.target
After=network.target

[Service]
Type=forking
WorkingDirectory=/etc/cmh-ludl
ExecStart=/bin/bash /etc/cmh-ludl/run_openLuup.sh

[Install]
WantedBy=multi-user.target

Next (one time only) create the service and start openLuup. Make sure openLuup server is stopped using http://openLuupIP:3480/data_request?id=exit

Code: [Select]
sudo systemctl enable openluup
sudo systemctl start openluup

That's it. openLuup will now autostart with reboots.

Other useful commands:
Code: [Select]
sudo systemctl status openluup -l
sudo systemctl stop openluup
sudo systemctl disable openluup

Offline akbooer

  • Moderator
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +292/-70
  • "Less is more"
Re: openLuup Start on Bootup using Systemctl on Raspberry Pi
« Reply #1 on: March 26, 2017, 04:05:51 am »
This looks interesting.  I'll have a play!  Thanks.
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 Start on Bootup using Systemctl on Raspberry Pi
« Reply #2 on: September 23, 2017, 01:02:38 am »
I implemented this for the Raspberry Pi Zero W turn-key and it works great.. Many thanks !
openLuup, AltUI, Zway and HomeWave, enough said...

Offline jswim788

  • Hero Member
  • *****
  • Posts: 809
  • Karma: +58/-2
Re: openLuup Start on Bootup using Systemctl on Raspberry Pi
« Reply #3 on: September 23, 2017, 11:27:10 am »
How does this shut openLuup down?  Does it just kill the process or does it stop openLuup cleanly?  I've been using the script from @martynwendon (http://forum.micasaverde.com/index.php/topic,35681.msg263887.html#msg263887) because it does the exit request.

Offline akbooer

  • Moderator
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +292/-70
  • "Less is more"
Re: openLuup Start on Bootup using Systemctl on Raspberry Pi
« Reply #4 on: September 23, 2017, 01:23:30 pm »
Looks like stop does the right thing, issuing an exit command to openLuup.

Code: [Select]
        echo "Stopping openLuup.."
        sudo wget -q -t 1 -T 5 http://127.0.0.1:3480/data_request?id=exit

OTOH, kill does exactly what it says on the tin.
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 Start on Bootup using Systemctl on Raspberry Pi
« Reply #5 on: September 23, 2017, 04:40:13 pm »
Looks like stop does the right thing, issuing an exit command to openLuup.
That's the code from the other thread, not this one - or am I going blind?

Offline akbooer

  • Moderator
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +292/-70
  • "Less is more"
Re: openLuup Start on Bootup using Systemctl on Raspberry Pi
« Reply #6 on: September 23, 2017, 06:29:13 pm »
No... I'm going stupid.  I mis-read your post.  I think, for the reasons described in that other thread, that this will not shut openLuup down gracefully since Lua doesn't receive the signal.  Although I am no Unix expert (or any other sort, really.)
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 Start on Bootup using Systemctl on Raspberry Pi
« Reply #7 on: September 24, 2017, 12:15:52 am »
I actually added ExecStop to the openluup.service file and used curl to request the exit on localhost. I also removed the logging as I didn't see it necessary for starts/stops.

Code: [Select]
[Unit]
Description=openLuup and AltUI Server
Wants=network.target
After=network.target

[Service]
Type=forking
WorkingDirectory=/etc/cmh-ludl
ExecStart=/bin/bash /etc/cmh-ludl/run_openLuup.sh
ExecStop=curl http://localhost:3480/data_request?id=exit

[Install]
WantedBy=multi-user.target

Assuming this looks ok...
'2017-09-23 22:48:05.392   openLuup.luup:0: exiting with code 0 - after 22.9 hours'
« Last Edit: September 24, 2017, 12:19:21 am by CudaNet »
openLuup, AltUI, Zway and HomeWave, enough said...

Offline akbooer

  • Moderator
  • Master Member
  • *****
  • Posts: 6387
  • Karma: +292/-70
  • "Less is more"
Re: openLuup Start on Bootup using Systemctl on Raspberry Pi
« Reply #8 on: September 24, 2017, 02:39:44 am »
Yup, if you get that message, it's all done saving the user_data.json file.
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.