1

I am building a windows server image using Packer tool and Powershell DSC. In my DSC script I am installing and starting the tomcat service as below,

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.

Is there any way I could set the Startup type to Automatic for tomcat service using Powershell?

1 Answers1

1

I believe you can leverage DSC service resource and try to set startup type and start the service.

halfer
  • 19,824
  • 17
  • 99
  • 186
KrishnaG
  • 3,340
  • 2
  • 6
  • 16
  • Hi there. Please don't add greetings or the names of question authors in your answer posts. While it is necessary to answer the question posed, the point of giving an answer is to help a large number of future people with the same problem - so you are addressing a wide audience. Thanks! – halfer Oct 16 '21 at 12:51