我正在尝试使用Gradle ssh插件将我的Java构建部署到CentOS
remotes {
ftc {
role 'masterNode'
host = '173.199.123.42'
user = 'root'
password = 'myPass'
}
}
ssh.settings {
knownHosts = allowAnyHosts
}
task deploy {
doLast {
ssh.run {
session(remotes.ftc) {
execute 'pkill -f \'java.*chat\'', ignoreError: true
remove 'build/libs/chat.jar'
put from: file('build/libs/chat.jar'), into: '/root/test'
execute 'nohup java -jar /root/test/chat.jar &'
}
}
}
}
除非它永远不会完成,否则它会停留在execute nohup java -jar /root/test/chat.jar &
如何让它在后台运行?
答案 0 :(得分:1)
使用nohup
通常还涉及将IO重定向到某个文件,以便可以关闭连接中的文件描述符:
execute 'nohup java -jar /root/test/chat.jar & &> /tmp/log'