DEV Community

Cover image for Running Azurite emulator in the background on Windows startup
Krzysztof Koziarski
Krzysztof Koziarski

Posted on

Running Azurite emulator in the background on Windows startup

Azurite is an open-source emulator that enables you to test your applications using Azure Blob, Queue Storage, and Table Storage in a local environment without any cost.
Azurite replaces the Azure Storage Emulator and is regularly updated to ensure support for the latest versions of the Azure Storage APIs.

However, Azurite has one significant drawback compared to the outdated Azure Storage Emulator - it cannot be run in the background without keeping a console/terminal window open at all times.
The obsolete Azure Storage Emulator could be run in the background without opening a new window by running it from the command line:



"C:\Program Files (x86)\Microsoft SDKs\Azure\Storage Emulator\AzureStorageEmulator.exe" start


Enter fullscreen mode Exit fullscreen mode

You could create a start-azure-storage-emulator.cmd script and put the command inside that script, then copy/move it to the Windows Startup folder and voila - the emulator was running in the background and you could forget about it.
Unfortunately this is not possible for Azurite 😥

Options for starting the Azurite emulator

Option 1 - use Docker

One way is to use Docker and run Azurite inside docker:



docker run -d --restart always --name azurite -p 127.0.0.1:10000:10000 -p 127.0.0.1:10001:10001 -p 127.0.0.1:10002:10002 -v c:/dev/data/Azurite:/workspace mcr.microsoft.com/azure-storage/azurite azurite -l /workspace --blobHost 0.0.0.0 --blobPort 10000 --queueHost 0.0.0.0 --queuePort 10001 --tableHost 0.0.0.0 --tablePort 10002


Enter fullscreen mode Exit fullscreen mode

The important thing here is to bind the volume: -v c:/dev/data/Azurite:/workspace where the data is stored, so that it is not lost when the container or Docker is stopped.

But sometimes you can't or don't want to use Docker... What options do you have then?

Option 2 - Run Azurite manually

Run Azurite whenever you need it and keep the console window open all the time.



azurite -l "C:\dev\data\Azurite" --blobHost 0.0.0.0 --blobPort 10000 --queueHost 0.0.0.0 --queuePort 10001 --tableHost 0.0.0.0 --tablePort 10002


Enter fullscreen mode Exit fullscreen mode

azurite - run manually output log

Option 3 - Adding Azurite to the Windows startup

This is the option I want to focus on in this article.

Installation



npm install -g azurite


Enter fullscreen mode Exit fullscreen mode

Create batch script

Create a C:\dev\scripts\azurite-startup.cmd file, open it in notepad and paste the following content:



start /B /MIN azurite -l "C:\dev\data\Azurite" --blobHost 0.0.0.0 --blobPort 10000 --queueHost 0.0.0.0 --queuePort 10001 --tableHost 0.0.0.0 --tablePort 10002 > "C:\dev\data\Azurite\azurite.log" 2>&1


Enter fullscreen mode Exit fullscreen mode

The -l, --location option is important here - this is the location of the workspace, where Azurite will store all data.

> "C:\dev\data\Azurite\azurite.log" 2>&1 means you want to redirect standard output and errors to the specified file.

You don't need to specify the *Host and *Port parameters if you don't want to change the default hosts and ports.

Create VBScript

Create a C:\dev\scripts\azurite-win-autostart.vbs file, open it in notepad and paste the following content:



Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "C:\dev\scripts\azurite-startup.cmd" & Chr(34), 0
Set WshShell = Nothing


Enter fullscreen mode Exit fullscreen mode

Windows auto-startup

To run the VBScript file on startup, place it (or it's shortcut right click -> Create shortcut) in the Windows Startup folder. To do this, follow these steps:

  1. Press the Win + R to open the Run dialog box
  2. Type shell:startup and press Enter
  3. Copy the VBScript file you created earlier into the Startup folder.

Restart your computer and the batch script should start without a console window.

Find running Azurite process(es)

If Azurite is running in the background, you won't be able to find or stop the process easily.

You can find it using a PowerShell command:



Get-Process -name "cmd","node" -ErrorAction Ignore | Where-Object { $_.CommandLine -like '*azurite*' -and $_.CommandLine -like '*--blobPort*' }


Enter fullscreen mode Exit fullscreen mode

An even better way is to create functions and/or aliases.

Open the PowerShell $PROFILE file in Notepad: notepad $PROFILE and paste the following content at the end:



function get-azurite-processes { Get-Process -name "cmd","node" -ErrorAction Ignore | Where-Object { $_.CommandLine -like '*azurite*' -and $_.CommandLine -like '*--blobPort*' } }

Set-Alias -Name azp -Value get-azurite-processes -Description "Get Azurite background processess (node and cmd)"

function stop-azurite-processes { get-azurite-processes | Stop-Process }


Enter fullscreen mode Exit fullscreen mode

This will find the cmd and node processes responsible for running Azurite.

get-azurite-processes powershell function

To stop Azurite, you can run the function you created in the previous step:



stop-azurite-processes


Enter fullscreen mode Exit fullscreen mode

Top comments (0)