简体   繁体   English

如何使用 Powershell DSC 为 Windows 服务设置自动启动配置

[英]How to setup automatic startup configuration for a windows service using Powershell DSC

I am building a windows server image using Packer tool and Powershell DSC .我正在使用Packer工具和Powershell DSC构建 Windows 服务器映像。 In my DSC script I am installing and starting the tomcat service as below,在我的 DSC 脚本中,我正在安装和启动 tomcat 服务,如下所示,

Script Tomcat_Service_Install
        {
            TestScript = { $false }
            GetScript = { $null }
            SetScript = { Start-Process "C:\Program Files\apache-tomcat-X.X.XX\bin\service.bat" -ArgumentList "install" -WorkingDirectory "C:\Program Files\apache-tomcat-X.X.XX\bin" -Wait}
        }
Script Tomcat_Service_Start
        {
            TestScript = { $false }
            GetScript = { $null }
            SetScript = { Start-Process "C:\Program Files\apache-tomcat-X.X.XX\bin\tomcatX.exe" -ArgumentList "start" -WorkingDirectory "C:\Program Files\apache-tomcat-X.X.XX\bin" -Wait}
            DependsOn = "[Script]Tomcat_Service_Install"
        }

After the build completes, I logged into the system to check all the configurations.构建完成后,我登录系统检查所有配置。 I found out that the tomcat service was installed on the system as a windows services but it was not running and the startup type was set to Manual.我发现tomcat服务作为windows服务安装在系统上,但没有运行,启动类型设置为手动。

Is there any way I could set the Startup type to Automatic for tomcat service using Powershell?有什么办法可以使用Powershell将tomcat服务的启动类型设置为自动吗?

我相信您可以利用DSC 服务资源并尝试设置启动类型并启动服务。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM