Note that there are some explanatory texts on larger screens.

plurals
  1. POJava Jar run as Daemon cant issue exec()
    primarykey
    data
    text
    <p>I have a java socket server I wrote to allow me to keep a web clusters code base in sync. When I run the init.d script from a shell login like so</p> <pre><code>[root@web11 www]# /etc/init.d/servermngr start </code></pre> <p>Logout and all will work fine but if the server reboots or I run the init.d using services like so </p> <pre><code>[root@web11 www]# service servermngr start </code></pre> <p>Any of the exec() commands passed to the socket server will not get executed on the linux box. I am assuming it has to do with the JVM having no real shell. If I login and run </p> <pre><code>[root@web11 www]# /etc/init.d/servermngr start </code></pre> <p>...and logout all runs nice all CVS commands are executed. </p> <p>Another note when run as a service the socket server responds to status checks so it is running </p> <p>Here is the init.d script</p> <pre><code>#!/bin/sh # chkconfig: 2345 95 1 # description: Starts Daemon Using ServerManager.jar. # # Source function library. . /etc/init.d/functions start () { echo -n $"Starting ServerManager: " # start daemon cd /www/servermanager/ daemon java -jar ServerManager.jar &gt; /www/logs/ServerManager.log &amp; RETVAL=$? echo [ $RETVAL = 0 ] &amp;&amp; touch /var/lock/subsys/cups echo ""; return $RETVAL } stop () { # stop daemon echo -n $"Stopping $prog: " kill `ps uax | grep -i "java -jar ServerManager.ja[r]" | head -n 1 | awk '{print $2}'` RETVAL=$? echo ""; return $RETVAL } restart() { stop start } case $1 in start) start ;; stop) stop ;; *) echo $"Usage: servermngr {start|stop}" exit 3 esac exit $RETVAL </code></pre> <p>And the Java responsible for actually executing the code:</p> <pre><code>// Build cmd Array of Strings String[] cmd = {"/bin/sh", "-c", "cd /www;cvs up -d htdocs/;cvs up -d phpinclude/"}; final Process process; try { process = Runtime.getRuntime().exec(cmd); BufferedReader buf = new BufferedReader(new InputStreamReader( process.getInputStream())); // Since this is a CVS UP we return the Response to PHP if(input.matches(".*(cvs up).*")){ String line1; out.println("cvsupdate-start"); System.out.println("CVS Update" + input); while ((line1 = buf.readLine()) != null) { out.println(line1); System.out.println("CVS:" + line1); } out.println("cvsupdate-end"); } } catch (IOException ex) { System.out.println("IOException on Run cmd " + CommandFactory.class.getName() + " " + ex); Logger.getLogger(CommandFactory.class.getName()).log(Level.SEVERE, null, ex); } </code></pre> <p>Thx for any help</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload