简体   繁体   English

如何使用SSH远程启动jboss服务?

[英]How start jboss service remotely with SSH?

I need to start the service of Jboss 7.1.1 remotely through SSH. 我需要通过SSH远程启动Jboss 7.1.1的服务。 But when execute the command does not happened. 但是执行命令时并没有发生。

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

The script jboss-as: 脚本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' ? 如何执行命令: ssh user@server 'service jboss-as start'ssh user@server '/etc/init.d/jboss-as start' ssh user@server 'service jboss-as start' ssh user@server '/etc/init.d/jboss-as start'吗?

  • The connection with ssh is OK 与ssh的连接可以
  • The Jboss Server is OK Jboss服务器正常
  • If i execute the code: ssh user@server '/etc/init.d/mysql restart' it happens! 如果我执行代码: ssh user@server '/etc/init.d/mysql restart'就会发生!

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连接后,您可以对所有这些进行远程测试。 SSH into the server and start the service with the same user you are going to connect with using the above command. SSH进入服务器,并使用上述命令以您要连接的同一用户身份启动服务。

Firstly make sure the service is actually called 'jboos-as' with ls /etc/init.d/ |grep 'jboss'. 首先,使用ls /etc/init.d/ | grep'jboss'确保该服务实际上被称为'jboos-as'。 The result will be exactly how you will call the command so replace jboss-as with the output from the grep. 结果将与调用命令的方式完全相同,因此用grep的输出替换jboss-as。

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: 要检查运行ls -al /etc/init.d/ |grep 'jboss' ,您的输出应如下所示:

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. 例如,如果您的用户在wheel组中,则可能会有所不同,但通常服务是作为root用户或该服务的特定用户运行的。

Lastly The more important aspect is that the file is executable. 最后,更重要的方面是该文件是可执行文件。 This is listed as the x value in the ls -al output above. 上面的ls -al输出中将其列为x值。 If no 'x's are listed you will need to make the file executable with the following: 如果未列出“ x”,则需要使用以下命令使文件可执行:

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. 重要上述所有命令将需要您参考第一个grep命令中输出的文件,因此/etc/init.d/jboss-as或/etc/init.d/jboss或/etc/init.d/jboss -有些不同。

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. 希望这对您有所帮助,如果没有帮助,请发布ls -al输出的结果,我们将为您提供进一步的帮助。

Ok. 好。 Let`s go. 走吧

  1. Search the name of the jboss service: 搜索jboss服务的名称:

    ls /etc/init.d/ |grep 'jboss' Returned "jboss-as". ls /etc/init.d/ |grep 'jboss'返回“ 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 ls -al /etc/init.d/ |grep 'jboss'返回完全相同的输出: -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! -rwxr-xr-x. 1 root root 2979 Sep 19 05:34 jboss-as没关系!

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. 执行此命令的主要目的是在Java程序中使用SWT和实现SSH的lib(称为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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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