简体   繁体   中英

How start jboss service remotely with SSH?

I need to start the service of Jboss 7.1.1 remotely through SSH. But when execute the command does not happened.

The command: ssh user@server '/etc/init.d/jboss-as start' #(no error, no service started)

The script jboss-as:

#!/bin/sh
case "$1" in
    start)
        echo "Starting JBoss AS 7"
        su --command "/path/to/jboss-as-7.1.1.Final/bin/standalone.sh >& /dev/null &" root
    ;;
    stop)
        echo "Stopping JBoss AS 7"
        su --command "/path/to/jboss-as-7.1.1.Final/bin/jboss-cli.sh --connect command=:shutdown" root
    ;;
    *)
        echo "Usage: /etc/init.d/jboss-as {start|stop}"
        exit 1
    ;;
esac
exit 0

How to execute the command: ssh user@server 'service jboss-as start' or ssh user@server '/etc/init.d/jboss-as start' ?

  • The connection with ssh is OK
  • The Jboss Server is OK
  • If i execute the code: ssh user@server '/etc/init.d/mysql restart' it happens!

One of a few things are limiting your ability to run this service with the command as that is a valid method of starting the service.

user@server '/etc/init.d/jboss-as start'

All of which you can test remotely after initiating the SSH connection. SSH into the server and start the service with the same user you are going to connect with using the above command.

Firstly make sure the service is actually called 'jboos-as' with ls /etc/init.d/ |grep 'jboss'. The result will be exactly how you will call the command so replace jboss-as with the output from the grep.

Secondly it is a permissions issue on the init script. From what I could see online you have to create this script so if the permissions are not setup correctly it will not execute.

To check run ls -al /etc/init.d/ |grep 'jboss' and your output should appear as follows:

Output:

-rwxr-xr-x.  1 root root   2979 Sep 19 05:34 jboss*

The user issuing the start command will need to match the first user listed. In this case the first 'root' and/or be in the same group as the group listing which is the second 'root' in the example. This can vary if for instance your user is in the wheel group, but generally services are run as root or a specific user for that service.

Lastly The more important aspect is that the file is executable. This is listed as the x value in the ls -al output above. If no 'x's are listed you will need to make the file executable with the following:

chmod +x /etc/init.d/jboss

IMPORTANT all the above command will need you to referrence the file as it output in the first grep command, so /etc/init.d/jboss-as or /etc/init.d/jboss or /etc/init.d/jboss-something different.

I hope this helps you out and if it does not please post the results of the ls -al output and we can help you further.

Ok. Let`s go.

  1. Search the name of the jboss service:

    ls /etc/init.d/ |grep 'jboss' Returned "jboss-as". It is ok!

  2. Permissions:

    ls -al /etc/init.d/ |grep 'jboss' Returned exactly the same output: -rwxr-xr-x. 1 root root 2979 Sep 19 05:34 jboss-as -rwxr-xr-x. 1 root root 2979 Sep 19 05:34 jboss-as Its ok!

Still do not works. The principal objective to execute this command is an action of button in the Java program using SWT and the lib that implements SSH called JSCH. Look the code:

Session session = jsch.getSession("user", "SERVER_IP_ADDRESS", PORT);
session.setPassword("pass");
java.util.Properties config = new java.util.Properties(); 
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect();
Channel channel = session.openChannel("exec");
((ChannelExec)channel).setCommand("'/etc/init.d/jboss-as start'"); #command to start jboss service
channel.setInputStream(null);
((ChannelExec)channel).setErrStream(System.err);
InputStream in=channel.getInputStream();
channel.connect();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM