简体   繁体   中英

Run Azure Storage Emulator as service

We use Azure Storage Emulator on the development machines and the CI server to be able to use storage queues locally. Now every time I sign out of Windows or reboot, I need to start the storage emulator manually.

Is there a way to start the Azure storage emulator as service, so that it automatically starts when Windows does?

Updated answer after trying out options from Gaurav Mantris answer

Running the batch file as described by Gaurav Mantri keeps the command window open. Here is a way to avoid that:

  • Open Task Scheduler
  • Create a new task
  • Add the "At log on" trigger
  • Add a "Start a program" action with the following settings:
    • Program/Script: AzureStorageEmulator.exe
    • Add arguments: start
    • Start in: C:\\Program Files (x86)\\Microsoft SDKs\\Azure\\Storage Emulator (or wherever the storage emulator resides on your disk)

Storage Emulator files can be found in C:\\Program Files (x86)\\Microsoft SDKs\\Azure\\Storage Emulator . I noticed a batch file in there called StartStorageEmulator.cmd .

What you could is create a shortcut of this file in your Startup folder (eg C:\\Users\\<your user name>\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup ). Then when you login back again, the storage emulator will start automatically. [Please see instructions here: http://www.tech-recipes.com/rx/28206/windows-8-how-to-add-applications-startup-folder/] .

Other alternative is to create a new task that runs this batch file and schedule that task to run when computer starts. Please see this thread for more details: Run Batch File On Start-up .

One option to run any non-service process, such as a console application, as a service is to use the Non-Sucking Service Manager as the host. (Historically you might have used SRVANY.EXE from the Windows NT Resource Kit.)

Using NSSM it's as simple as:

> choco install nssm -y
> nssm install AzureStorageEmulator "C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe" start -inprocess

On our AX "OneBox" dev environments, there was already a scheduled task DynamicsStartAzureStorageEmulator that launches the emulator as NT AUTHORITY\\SYSTEM on startup. Azure Storage Emulator was upgraded (Automatically? By the devs?), and then it stopped working.

The issue was twofold:

  1. It was trying to use the LocalDB(SQL Express Subset) instance

  2. It needed to initialize a new DB, as SYSTEM.

(Example, before it was AzureStorageEmulatorDB49 , now it's AzureStorageEmulatorDB510 )

Once I ran a shell/cmd as SYSTEM (using PSEXEC, and tried to run the emulator to see the error output, the rest was pretty straightforward.

The solution was pretty much just: Run shell as system (Using Psexec)

PsExec.exe -i -s cmd

And as SYSTEM, init the new database (in our case, using "Real" SQL, rather than LocalDB/Express.):

AzureStorageEmulator.exe init -server localhost

(If you want to stick w/ LocalDB, AzureStorageEmulator.exe init should work just fine)

As it was multiple VMs, I used powershell remoting:

$ListOfHostnames | foreach {.\PsExec.exe \\$_ -i -s "C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe" init -server localhost}

(Yes, if you have PwSH 7, you can use -parallel ;)

After that, it was a simple reboot to verify it all came up automatically.

Additional items: I set the scheduled task to also just start once a day at like 5 am, just in case it wasn't running for some reason.

Some envs had an emulator DB on the LocalDB instance, which I deleted. Not strictly necessary, just cleaner.

References:

https://docs.microsoft.com/en-us/azure/storage/common/storage-use-emulator#initialize-the-storage-emulator-to-use-a-different-sql-database and https://docs.microsoft.com/en-us/azure/storage/common/storage-use-emulator#command-line-syntax

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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