19

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?

theDmi
  • 17,546
  • 6
  • 71
  • 138

4 Answers4

28

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)
theDmi
  • 17,546
  • 6
  • 71
  • 138
  • 3
    This still requires you to login to the server, were you able to set it up like a standard Windows Service and not have to login? – Pappy Mar 14 '18 at 21:04
5

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 (e.g. 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.

Community
  • 1
  • 1
Gaurav Mantri
  • 128,066
  • 12
  • 206
  • 241
5

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
Chris Oldwood
  • 1,060
  • 10
  • 17
  • This surely worked under the emulator version at the time, but unfortunately it's not working today. The service starts and the process stays in memory, but the emulator reports a status of not running at the command line and returns a 500 server error to the browser. Shucks. I had high hopes for this one. – InteXX Jun 23 '20 at 11:12
  • I just read Orangutech's post below, and it seems to be a good solution. I'll try it later today and report the results back here. – InteXX Jun 23 '20 at 11:17
  • I wasn't able to get it working as a service (same problem, even after the db trick from Orangutech), so I did the next best thing: ran it as a scheduled task, every hour on the hour. Turns out it doesn't hurt anything to run `AzureStorageEmulator start -inprocess` while it's already listening—it just spits out an error message to the console, that's all. – InteXX Jun 24 '20 at 01:16
  • FYI I'm running the scheduled task under SYSTEM. Works great. – InteXX Jun 24 '20 at 01:18
0

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://learn.microsoft.com/en-us/azure/storage/common/storage-use-emulator#initialize-the-storage-emulator-to-use-a-different-sql-database and https://learn.microsoft.com/en-us/azure/storage/common/storage-use-emulator#command-line-syntax

Orangutech
  • 769
  • 1
  • 10
  • 17