starting openHAB as daemon

3,833 views
Skip to first unread message

Thomas Eichstädt-Engelen

unread,
May 26, 2012, 4:44:31 AM5/26/12
to ope...@googlegroups.com
Hi,

does anybody of you starts openHAB as Daemon using "start-stop-command"? I tried to follow

* http://www.ralfebert.de/blog/java/debian_daemon/
* https://wiki.jenkins-ci.org/display/JENKINS/Starting+and+Accessing+Jenkins

The problem is, that the created pid-file contains the wrong PID. This is mentioned in the tutorials as well. The proposed solution is to us "startas" instead of "exec" but doesn't work for me either.

Any suggestions?

Regards,

Thomas E.-E.

Lars Bretschneider

unread,
May 28, 2012, 10:48:17 AM5/28/12
to openhab
Hi Thomas,

i was little thinking about it an had a look in my system ....

so the pid is the pid of the shell wich is created in the runlevel
script, but (in my case) a new shell is opened with another pid, so
that why the pids are different, i´m not an expert how to get the pid
of the java process becouse the shell is still running in background i
think

Hauke

unread,
Jun 3, 2012, 9:41:48 AM6/3/12
to ope...@googlegroups.com

does anybody of you starts openHAB as Daemon using "start-stop-command"? I tried to follow


Hi Thomas,

did you solve your problem already? Could you provide your start-stop script as an example?
I'd also like to start it as a daemon but don't want to reinvent the wheel with such a script.

Cheers,
Hauke

Thomas Eichstädt-Engelen

unread,
Jun 3, 2012, 1:09:31 PM6/3/12
to ope...@googlegroups.com
Hi Hauke,

please find attached my current daemon-script. Please note, that stopping the daemon process does not work properly because the PID written to PID-file is not the PID of the Java-Process. It would be great if someone could help to make this running. I am going the script to Archlinux as well.

Regards,

Thomas E.-E.

openhab

Hauke

unread,
Jun 3, 2012, 3:32:01 PM6/3/12
to ope...@googlegroups.com
Hi Thomas,

sorry, but I do not see any attachment. I use the groups.google website. How do I seen and open the attachment?

Cheers,
Hauke

Mihail Panayotov

unread,
Jun 6, 2012, 4:52:24 AM6/6/12
to ope...@googlegroups.com
Hi Thomas, I don't find the attachment either. Could you repost it or upload it somewhere?

Lars Bretschneider

unread,
Jun 6, 2012, 5:16:56 AM6/6/12
to openhab
just send an pn to ope...@lb-automation.de you may get the files from
me also

Thomas Eichstädt-Engelen

unread,
Jun 13, 2012, 10:03:14 AM6/13/12
to ope...@googlegroups.com
Hi,
openhab

rick.c...@gmail.com

unread,
Aug 22, 2012, 7:49:00 AM8/22/12
to ope...@googlegroups.com, teic...@googlemail.com
I think one should write a simple start/stop script and publish this to the rc.d tree to commence on start-up.

Finding out the PID of the process started is relatively simple by doing a command:
ps | grep /usr/bin/java | sed -n 's|ttys.*||'
filtering for the first digit and storing the output into a temporary file. This PID can be used to kill the process.

However, I am struggling with how to avoid the console output to startup and, in case we interrupt or restart the process, reload the last persistent state of the elements or measured values.

I look for inspiration to the eibd script that I use for starting and stopping the eibd KNX/EIBD router server. This command however HAS a proper -daemon option. Not sure how to make that in Java.

Looking forward to more ideas.

Kind regards,
Rick


On Wednesday, June 13, 2012 4:03:14 PM UTC+2, Thomas Eichstädt-Engelen wrote:
Hi,

> Hi Thomas, I don't find the attachment either. Could you repost it or upload it somewhere?




second try :-)

Are there any updates already?

Regards,

Thomas E.-E.

Karel Goderis

unread,
Aug 22, 2012, 8:07:13 AM8/22/12
to ope...@googlegroups.com
on Mac OS X that can be done in an even more easy way:

create a .plist file in /Library/LaunchDaemons , something that resembles for example

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>GID</key>
<integer>0</integer>
<key>Label</key>
<string>org.opensc.pcscd.autostart</string>
<key>OnDemand</key>
<false/>
<key>ProgramArguments</key>
<array>
<string>/usr/sbin/pcscd</string>
<string>-f</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>UserName</key>
<string>root</string>
</dict>
</plist>

the program itself can be a script or whatever

K


--
You received this message because you are subscribed to the Google Groups "openhab" group.
To view this discussion on the web visit https://groups.google.com/d/msg/openhab/-/ONEjbecsv54J.
To post to this group, send email to ope...@googlegroups.com.
To unsubscribe from this group, send email to openhab+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/openhab?hl=en.

