Reputation: 3182
From my (Windows) desktop or the (Windows or Unix) Jenkins server (which I believe uses the same underlying JSch technology), I can't seem to call the startup.sh script in the Tomcat bin dir as I want to. Tomcat (7) lives on a Solaris 9 server. I have rather basic Unix knowledge.
It executes successfully (Tomcat starts fine) but never returns until the Tomcat process is killed. I imagine other similar scripts would have the same behavior.
Example ant task (the commands are the same as I would put in Jenkins "Execute shell script on remote host" build task)
<?xml version="1.0" encoding="UTF-8"?>
<project name="remote-tomcat-controls" basedir=".">
<property name="hostname">someserver</property>
<property name="username">someuser</property>
<property name="password">somepassword</property>
<property name="port">22</property>
<property name="tomcathome">~/tomcat</property>
<target name="start-tomcat">
<sshexec host="${hostname}" port="${port}" username="${username}"
password="${password}" trust="true"
command=". ~/.profile; cd ${tomcathome}/bin; ./startup.sh" />
</target>
</project>
This starts Tomcat successfully but the task never returns unless/until the Tomcat process is killed on the server:
start-tomcat:
[sshexec] Connecting to someserver:22
[sshexec] cmd : . ~/.profile; cd ~/tomcat/bin; ./startup.sh
There are 3 commands involved:
I have tried moving these commands into a new script on the server, and have the Ant task simply call that, same results.
I have tried prepending the command with nohup and ending with &, no luck either.
Results you get when running the startup.sh script during an interactive ssh session:
$ ./startup.sh
Using CATALINA_BASE: /home/ebiztest/tomcat-datasheets
Using CATALINA_HOME: /home/ebiztest/tomcat-datasheets
Using CATALINA_TMPDIR: /home/ebiztest/tomcat-datasheets/temp
Using JRE_HOME: /home/ebiztest/jdk1.6.0_34
Using CLASSPATH: /home/ebiztest/tomcat-datasheets/bin/bootstrap.jar:/home/ebiztest/tomcat-datasheets/bin/tomcat-juli.jar
$
Control is returned immediately.
Any ideas? Thanks!
In response to the answer from 'aa vv' Using commandResource instead of command let me point to a local file that contains the commands to run (added more commands for demonstration):
pwd
. ~/.profile;java -version
pwd
java -version
pwd
cd ~/tomcat-datasheets/bin;pwd
pwd
./startup.sh
Output:
start-tomcat:
[sshexec] Connecting to servername:22
[sshexec] cmd : pwd
[sshexec] /home/ebiztest
[sshexec] cmd : . ~/.profile;java -version
[sshexec] java version "1.6.0_34"
[sshexec]
[sshexec] Java(TM) SE Runtime Environment (build 1.6.0_34-b04)
[sshexec]
[sshexec] Java HotSpot(TM) Server VM (build 20.9-b04, mixed mode)
[sshexec]
[sshexec] cmd : pwd
[sshexec] /home/ebiztest
[sshexec] cmd : java -version
[sshexec] java version "1.4.2_04"
[sshexec]
[sshexec] Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_04-b05)
[sshexec] Java HotSpot(TM) Client VM (build 1.4.2_04-b05, mixed mode)
[sshexec]
[sshexec] cmd : pwd
[sshexec] /home/ebiztest
[sshexec] cmd : cd ~/tomcat-datasheets/bin;pwd
[sshexec] /home/ebiztest/tomcat-datasheets/bin
[sshexec] cmd : pwd
[sshexec] /home/ebiztest
[sshexec] cmd : ./startup.sh
[sshexec] ksh: ./startup.sh: not found
It seems commands on separate lines are run entirely separately from eachother, only semicolon separated commands on the same line execute sequentially.
Upvotes: 1
Views: 1859
Reputation: 10377
Try to chain the commands like that :
command=". ~/.profile && cd ${tomcathome}/bin && ./startup.sh"
Upvotes: 0
Reputation:
It looks like with 'command'
option, you have execute a command/set of commands ( 2 cases : either ; seperated commands is not supported for running single command line OR script call is not supported ).
<sshexec host="${hostname}" port="${port}" username="${username}"
password="${password}" trust="true"
commandResource="wrapper_script" outputproperty="wrapper.output.prop"/>
<echo message="${wrapper.output.prop}"/>
Instead of command
use commandResource
as specified in ant manual: http://ant.apache.org/manual/Tasks/sshexec.html to see if that helps.
wrapper_script
. ~/.profile
cd ${tomcathome}/bin
./startup.sh
Upvotes: 1