为 windows 7 自动安装 Bamboo 远程代理 - 无法使用 StopBambooAgent-NT.bat 停止 运行 代理

Automating Bamboo Remote Agent Installation for windows 7 - Cannot stop the running agent with StopBambooAgent-NT.bat

我目前正在创建 bash 脚本来自动执行在 windows 7 VM 上执行全新安装和卸载 Bamboo 远程代理的过程。

这是我的两个脚本:

全新安装:

#!/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

(主要是下载 atlassian-bamboo-agent-installer-5.5。0.jar 并将其安装到名为 "install-directory" 的文件夹中)

完全卸载:

 #!/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

(基本上调用StopBambooAgent-NT.bat,然后UninstallBambooAgent-NT.bat,删除"install-directory"文件夹)

我一直在做的步骤顺序:

运行./clean-install.sh。此时代理工作,我可以去服务器看看它,运行 上面有工作,等等

有一个终端 window 打开,输出为:

****************************************************************                                                                                                    ********************************************************************************                                                                                                    ***********
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.

我 cntrl-C 退出了这个,代理还在服务器上,我仍然可以配置它,运行 上面的作业,等等。(至少看起来是这样的例。)

然后我停止代理上的所有构建作业并尝试卸载它,这就是问题所在。

问题:

基本上,当我尝试 运行 卸载脚本时,我收到此错误消息:

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 . . .

这对应于 StopBambooAgent.bat 被卸载脚本 运行。

此外,当我尝试删除 "install-directory" 文件夹时,我还会收到许多以下错误消息(每个文件一个):

rm: cannot remove ‘/cygdrive/c/Users/vagrant/bamboo-agent-dev/install-directory/bin’: Device or resource busy

向我表明我没有正确停止代理。这些文件似乎由 java JVM 实例保持打开状态。

为什么它告诉我没有安装代理?我是否试图正确停止远程代理?如何停止远程代理?

非常感谢。

通过@Etan Reisner

我并没有将 bamboo 代理安装为 windows 服务,尽管这是我的意图,这就是脚本无法运行的原因。为了解决这个问题,我在安装脚本的 java 命令中传入了 installntservice。

(参见:https://confluence.atlassian.com/display/BAMBOO056/Additional+remote+agent+options#Additionalremoteagentoptions-ntservice