start-stop-daemon and java program
Asked Answered
G

2

8

I'm having a heck of a time getting a java program to launch properly in an init script using start-stop-daemon. I've written the init script and it seems to run but there's never a process afterward representing the running program.

Here's a snippet of my init script

#! /bin/sh
#
#

DAEMON="/usr/bin/java"
DAEMON_ARGS="-server -cp <bunch of RMI arguments and classpath stuff> -jar <absolute path>/myprog.jar"

PIDFILE="/var/run/myprog.pid"

case "$1" in
start)
    echo -n "Starting myprog"
    start-stop-daemon --start --pidfile "$PIDFILE" --chuid "myuser" --verbose --background --make-pidfile --startas "$DAEMON" -- $DAEMON_ARGS
    echo "."
;;

When I try to launch it via /etc/init.d I get the following:

/etc/init.d# /etc/init.d/myscript start

Starting myprogStarting /usr/bin/java...

Detatching to start /usr/bin/java...done.

.

Afterward, there is no java interpreter process running, executing myprog.jar

I've tried various combinations of --exec, --start with more or less the same results. If I could get some more visibility into what is going on, I'm sure I could figure this out but I'm not sure how to do even that.

Any suggestions?

(I'm running Angstrom on an embedded ARM platform so Java Service Wrapper isn't really an viable option, ie. I don't think its available for ARM)

I'm stuck so any advice would be really appreciated.

Thanks.

Guayule answered 26/3, 2012 at 1:42 Comment(1)
I should point out that my program currently does NOT implement the Daemon interface. Is this required?Guayule
D
14

Two things to try, first try removing --startas and use --exec instead like so:

start-stop-daemon --start --pidfile "$PIDFILE" --chuid "myuser" --verbose --background --make-pidfile --exec "$DAEMON" -- $DAEMON_ARGS

Second since you are using --background try specifying the --chdir option, if you don't the working directory ends up being /.

I ended up stumbling on your question trying to solve my issue which eventually was resolved by --chdir, I believe it will resolve yours as well.

Defray answered 21/5, 2012 at 7:30 Comment(1)
The most frustrating bit in this story is that start-stop-daemon swallows all program output if not told otherwiseFolse
C
-4

you're looking for a way to run and be able to monitor it?

have you tried ms batch dos programming it yet?

for example

@echo off
cd DirectoryOfFiles
echo "Starting up..."
java -Xmx512m mainFile
pause

mainFile = main.java? DirectoryOfFiles = the directory you have all the class files in, if running file is same directory just remove this line

hopefully this is what you're asking for

Carnival answered 26/3, 2012 at 1:47 Comment(1)
I'm just trying to get the thing to launch, period. I'm less interesting in monitoring it once I can confirm it's actually running. My platform is an embedded linux (Angstrom) so ms batch dos programming isn't an option. Thanks for the suggestion though.Guayule

© 2022 - 2024 — McMap. All rights reserved.