Kai Kreuzer

unread,
Aug 22, 2012, 1:57:40 PM8/22/12
to ope...@googlegroups.com
There is another thing that makes it difficult: The runtime should normally be stopped not by killing the process but by doing a "shutdown" on the OSGi console.
If I kill it, I always have the problem that I cannot reconnect to my KNX IP interface as it still things it has a connections and rejects me for a few minutes.

Regards,
Kai

Thomas Eichstädt-Engelen

unread,
Aug 22, 2012, 3:21:16 PM8/22/12
to ope...@googlegroups.com

If I kill it, I always have the problem that I cannot reconnect to my KNX IP interface as it still things it has a connections and rejects me for a few minutes.

even if it's a "normal" kill (not -9)?


erru

unread,
Aug 23, 2012, 9:55:49 AM8/23/12
to ope...@googlegroups.com
If the REST API would have a Command API extension, it would be possible to shutdown via e.g. wget http://localhost:8080/rest?command=shutdown
 So you wouldn´t need the pid.

Kai Kreuzer

unread,
Aug 24, 2012, 11:15:25 AM8/24/12
to ope...@googlegroups.com
If the REST API would have a Command API extension, it would be possible to shutdown via e.g. wget http://localhost:8080/rest?command=shutdown
 So you wouldn´t need the pid.

No way I would allow normal users to shut down my openHAB instance! And we do not have any fine grained rights management yet - only access or no access :-)

Karel Goderis

unread,
Aug 24, 2012, 11:19:10 AM8/24/12
to ope...@googlegroups.com
So we implement a Person repository after all? ;-)

Sent from my iPhone
--
You received this message because you are subscribed to the Google Groups "openhab" group.

HenrikS

unread,
Aug 24, 2012, 2:35:15 PM8/24/12
to ope...@googlegroups.com
If the REST API would have a Command API extension, it would be possible to shutdown via e.g. wget http://localhost:8080/rest?command=shutdown
 So you wouldn´t need the pid.

No way I would allow normal users to shut down my openHAB instance! And we do not have any fine grained rights management yet - only access or no access :-)


We could put a password parameter on the URL, or we could allow shutdown from localhost only. A normal user (such as wife, kids) should not have access to execute commands on your openhab production server.

I'm currently killing my openhab instance (Linux) using kill <pid>. Works fine but I see a lot of db4o transaction errors in the logs during shutdown.

Is there any other way to send the exit command to the osgi instance?

/Henrik

Kai Kreuzer

unread,
Aug 24, 2012, 5:23:47 PM8/24/12
to ope...@googlegroups.com
> I'm currently killing my openhab instance (Linux) using kill <pid>. Works fine but I see a lot of db4o transaction errors in the logs during shutdown.

You are right, I was wrong. A "kill <pid>" actually shuts down the OSGi framework gracefully. So no need for any other mechanism here (but still requiring to get the right pid).

Regards,
Kai

udo1...@googlemail.com

unread,
Sep 12, 2012, 9:28:53 AM9/12/12
to ope...@googlegroups.com, teic...@googlemail.com
Hi,

Quick and dirty: ;) I use screen to start the openhab-server. Then I can close the ssh-connection and reconnect to see the actual output, or to shutdown the server...
Nevertheless the best option would be a deamonized process.

Regards,

Udo Hartmann
Message has been deleted
Message has been deleted

Udo Hartmann

unread,
Sep 24, 2012, 3:10:34 AM9/24/12
to ope...@googlegroups.com

Hi Lars,

as I mentioned, I'm using screen. 'apt-get install screen' should work for rasperry pi with debian (I'm waiting for my rasperry...).
Starting screen gives you a 'new' console, which can be deconnected with shortcut 'ALT-a-d' and reconnected at any time (or from any - maybe new - console - only be shure to use the same login ;) ) with 'screen -r'. With screen running, you can close the ssh-connection without terminating the java-session.

Regards,
Udo

Am 23.09.2012 17:29 schrieb <lars....@gmail.com>:
Hi Udo,

when I log into my linux-server using ssh and start the openhab-server using the start.sh script, closing the ssh connection to the linux server also terminates the java process. I am surprised that this is working for you. Are you starting the script in the background with "start.sh &" ?

I have been unsuccessful to start OpenHab in the background so far. In particular I did not want to see the osgi console after starting OpenHab with the start.sh script. I tried to disconnect from the console using the "disconnect" command, but it did not bring back the linux shell. Using the options  -console 5555 -Dgosh.args=--nointeractive did not help either: After starting OpenHab I was unable to connect to it using telnet on port 5555 (no connection error).

