question

EusebiuMarcu avatar image
0 Votes"
EusebiuMarcu asked ·

Start service on newly created VM from captured image

Hello,

I've created a VM (Windows) and I've registered a Windows Service (dotnet core 3.1) and marked it as Automatic.

After I capture that VM (because I want to create new VMs from that image, e.g. using Azure API) and create a new VM instance, the service I registered is stopped when the VM is booted.

How can I make that service start with the VM?

Thanks!

azure-virtual-machines
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

EusebiuMarcu avatar image
0 Votes"
EusebiuMarcu answered ·

So, I moved from Image creation to Disk snapshot and create a VM from a copied disk from snapshot.
I've also increased the time for service start timeout (I had a 1 vCPU and 2GB of RAM)
https://www.codetwo.com/kb/how-to-extend-the-timeout-for-services-if-they-do-fail-to-start/#:~:text=Run%20Windows%20Services%20manager%20(launch,)%2C%20as%20shown%20in%20Fig.

Other option: Automatic (Delay start).

·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

TravisCragg-MSFT avatar image
0 Votes"
TravisCragg-MSFT answered ·

This should work, did you make sure the original image kept the service after a reboot? Sometimes dependencies or other factors can prevent the service from starting.

You can also use a custom script extension (easy) or Desired State Configuration (complicated) to configure the service to start on creation.


· 1 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Yes, the service is kept; it's just not started even if it is running and marked as Automatic before image creation.

I tried custom script extension but after the image is created based on that VM, it is still not started.

Set-AzVMCustomScriptExtension -ResourceGroupName VSES -VMName LetsVR10 -FileUri https://raw.githubusercontent.com/eusebiu/LetsVR.Public/master/start-service.ps1 -Run 'start-service.ps1' -Name StartServiceCSE -Location "West Europe"

I think it is because it is not kept after the generalization of the VM and image creation.

So, I would need a way to keep it after the generalization and image creation.

0 Votes 0 ·