Windows Service to Azure?

后端 未结 7 1849
面向向阳花
面向向阳花 2020-12-14 00:23

I\'ve written a Windows Service in C# that does a whole bunch of background admin tasks on the database. Now my customer wants to migrate the whole shebang to Azure. I kno

7条回答
  •  抹茶落季
    2020-12-14 00:55

    Here are the steps to install a windows service on Windows Azure running VM with Windows Server 2012 R2:

    • start your VM in Windows Azure Console and connect to it with Remote Desktop Connector
    • map your storage as a new drive in your VM:

      net use z: \mystorage.file.core.windows.net\endoint /u:myusername verylongkeythatendswith==

    Storage key can be found in your Azure Management Console -> Storages -> Manage Access Keys

    • copy all the necessary installation files to the mapped storage (copy&paste)
    • copy nssm to a local drive (not z: as it uses MAFS file system and that cannot be accessed with low-level windows API commands)
    • Create a .bat file with the following entries

    set username=xxx set password=yyy call d:\nssm install "My service" "%programfiles%\PathToService\myservice.exe" "-p 8677" d:\nssm set "My service" ObjectName "%username%" "%password%" sc failure "My service" actions= restart/60000/restart/60000/restart/60000 reset= 240 d:\nssm start "My service"

    Username and password should be the ones you used to create the VM.

    • run the script. The service should be visible in your services list.

    Enjoy!

    PS : I used NSSM to simplify the service deployment.

提交回复
热议问题