Ha-bridge: Running from rc.local

Created on 11 May 2016  路  6Comments  路  Source: bwssytems/ha-bridge

When I run the bridge from the console it works and save the config file relative to the java package for example if my java package is in /home/pi/link/habridge then the conf file is in /home/pi/habridge/data/habridge.conf

When i run from rc.local, no matter what i do, it wants to save the the file to a data dir in the root of the file system.

I have tried many variations of this, what am i doing wrong?

sudo -u pi /usr/bin/java -jar -Dserver.port=9090 /home/pi/link/habridge/ha-bridge-2.0.5.jar -d /home/pi/link/habridge/ > /dev/null 2>&1 &

question

All 6 comments

Try to start with option: -Dconfig.file=/etc/habridge/habridge.config

Here is the way I have mine start.
Command I run from rc.local: su -l -c "/home/pi/startup.sh" pi &

!/bin/bash

This is /home/pi/startup.sh

/home/pi/starteb.sh
/home/pi/startscript2.sh
/home/pi/startscript3.sh

!/bin/bash

This is /home/pi/starteb.sh

cd /home/pi/habridge
nohup java -jar -Dserver.port=9090 ha-bridge-2.0.5.jar > /home/pi/habridge.log 2>&1 &

It seems to set up the base directory in whatever directory you are in when you run the java script. I think rc.local runs as root, so even though you use sudo -u pi, I think it is still executing the command in the root directory

@paulv888 thanks, i tried that first and that resulted in a 500 error as it couldn't create file / said file was missing

@dmoos777 thanks i like that, looks elegant, after i posted i found this also works (calling a bash shell, though i have no idea why this needs it and the other apps in rc.local don't - but then i am a windows guy and pi dragged me kicking and screaming to linux :-) )

sudo -u pi sh "cd /home/pi/link/habridge ; java -jar Dserver.port:9090 ha-bridge-2.0.5jar" 2>&1 &

i guess it is time for me upgrade to jessie and figure out sysctrl :-)

[edited again!]
Try this and no need to run as sudo on the pi and make sure that ha-bridge-2.0.5.jar is in your /home/pi/link/habridge directory.

pi@raspberrypi:~ $ nano starthabridge.sh

Then cut and past this, modify any locations that are not correct

cd /home/pi/link/habridge
rm log.txt
nohup java -jar -Dserver.port=9090 /home/pi/link/habridge/ha-bridge-2.0.5.jar > log.txt 2>&1 &
chmod 777 log.txt

Then execute on the command line:

pi@raspberrypi:~ $ chmod u+x starthabridge.sh

Then execute the script:

pi@raspberrypi:~ $ ./starthabridge.sh

@bwssytems thanks i can try that too. To be clear the line below worked for me and is simpler for me to maintain so you can close issue. though i can't be the only linux noob so documenting your way might be a good idea?

sudo -u pi sh "cd /home/pi/link/habridge ; java -jar Dserver.port:9090 ha-bridge-2.0.5jar" 2>&1 &

I'll add it to the readme as that will help.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

scottdalton picture scottdalton  路  5Comments

AdrianKielbowicz picture AdrianKielbowicz  路  3Comments

Lorccan picture Lorccan  路  4Comments

tylerstraub picture tylerstraub  路  10Comments

sanderlv picture sanderlv  路  15Comments