powershell 来自http://www.abhinavrastogi.com/powershell_for_remote_tomcat_deployment.html

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell 来自http://www.abhinavrastogi.com/powershell_for_remote_tomcat_deployment.html相关的知识,希望对你有一定的参考价值。

# Params:
# $tomcatUrl: Url of tomcat
# $warPath: Url of war file containing application
# $appVirtualPath: Virtual path of application to be deployed
# $user: User with permissions to deploy i.e. a user in tomcat-users.xml with manager-script role
# $password: Password for specified user
Function DeployToTomcat($tomcatUrl, $warPath, $appVirtualPath, $user, $password)
{
        # Webclient for making requests
        $webclient = new-object System.Net.WebClient

        # Object for keeping authorization credentials
        $credCache = new-object System.Net.CredentialCache

        # Tomcat uses basic auth by default
        $creds = new-object System.Net.NetworkCredential($user, $password)
        $credCache.Add($tomcatUrl + "manager/text/list", "Basic", $creds)
        $webclient.Credentials = $credCache

        # 1. Stop application
        $webpage = $webclient.DownloadString($tomcatUrl  + "manager/text/stop?path=/" + $appVirtualPath)
        write-output $webpage

        # 2. Undeploy application
        $webpage = $webclient.DownloadString($tomcatUrl + "manager/text/undeploy?path=/" + $appVirtualPath)
        write-output $webpage

        # 2A. Wait for application to be undeployed
        [System.Threading.Thread]::Sleep(10000)

        #3. Upload new application
        $uploadUrl = ($tomcatUrl  + "manager/text/deploy?path=/"  + $appVirtualPath)
        $bytes =  [System.IO.File]::ReadAllBytes($warPath)
        $uploadresults = $webclient.UploadData($uploadUrl, "PUT", $bytes)
        #write-output $uploadresults

        #3A. Wait for new application to be pushed to tomcat server and unzipped
        [System.Threading.Thread]::Sleep(10000)

        #4. Start new application
        $webpage = $webclient.DownloadString($tomcatUrl  + "manager/text/start?path=/" + $appVirtualPath)
        write-output $webpage

        #5. Get a list of running applications
        $webpage = $webclient.DownloadString($tomcatUrl  + "manager/text/list")
        write-output $webpage

        #6. Print url for application
        write-output ("Application running here: " + $tomcatUrl + $appVirtualPath)
}

以上是关于powershell 来自http://www.abhinavrastogi.com/powershell_for_remote_tomcat_deployment.html的主要内容,如果未能解决你的问题,请参考以下文章

powershell 添加和删​​除Windows存储来自Powershell / CMD的应用程序

powershell 从文件加载Powershell函数。来自http://stackoverflow.com/a/6016630/1678525

powershell 从文件加载Powershell函数。来自http://stackoverflow.com/a/6016630/1678525

powershell 来自https://stackoverflow.com/questions/1663748/powershell-analog-to-quote-words

使用来自 Textfile 的文件创建 7-Zip 存档 - Powershell

管道文件到 uglifyjs - 来自 Powershell