I am currently working on creating bash scripts to automate the process of doing a clean install and clean uninstall of Bamboo remote agents on a windows 7 VM.
These are my two scripts:
Clean install:
#!/bin/bash
#Main function
main(){
URL=https://bamboo.ihs.organization.net/agentServer/agentInstaller/atlassian-bamboo-agent-installer-5.5.0.jar
mkdir -p install-directory
#download jar
cwd=$(pwd)
echo "INFO - attempting to download jar file to:"
echo $cwd
echo "..."
echo ""
wget -nc --tries=10 $URL
cwd=$(pwd)
if [ $? -eq 1 ]
then
echo "ERROR - Failed to download jar file from $URL. It may have changed in the meantime."
exit 1
else
echo "INFO - Succeeded! Jar file downloaded to LOCATION"
fi
echo "INFO - Installing bamboo agent..."
#execute jar
echo "INFO - unpacking jar file..."
cwd=$(pwd)
win_cwd=$(cygpath -w ${cwd})
echo $win_cwd
java -Dbamboo.home=$win_cwd/install-directory/ -jar atlassian-bamboo-agent-installer-5.5.0.jar https://bamboo.ihs.organization.net/agentServer/
if [ $? -eq 1 ]
then
echo "ERROR - Failed to unpack jar file."
exit 1
else
echo -n "INFO - Succeeded! Jar file unpacked to "
echo $cwd/install-directory
fi
}
main
(basically downloads atlassian-bamboo-agent-installer-5.5.0.jar and installs it into a folder called "install-directory")
Clean uninstall:
#!/bin/bash
#Main function
main(){
cwd=$(pwd)
install_dir="$cwd""/install-directory"
win_install_dir=$(cygpath -w ${install_dir})
if [ -d $install_dir ]; then
echo -n "INFO - "
echo -n $install_dir
echo " detected. "
cd "$install_dir"
cd "bin"
STOP_SCRIPT="StopBambooAgent-NT.bat"
UNINSTALL_SCRIPT="UninstallBambooAgent-NT.bat"
cmd /c "$win_install_dir"/bin/"$STOP_SCRIPT"
cmd /c "$win_install_dir"/bin/"$UNINSTALL_SCRIPT"
if [ $? -eq 1 ]
then
echo -n "ERROR - '"
echo -n "$UNINSTALL_SCRIPT"
echo "' failed. See output above."
exit 1
fi
cd "../.."
echo -n "INFO - attempting to remove"
echo -n $install_dir
echo "... "
rm -rf $install_dir
if [ $? -eq 1 ]
then
echo -n "ERROR - removing '"
echo -n "$install_dir"
echo "' failed. See output above."
else
echo -n "INFO - removing '"
echo -n "$install_dir"
echo "' succeeded!"
fi
else
echo -n "ERROR - "
echo -n $install_dir
echo " is expected to exist."
exit 1
fi
}
main
(basically calls StopBambooAgent-NT.bat, then UninstallBambooAgent-NT.bat, the deletes the "install-directory" folder)
The sequence of steps I have been doing:
Run ./clean-install.sh. At this point the agent works, I can go to the server and see it, run jobs on it, etc.
There is a terminal window open with this as output:
**************************************************************** ******************************************************************************** ***********
INFO | jvm 1 | 2015/01/27 11:52:07 | 2015-01-27 03:52:07,573 INFO [Thread-1 ] [RemoteAgent] * *
INFO | jvm 1 | 2015/01/27 11:52:07 | 2015-01-27 03:52:07,573 INFO [Thread-1 ] [RemoteAgent] * Bamboo agent '10.0.2.15 (12)' ready to receive builds.
INFO | jvm 1 | 2015/01/27 11:52:07 | 2015-01-27 03:52:07,573 INFO [Thread-1 ] [RemoteAgent] * Remote Agent Home: C:\Users\vagrant\bamboo-agent-dev\install-d irectory
INFO | jvm 1 | 2015/01/27 11:52:07 | 2015-01-27 03:52:07,573 INFO [Thread-1 ] [RemoteAgent] * Broker URL: failover:(tcp://bamboo.ihs.organization.net:54663?wir eFormat.maxInactivityDuration=300000)?initialReconnectDelay=15000&maxReconnectAt tempts=10
INFO | jvm 1 | 2015/01/27 11:52:07 | 2015-01-27 03:52:07,573 INFO [Thread-1 ] [RemoteAgent] * *
INFO | jvm 1 | 2015/01/27 11:52:07 | 2015-01-27 03:52:07,573 INFO [Thread-1 ] [RemoteAgent] **************************************************************** ******************************************************************************** ***********
INFO | jvm 1 | 2015/01/27 11:52:07 | 2015-01-27 03:52:07,588 INFO [QuartzSc heduler_Worker-1] [AgentHeartBeatJob] executableBuildAgent still unavailable. He artbeat skipped.
I cntrl-C out of this, and the agent is still there on the server, and I can still configure it, run jobs on it, etc. (At least it seems like that is the case.)
I then stop all the build jobs on the agent and try to uninstall it, and here is where the problem is.
The problem:
Basically when I try to run the uninstall script I get this error message:
INFO - /cygdrive/c/Users/vagrant/bamboo-agent-dev/install-directory detected.
ERROR | wrapper | 2015/01/27 11:41:42 | The bamboo-remote-agent service is not installed - The specified service does not exist as an installed service. (0x424)
Press any key to continue . . .
This corresponds to StopBambooAgent.bat being run by the uninstall script.
Furthermore when I try to delete the "install-directory" folder I also get lots of the following error messages (one for each file):
rm: cannot remove ‘/cygdrive/c/Users/vagrant/bamboo-agent-dev/install-directory/bin’: Device or resource busy
indicating to me that I have not stopped the agent properly. These files seem to be held open by a java JVM instance.
Why is it telling me the agent is not installed when it is? Am I trying to stop the remote agent correctly? How can I stop the remote agent?
Thanks very much.
$?is the return code of the most recent command. So when youcwd=$(pwd)betweenwgetand theifcheck you lose the return value ofwget. You also don't need thatcwdassignment again since you just did it a few lines before that (and haven't changed directory since). You can also likely just use$PWDinstead of thepwdcommand. - Etan Reisnerinstallas an argument to the initialjavacommand and then using the service to start it later was a better installation plan. - Etan Reisner