简体   繁体   English

将 Azure 存储模拟器作为服务运行

[英]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.我们在开发机器和 CI 服务器上使用 Azure 存储模拟器,以便能够在本地使用存储队列。 Now every time I sign out of Windows or reboot, I need to start the storage emulator manually.现在每次我退出 Windows 或重新启动时,我都需要手动启动存储模拟器。

Is there a way to start the Azure storage emulator as service, so that it automatically starts when Windows does?有没有办法将 Azure 存储模拟器作为服务启动,以便在 Windows 启动时自动启动?

Updated answer after trying out options from Gaurav Mantris answer在尝试了 Gaurav Mantris 答案中的选项后更新了答案

Running the batch file as described by Gaurav Mantri keeps the command window open.按照 Gaurav Mantri 的描述运行批处理文件会保持命令窗口打开。 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程序/脚本: AzureStorageEmulator.exe
    • Add arguments: start添加参数: start
    • Start in: C:\\Program Files (x86)\\Microsoft SDKs\\Azure\\Storage Emulator (or wherever the storage emulator resides on your disk)开始于: C:\\Program Files (x86)\\Microsoft SDKs\\Azure\\Storage Emulator (或存储模拟器驻留在磁盘上的任何位置)

Storage Emulator files can be found in C:\\Program Files (x86)\\Microsoft SDKs\\Azure\\Storage Emulator .存储模拟器文件可以在C:\\Program Files (x86)\\Microsoft SDKs\\Azure\\Storage Emulator I noticed a batch file in there called StartStorageEmulator.cmd .我注意到那里有一个名为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 ).您可以在Startup文件夹中创建此文件的快捷方式(例如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/] . [请参阅此处的说明: 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.将任何非服务进程(例如控制台应用程序)作为服务运行的一种选择是使用Non-Sucking Service Manager作为主机。 (Historically you might have used SRVANY.EXE from the Windows NT Resource Kit.) (从历史上看,你可能已经使用SRVANY.EXE从Windows NT资源工具包)。

Using NSSM it's as simple as:使用 NSSM 就这么简单:

> 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.在我们的 AX“OneBox”开发环境中,已经有一个计划任务DynamicsStartAzureStorageEmulator ,它在启动时将模拟器作为 NT AUTHORITY\\SYSTEM 启动。 Azure Storage Emulator was upgraded (Automatically? By the devs?), and then it stopped working. Azure 存储模拟器已升级(自动?由开发人员?),然后停止工作。

The issue was twofold:问题是双重的:

  1. It was trying to use the LocalDB(SQL Express Subset) instance它试图使用 LocalDB(SQL Express Subset) 实例

  2. It needed to initialize a new DB, as SYSTEM.它需要初始化一个新的 DB,如 SYSTEM。

(Example, before it was AzureStorageEmulatorDB49 , now it's AzureStorageEmulatorDB510 ) (例如,之前是AzureStorageEmulatorDB49 ,现在是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.一旦我以 SYSTEM 身份运行 shell/cmd(使用 PSEXEC,并尝试运行模拟器以查看错误输出,其余的就非常简单了。

The solution was pretty much just: Run shell as system (Using Psexec)解决方案几乎只是:将 shell 作为系统运行(使用 Psexec)

PsExec.exe -i -s cmd

And as SYSTEM, init the new database (in our case, using "Real" SQL, rather than LocalDB/Express.):作为 SYSTEM,初始化新数据库(在我们的例子中,使用“真实”SQL,而不是 LocalDB/Express。):

AzureStorageEmulator.exe init -server localhost

(If you want to stick w/ LocalDB, AzureStorageEmulator.exe init should work just fine) (如果你想坚持使用 LocalDB, AzureStorageEmulator.exe init应该可以正常工作)

As it was multiple VMs, I used powershell remoting:由于它是多个虚拟机,我使用了 powershell 远程处理:

$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 ;) (是的,如果你有 PwSH 7,你可以使用 -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.附加项目:我将计划任务设置为每天早上 5 点左右开始一次,以防万一它由于某种原因没有运行。

Some envs had an emulator DB on the LocalDB instance, which I deleted.一些环境在 LocalDB 实例上有一个模拟器数据库,我删除了它。 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 https://docs.microsoft.com/en-us/azure/storage/common/storage-use-emulator#initialize-the-storage-emulator-to-use-a-different-sql-databasehttps:// docs.microsoft.com/en-us/azure/storage/common/storage-use-emulator#command-line-syntax

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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