Automatically Restart Ambience Service and Terminate Java Processes Using a Batch Script

In some cases, multiple Java processes may remain active even after attempting to stop the Ambience 4.x service manually. To avoid repeatedly manually killing processes in Task Manager, you can use a custom Windows batch script to automate the stop–restart cycle of the Ambience service. This ensures all processes are terminated cleanly before restarting.

Steps

  1. Example to create a new batch file in Windows
    Open Notepad and paste the following script:
:: 1. Set date and path for stop-restart logging
SET dt_fmt=%DATE:/=%
SET logpath="C:\ElixirAmbience\log\amb_restart-%dt_fmt%_%time:~0,2%%time:~3,2%%time:~6,2%.log"

:: 2. Log current Ambience Windows Service and Java processes
tasklist /v /fi "Imagename eq Java.exe" >%logpath%
tasklist /v /fi "Imagename eq elx-ambience-service.exe" >>%logpath%

:: 3. Stop Ambience Windows Service and wait 90 seconds
net stop "ElixirAmbience" >>%logpath%
echo Waiting Start Time: %time% >>%logpath%
echo 90sec interval >>%logpath%
TIMEOUT /T 90 /NOBREAK
echo Waiting End Time: %time% >>%logpath%

:: 4. Force kill remaining processes, remove lock file, and wait 90 seconds
taskkill /F /IM elx-ambience-service.exe /T >>%logpath%
taskkill /F /IM Java.exe /T >>%logpath%
del "C:\ElixirAmbience\data\running.lock" >>%logpath%
echo Waiting Start Time: %time% >>%logpath%
echo 90sec interval >>%logpath%
TIMEOUT /T 90 /NOBREAK
echo Waiting End Time: %time% >>%logpath%

:: 5. Restart Ambience service
net start "ElixirAmbience" >>%logpath%
echo Ending Date/Time: %DATE%,%time% >>%logpath%

:: 6. Log status after restart
tasklist /v /fi "Imagename eq Java.exe" >>%logpath%
tasklist /v /fi "Imagename eq elx-ambience-service.exe" >>%logpath%
  1. Save the file
    Save the script with a .bat extension, for example:
restart-ambience.bat
  1. Run the script as Administrator
    Right-click the batch file and select Run as administrator.
    This will:
  • Stop the Ambience Windows service.
  • Wait 90 seconds to allow Java processes to exit gracefully.
  • Force kill any remaining Java processes.
  • Remove the running.lock file.
  • Restart the Ambience service.
  • Log all actions to the log directory.
  1. Review the logs
    After execution, check the log file under:
C:\ElixirAmbience\log\

The log will include:

  • Ambience service status.
  • Java processes and their memory usage.
  • Timestamps for each action.

Notes

  • You can adjust the timeout values (90 seconds) depending on how long your system takes to release Java processes.
  • Update the paths (C:\ElixirAmbience) if your installation is in a different directory.
  • This script should be run only when Ambience needs to be restarted or when lingering Java processes are observed.
  • Use the above script as reference in adapting to Linux systems.