1758561 Members
1756 Online
108872 Solutions
New Discussion юеВ

Java Daemons under HP-UX

 
SOLVED
Go to solution

Java Daemons under HP-UX

I'm trying to run a Java application (not applet) as a daemon. I added a configuration file under /etc/rc.config.d and an initialization file /sbin/init.d/mydaemon. I linked to this file in /sbin/rc3.d as S950mydaemon so that it should get executed right before the login screen gets started. This file when run standalone: S950mydaemon start works fine but nothing happens when this is run as part of booting up. The mydaemon script runs another script which contains the java call. I put checks in all the scripts to make sure everything is running and it *appears* to be. The only thing I can think of is that the java call itself is failing and I'm not seeing the output from it. I haven't had much luck in redirecting the stderr from this. Any ideas?

Thanks in advance,

Scott LaBounty
Netaphor Software, Inc.
5 REPLIES 5
Rick Beldin
HPE Pro

Re: Java Daemons under HP-UX

Does your Java code have a GUI interface using Swing or AWT? If so, you'll have to provide a display for it to use. You'll need to make sure that the Xserver is running and that you have access to screen, which if you are running CDE, you do not have access to.
CDE grabs the screen for exclusive access while the login manager is displaying for security purposes.
Necessary questions: Why? What? How? When?

Re: Java Daemons under HP-UX

Rick,

No, the daemon does not use in Swing or AWT components it is strictly command line only. However when I run it "normally" (i.e. from a command line) I get the following errors:

Xlib: connection to "hpb2000:0.0" refused by server^M
Xlib: Client is not authorized to connect to Server^M
/usr/bin/X11/xset: unable to open display "hpb2000:0.0"

The application continues to run fine so I wasn't too worried about it but I suppose that it could make a difference when run at boot time. Could this be the problem? Is there a way to tell java not to try to connect to X?

Thanks,

Scott LaBounty
Netaphor Software, Inc.
Rick Garland
Honored Contributor

Re: Java Daemons under HP-UX

Do xhosts + (or just xhosts from the system you wish to run the app. Set the DISPLAY variable.

It appears that the xhosts command needs to be run in order to allow a connection to the X-server.
Mike Stroyan
Honored Contributor
Solution

Re: Java Daemons under HP-UX

Your "daemon" is probably just dying because it recieves a SIGHUP signal when the /sbin/rc completes. To properly daemonize a process it needs to ignore SIGHUP. You can to that with java by just using the nohup command to start java-
nohup java MyClass
or
nohup java MyClass >/dev/null 2>/dev/null

Re: Java Daemons under HP-UX

Mike,

nohup was the right answer and everything now works great. Thanks.

Scott LaBounty
Netaphor Software, Inc.