Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6349299
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T21:35:19+00:00 2026-05-24T21:35:19+00:00

I have a java socket server I wrote to allow me to keep a

  • 0

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

[root@web11 www]# /etc/init.d/servermngr start

Logout and all will work fine but if the server reboots or I run the init.d using services like so

[root@web11 www]# service servermngr start

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

[root@web11 www]# /etc/init.d/servermngr start

…and logout all runs nice all CVS commands are executed.

Another note when run as a service the socket server responds to status checks so it is running

Here is the init.d script

#!/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 > /www/logs/ServerManager.log &
    RETVAL=$?
    echo
    [ $RETVAL = 0 ] && 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

And the Java responsible for actually executing the 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);
            }

Thx for any help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T21:35:20+00:00Added an answer on May 24, 2026 at 9:35 pm

    What is the command you are trying to run? cd is not a program and if you have ; you have multiple commands. You can only run one program!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hey all. I have a server written in java using the ServerSocket and Socket
I have java script code to set some of the properties of ajax controls.
Suppose I have some PHP code running inside a web server, for example, running
I have an in-house HTTP server written in Java; full source code at my
I have a Java server that will accept a connection from a python socket
Java Socket Server I have a Java process that is creating a listener on
I have a java server that has to communicate over a TCP socket to
I wrote code for tcp-server in java, and tested with tcp-client in java and
I have written a java socket server program which listens to a port continuously.
I have to write a multithreaded client and server using Java's socket api. Both

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.