Hi Mikrotik Community.
im using the Community Script to update Containers from this post (http://forum.mikrotik.com/t/easy-container-update-script/172741/6) to update my Home Assistant instance.
This works really well, when executed on the Mikrotik (RB5009) itself.
In Home Assistant, I built an automation, which utilizes the Mikrotik API to trigger the script.
Unfortunately when trigged via API, the Script behaves differently:
Triggered via API:
13:26:47 script,info Container update: Container HomeAssistant update started
13:26:47 script,warning Container update: Container HomeAssistant is running, stopping container
13:26:58 system,info,account user h1ghrise logged out from 10.10.20.2 via api
Do scripts get executes differently, when triggered via API? I cannot reproduce this behavior.
No further entries. The Container is stopped, and nothing happens.
Triggered on the Mikrotik directly:
13:49:38 script,info Container update: Container HomeAssistant update started
13:49:38 script,warning Container update: Container HomeAssistant is running, stopping container
13:49:44 system,info,account user h1ghrise logged out from 10.10.20.2 via api
13:49:49 script,info Container update: Container HomeAssistant stopped
13:49:49 container,info,debug removing files, container f934a903-152d-4bdc-a04f-944b8e15a442
...
the corresponding code in the script:
:if ($contStatus != "stopped") do={
:if ($contStatus = "running") do={
:log warn "$($logPrefix)Container $contComment is running, stopping container"
:set contStarted true
stop $contId
}
:local stopTimeoutSec 120
:local sec 0
:while (([get $contId]->"status") != "stopped" && $sec <= $stopTimeoutSec) do={
:delay 1
:set sec ($sec + 1)
}
:if ($sec > $stopTimeoutSec) do={ $abortWithMessage ("container $contComment stop timed out, aborting") logPrefix=$logPrefix }
:log info "$($logPrefix)Container $contComment stopped"
}