今天给各位分享nohupjava虚拟内存的知识,其中也会对进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
1、linux nohup 启动java工程问题2、jenkins上使用shell脚本nohup部署jar服务到remote服务器3、使用xshell的nohup&命令在服务器上运行Java程序
linux nohup 启动java工程问题
1) 在ECLIPSE下面EXPORT成为RUNNABLE JAR FILE。
2)拷贝1)中生成的JAR包,到LINUX中去。
3)随便搞个什么名字的.SH文件,里面输入java -jar XXX.jar
jenkins上使用shell脚本nohup部署jar服务到remote服务器
先贴一下,我的jenkins里最后核心配置
remove_jar.sh脚本:
start_jar.sh脚本内容:
remove_jar.sh 和 start_jar.sh 在jenkins服务器上,需要将这两个shell在0.0.0.0(不能暴露)的远端去执行
没错,客官您一眼就看出来了,觉得简单的不值一提吧,先别着急,对搜这个问题的小菜鸡来说这里面也是大有文章,听我一一道来。
1、第一个问题:ps -ef|grep xxx.jar查到多余的pid
现象:在0.0.0.0上行 ps -ef | grep alk-wxapi-test.jar | grep -v grep | awk ‘{print $2}’ 只能查到一个pid,但是把这句话放到shell脚本里,在本地使用命令上远端执行,就会找到3个pid,而且kill 时提示失败的错误。
现在已经知道原因了,但是当时确实是个问题。
已经解决不方便复现了,因此就描述一下就行了。
原因:shell里的这个命令也是通过bash在远程执行的,所以找到的别的 无关紧要 的pid其实是bash,因此在grep是除了排除grep本身( grep -v grep )外还要排除bash( grep -v bash )
最后命令是:
2、远程执行脚本,里面有nohup java -jar,发生错误: nohup: failed to run command ‘java’: No such file or directory
这是因为nohup时java环境变量没有读到,处理方式就是在nohup执行前加入
3、其他思路
4、第二条说jdk的路径因为每个服务企业都不一样,所以需要手动传改,这一点已经在脚本上做了修改,启动脚本上携带的第一个参数就是jdk的安装路径
这两个也都是比较好的思路,以后肯定有机会体验的,本篇到此。
ps -ef |grep -v 在shell sh 脚本中貌似无效?
linux下搭建zookeeper集群遇到的坑
nohup: cannot run command异常解决
Zookeeper not starting, nohup error
使用xshell的nohup&命令在服务器上运行Java程序
您好,在网上有挺多版本,C JAVA的都有,我找了一个还可以,有源码,大概试了试效果还不错。需要下载一个ganymed-ssh2-build210 代码部分大概是这样的。
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import ch.ethz.ssh2.ChannelCondition;
import ch.ethz.ssh2.Connection;
import ch.ethz.ssh2.Session;
import ch.ethz.ssh2.StreamGobbler;
public class RmtShellExecutor {
private Connection conn;
private String ip;
private String usr;
private String psword;
private String charset = Charset.defaultCharset().toString();
private static final int TIME_OUT = 1000 * 5 * 60;
public RmtShellExecutor(ShellParam param) {
this.ip = param.getIp();
this.usr = param.getUsername();
this.psword = param.getPassword();
}
class ShellParam{
String ip;
String usr;
String psword;
String getIp(){
return ip;
};
String getUsername(){
return usr;
}
String getPassword(){
return psword;
}
}
public RmtShellExecutor(String ip, String usr, String ps) {
this.ip = ip;
this.usr = usr;
this.psword =ps;
}
private boolean login() throws IOException {
conn = new Connection(ip);
conn.connect();
return conn.authenticateWithPassword(usr, psword);
}
public int exec(String cmds) throws Exception {
InputStream stdOut = null;
InputStream stdErr = null;
String outStr = “”;
String outErr = “”;
int ret = -1;
try {
if (login()) {
// Open a new {@link Session} on this connection
Session session = conn.openSession();
// Execute a command on the remote machine.
session.execCommand(cmds);
stdOut = new StreamGobbler(session.getStdout());
outStr = processStream(stdOut, charset);
stdErr = new StreamGobbler(session.getStderr());
outErr = processStream(stdErr, charset);
session.waitForCondition(ChannelCondition.EXIT_STATUS, TIME_OUT);
System.out.println(“” + outStr);
ret = session.getExitStatus();
} else {
System.out.println(“登录远程机器失败”+ ip);
}
} finally {
if (conn != null) {
conn.close();
}
}
return ret;
}
private String processStream(InputStream in, String charset) throws Exception {
byte[] buf = new byte[1024];
StringBuilder sb = new StringBuilder();
while (in.read(buf) != -1) {
sb.append(new String(buf, charset));
}
return sb.toString();
}
public static void main(String args[]) throws Exception {
RmtShellExecutor exe = new RmtShellExecutor(“”, “”, “”);
System.out.println(exe.exec(“ls”));
}
}
nohupjava虚拟内存的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于、nohupjava虚拟内存的信息别忘了在本站进行查找喔。