What I really want is to log into my linux server remotely (RaspberryPi) using ssh, start OpenHab via the command line and then terminate the ssh connection. Later I want to be able to telnet to the osgi runntime directly to shut it down.  

Any hits?

Cheers Lars

On Wednesday, September 12, 2012 3:28:53 PM UTC+2, Udo Hartmann wrote:
Hi,

Quick and dirty: ;) I use screen to start the openhab-server. Then I can close the ssh-connection and reconnect to see the actual output, or to shutdown the server...
Nevertheless the best option would be a deamonized process.

Regards,

Udo Hartmann

--
You received this message because you are subscribed to the Google Groups "openhab" group.
To view this discussion on the web visit https://groups.google.com/d/msg/openhab/-/cdHKJYn4IesJ.

Lee Quit

unread,
Sep 24, 2012, 5:25:11 AM9/24/12
to ope...@googlegroups.com

I like 'screen'. For more comfort use byobu instead.
To disconnect your terminal from 'screen' press Ctrl-D A consecutively.

regards Knut

Lee Quit

unread,
Sep 24, 2012, 5:35:28 AM9/24/12
to ope...@googlegroups.com
lars....@gmail.com wrote:
> I have attached the start script and below is the start-stop-daemon
> command it generates. It starts java, creates a prcess id but then
> terminates. I have not been able to figure out what the issue is.
> Perhaps someone can share a working script?

I guess there is a problem with your library path. Your java packages
all have relative paths but do you know where start-stop-daemon starts
the process? I have some suggestions:

- Use absolute paths for the jar-files
- or: The --chdir option could help you to start java in the correct path.
- Why not use the start.sh with --exec. This will keep your start-script
up-to-date with openhab developments.

regards Knut

lars....@gmail.com

unread,
Sep 25, 2012, 2:51:00 AM9/25/12
to ope...@googlegroups.com

Awsome! Screen was exactly what I was looking for. Works perfect for me. Thanks everybody for the feedback!
Cheers Lars

daka

unread,
Sep 27, 2012, 3:39:23 PM9/27/12
to ope...@googlegroups.com, lars....@gmail.com
Hi,

I'm using start and stop scripts that start openHAB as a daemon. Standard out output is logged into a file. Telnet is available on the specified port.
This runs fine on debian (armv5) with Java HotSpot(TM) Embedded Client VM version 1.7.0_06. I'll try to attach the files.

Regards,
David


start_stop_openhab.zip

rick.c...@gmail.com

unread,
Sep 30, 2012, 7:12:50 AM9/30/12
to ope...@googlegroups.com
Where did you. Attach the files?

Rick

daka

unread,
Sep 30, 2012, 9:16:57 AM9/30/12
to ope...@googlegroups.com, rick.c...@gmail.com
Hi Rick,

I can see the attachments in my post. I didn't see them when I accessed the forum from my phone, though. Strange.

Here is the contents of the scripts.
start.sh
------------------------------
#!/bin/bash

# set path to eclipse folder. If local folder, use '.'; otherwise, use /path/to/eclipse/
#eclipsehome="server";
eclipsehome="."

# get path to equinox jar inside $eclipsehome folder
cp=$(find ${eclipsehome} -name "org.eclipse.equinox.launcher_*.jar" | sort | tail -1);

http_port=8080
https_port=8443
telnet_port=5555

echo Launching the openHAB runtime...
PROGRAM="java -Dosgi.clean=true -Declipse.ignoreApp=true -Dosgi.noShutdown=true -Djetty.port=${http_port} -Djetty.port.ssl=${https_port} -Djetty.home=. -Dlogback.configurationFile=configurations/logback.xml -Dfelix.fileinstall.dir=addons -Djava.library.path=lib -Djava.security.auth.login.config=./etc/login.conf -Dorg.quartz.properties=./etc/quartz.properties -Djava.awt.headless=true -jar $cp $* -console ${telnet_port}"
$PROGRAM > openhab.stdout &
PID=$!
echo "PID is: ${PID}"
echo $PID > openhab.pid

> The pid is returned by the "$!" command. I write the pid to a file openhab.pid. The stop.sh script uses the pid.

stop.sh
-------------------------------------
#!/bin/bash
PID=$(cat openhab.pid)
rm -f openhab.pid
echo "Stopping process $PID...."
kill $PID

> The pid from the openhab.pid file is used to kill the process. The openhab.pid file is removed.
> It is also possible to do a telnet into the OSGi console and do a shutdown.

Regards,
David


Op zondag 30 september 2012 13:12:50 UTC+2 schreef rick.c...@gmail.com het volgende:
Reply all
Reply to author
Forward
0 new messages