Reputation: 18024
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?
Upvotes: 19
Views: 5650
Reputation: 842
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:
It was trying to use the LocalDB(SQL Express Subset) instance
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
Upvotes: 0
Reputation: 1080
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
Upvotes: 5
Reputation: 18024
Running the batch file as described by Gaurav Mantri keeps the command window open. Here is a way to avoid that:
AzureStorageEmulator.exe
start
C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator
(or wherever the storage emulator resides on your disk)Upvotes: 28
Reputation: 136146
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.
Upvotes: 5