如何將 ActiveMQ Artemis 安裝為 Windows 服務?

如何將 ActiveMQ Artemis 安裝為 Windows 服務?

標題有點誤導,因為我知道如何將 artemis 安裝為 Windows 服務,根據文檔,只需運行

artemis-service.exe install

這對我不起作用。我嘗試使用 ActiveMQ Artemis 版本 2.31 和 2.29 安裝並執行該服務。對於這兩個版本,運行該服務都會產生以下登入訊息artemis-service.wrapper.log

2023-10-23 10:19:50,116 DEBUG - Starting WinSW in the service mode
2023-10-23 10:19:50,147 INFO  - Starting %JAVA_HOME%\bin\java.exe  -XX:+UseParallelGC -Xms512M -Xmx1024M -classpath "C:\Program Files (x86)\apache-artemis-2.31.0\lib\artemis-boot.jar" "-Dartemis.home=C:\Program Files (x86)\apache-artemis-2.31.0" -Dartemis.instance=C:\ArtemisBroker -Ddata.dir=C:\ArtemisBroker\data -Dartemis.instance.etc=C:\ArtemisBroker\etc -Djava.security.auth.login.config=C:\ArtemisBroker\etc\login.config -Dhawtio.disableProxy=true -Dhawtio.realm=activemq -Dhawtio.offline="true" -Dhawtio.role=amq -Dhawtio.rolePrincipalClasses=org.apache.activemq.artemis.spi.core.security.jaas.RolePrincipal -Djolokia.policyLocation=file:/C:/ArtemisBroker/etc/jolokia-access.xml org.apache.activemq.artemis.boot.Artemis run 
2023-10-23 10:19:50,178 DEBUG - Completed. Exit code is 0

並彈出以下警告:

在此輸入影像描述

提供某種提示的唯一來源是 Windows 事件日誌,其中包含以下條目:

在此輸入影像描述

Service cannot be started. System.ComponentModel.Win32Exception (0x80004005): The system cannot find the file specified
   at System.Diagnostics.Process.StartWithCreateProcess(ProcessStartInfo startInfo)
   at winsw.Util.ProcessHelper.StartProcessAndCallbackForExit(Process processToStart, String executable, String arguments, Dictionary`2 envVars, String workingDirectory, Nullable`1 priority, ProcessCompletionCallback callback, Boolean redirectStdin, LogHandler logHandler, Boolean hideWindow)
   at winsw.WrapperService.StartProcess(Process processToStart, String arguments, String executable, LogHandler logHandler, Boolean redirectStdin)
   at winsw.WrapperService.OnStart(String[] args)
   at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object state)

我檢查了執行命令中的所有路徑,但一切似乎都很好。

我唯一注意到的是條目

<startargument>-Djolokia.policyLocation=%ARTEMIS_INSTANCE_ETC_URI%/jolokia-access.xml</startargument>

<env name="ARTEMIS_INSTANCE_ETC_URI" value="file:/C:/ArtemisBroker/etc/"/>

,然後artemis-service.xml解決

-Djolokia.policyLocation=file:/C:/ArtemisBroker/etc//jolokia-access.xml org.apache.activemq.artemis.boot.Artemis

這似乎有點錯誤,但改變這一點(刪除一個/)不會改變任何東西。

如何解決這個問題?

答案1

感謝格雷格的評論,我可以解決這個問題。使用 Sysinternals 進程監視器,經過一些過濾後,我發現了以下條目:

在此輸入影像描述

這意味著,服務啟動甚至找不到用於啟動的 java 可執行檔。路徑顯示%JAVA_HOME%實際上找不到環境變數(且程式掃描插入子路徑字串中的 PATH)。

我對此感到驚訝,因為我很確定已經設定了該變數 - 我的錯誤是我將其設定為使用者變數而不是系統變數。顯然,Windows 在我登入的使用者下以其他使用者身分啟動服務,因此無法找到該變數。

設定%JAVA_HOME%為系統環境變數解決了這個問題。

相關內容