Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature Request]: possibility to call a restart from inside ioBroker (e.g. javascript-adapter) #413

Open
FernetMenta opened this issue Jan 3, 2024 · 6 comments
Labels
enhancement It's not a bug, but it's worth an enhancement. workaround available There is still a workaround available.

Comments

@FernetMenta
Copy link

Description / Beschreibung

I call "exec('/opt/scripts/maintenance.sh restart -y')" from a script but it seems that the command does not run to its end. Log shows:

l","noInstances":17,"compactMode":false,"noCompactInstances":0,"model":"ARMv7 Processor rev 10 (v7l)","cpus":4,"mem":2109505536,"ostype":"Linux","city":""}
================================== > LOG REDIRECT system.adapter.admin.0 => false [Process stopped]
================================== > LOG REDIRECT system.adapter.jarvis.0 => false [Process stopped]
================================== > LOG REDIRECT system.adapter.javascript.0 => false [Process stopped]
================================== > LOG REDIRECT system.adapter.javascript.1 => false [Process stopped]
================================== > LOG REDIRECT system.adapter.admin.0 => false [system.adapter.admin.0.logging]
================================== > LOG REDIRECT system.adapter.jarvis.0 => false [system.adapter.jarvis.0.logging]
================================== > LOG REDIRECT system.adapter.javascript.0 => false [system.adapter.javascript.0.logging]
================================== > LOG REDIRECT system.adapter.javascript.1 => false [system.adapter.javascript.1.logging]

When I exec to the container and execute the same command it does not work either. It works if I set the container to maintenance mode first.

root@iobroker:/opt/iobroker#
root@iobroker:/opt/iobroker#
root@iobroker:/opt/iobroker# iob maintenance restart -y
You are now going to call a restart of your container.
Restarting will work depending on the configured restart policy.
Stopping ioBroker...root@iobroker:/opt/iobroker#
root@iobroker:/opt/iobroker# iob maintenance on -y
You are now going to stop ioBroker and activate maintenance mode for this container.
Activating maintenance mode...
Stopping ioBroker...root@iobroker:/opt/iobroker#
root@iobroker:/opt/iobroker# iob maintenance restart -y
You are now going to call a restart of your container.
Restarting will work depending on the configured restart policy.
Container will be stopped or restarted in 5 seconds...

Looks like stop_iob exits somewhere and does not return.

Image version

v9.0.1

Docker logs / Docker Protokoll

--------------------------------------------------------------------------------
-------------------------     2024-01-03 10:00:48      -------------------------
--------------------------------------------------------------------------------
-----                                                                      -----
----- ██╗  ██████╗  ██████╗  ██████╗   ██████╗  ██╗  ██╗ ███████╗ ██████╗  -----
----- ██║ ██╔═══██╗ ██╔══██╗ ██╔══██╗ ██╔═══██╗ ██║ ██╔╝ ██╔════╝ ██╔══██╗ -----
----- ██║ ██║   ██║ ██████╔╝ ██████╔╝ ██║   ██║ █████╔╝  █████╗   ██████╔╝ -----
----- ██║ ██║   ██║ ██╔══██╗ ██╔══██╗ ██║   ██║ ██╔═██╗  ██╔══╝   ██╔══██╗ -----
----- ██║ ╚██████╔╝ ██████╔╝ ██║  ██║ ╚██████╔╝ ██║  ██╗ ███████╗ ██║  ██║ -----
----- ╚═╝  ╚═════╝  ╚═════╝  ╚═╝  ╚═╝  ╚═════╝  ╚═╝  ╚═╝ ╚══════╝ ╚═╝  ╚═╝ -----
-----                                                                      -----
-----              Welcome to your ioBroker Docker container!              -----
-----                    Startupscript is now running!                     -----
-----                          Please be patient!                          -----
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
-----                          System Information                          -----
-----                    arch:                armv7l                       -----
-----                    hostname:            iobroker                     -----
-----                                                                      -----
-----                          Version Information                         -----
-----                    image:               v9.0.1                       -----
-----                    build:               2023-12-01T18:43:20+00:00    -----
-----                    node:                v18.19.0                     -----
-----                    npm:                 10.2.3                       -----
-----                                                                      -----
-----                        Environment Variables                         -----
-----                    SETGID:              1001                         -----
-----                    SETUID:              1001                         -----
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
-----                   Step 1 of 5: Preparing container                   -----
--------------------------------------------------------------------------------

This is not the first run of this container. Skipping first run preparation.

--------------------------------------------------------------------------------
-----             Step 2 of 5: Detecting ioBroker installation             -----
--------------------------------------------------------------------------------

Existing installation of ioBroker detected in "/opt/iobroker".

--------------------------------------------------------------------------------
-----             Step 3 of 5: Checking ioBroker installation              -----
--------------------------------------------------------------------------------

(Re)setting permissions (This might take a while! Please be patient!)... Done.

Checking Database connection... Done.

Hostname in ioBroker matches the hostname of this container.
No action required.

--------------------------------------------------------------------------------
-----                Step 4 of 5: Applying special settings                -----
--------------------------------------------------------------------------------

Some adapters have special requirements/ settings which can be activated by the use of environment variables.
For more information see ioBroker Docker Image Docs (https://docs.buanet.de/iobroker-docker-image/docs/).


--------------------------------------------------------------------------------
-----                    Step 5 of 5: ioBroker startup                     -----
--------------------------------------------------------------------------------

Starting ioBroker...

##### #### ### ## # iobroker.js-controller log output # ## ### #### #####
host.iobroker check instance "system.adapter.admin.0" for host "iobroker"
host.iobroker check instance "system.adapter.javascript.0" for host "iobroker"
host.iobroker check instance "system.adapter.javascript.1" for host "iobroker"
host.iobroker check instance "system.adapter.history.0" for host "iobroker"
host.iobroker check instance "system.adapter.hm-rega.0" for host "iobroker"
host.iobroker check instance "system.adapter.hm-rpc.0" for host "iobroker"
host.iobroker check instance "system.adapter.hm-rpc.1" for host "iobroker"
host.iobroker check instance "system.adapter.tr-064.0" for host "iobroker"
host.iobroker check instance "system.adapter.zigbee2mqtt.0" for host "iobroker"
host.iobroker check instance "system.adapter.nut.0" for host "iobroker"
host.iobroker check instance "system.adapter.discovery.0" for host "iobroker"
host.iobroker check instance "system.adapter.backitup.0" for host "iobroker"
host.iobroker check instance "system.adapter.ems-esp.0" for host "iobroker"
host.iobroker check instance "system.adapter.jarvis.0" for host "iobroker"
host.iobroker check instance "system.adapter.kecontact.0" for host "iobroker"
host.iobroker check instance "system.adapter.signal-cmb.0" for host "iobroker"
host.iobroker check instance "system.adapter.web.0" for host "iobroker"
Send diag info: {"uuid":"244ca933-3ff0-4a47-8f3a-597aff132a36","language":"en","country":"Germany","hosts":[{"version":"5.0.17","platform":"Javascript/Node.js","type":"linux"}],"node":"v18.19.0","arch":"arm","docker":true,"adapters":{"admin":{"version":"6.12.0","platform":"Javascript/Node.js"},"discovery":{"version":"4.2.0","platform":"Javascript/Node.js"},"backitup":{"version":"2.9.8","platform":"Javascript/Node.js"},"ems-esp":{"version":"2.6.2","platform":"Javascript/Node.js"},"hm-rega":{"version":"4.0.0","platform":"Javascript/Node.js"},"hm-rpc":{"version":"1.15.19","platform":"Javascript/Node.js"},"jarvis":{"version":"3.1.8","platform":"Javascript/Node.js"},"javascript":{"version":"7.1.6","platform":"Javascript/Node.js"},"kecontact":{"version":"2.0.2","platform":"Javascript/Node.js"},"signal-cmb":{"version":"0.3.0","platform":"Javascript/Node.js"},"socketio":{"version":"6.5.5","platform":"Javascript/Node.js"},"tr-064":{"version":"4.2.18","platform":"Javascript/Node.js"},"vis-materialdesign":{"version":"0.5.79","platform":"Javascript/Node.js"},"web":{"version":"6.1.10","platform":"Javascript/Node.js"},"ws":{"version":"2.5.8","platform":"Javascript/Node.js"},"zigbee2mqtt":{"version":"2.13.4","platform":"Javascript/Node.js"},"nut":{"version":"1.6.0","platform":"Javascript/Node.js"},"history":{"version":"3.0.1","platform":"Javascript/Node.js"}},"statesType":"jsonl","objectsType":"jsonl","noInstances":17,"compactMode":false,"noCompactInstances":0,"model":"ARMv7 Processor rev 10 (v7l)","cpus":4,"mem":2109505536,"ostype":"Linux","city":""}
================================== > LOG REDIRECT system.adapter.jarvis.0 => true [system.adapter.jarvis.0.logging]
================================== > LOG REDIRECT system.adapter.admin.0 => true [system.adapter.admin.0.logging]
Send diag info: {"uuid":"244ca933-3ff0-4a47-8f3a-597aff132a36","language":"en","country":"Germany","hosts":[{"version":"5.0.17","platform":"Javascript/Node.js","type":"linux"}],"node":"v18.19.0","arch":"arm","docker":true,"adapters":{"admin":{"version":"6.12.0","platform":"Javascript/Node.js"},"discovery":{"version":"4.2.0","platform":"Javascript/Node.js"},"backitup":{"version":"2.9.8","platform":"Javascript/Node.js"},"ems-esp":{"version":"2.6.2","platform":"Javascript/Node.js"},"hm-rega":{"version":"4.0.0","platform":"Javascript/Node.js"},"hm-rpc":{"version":"1.15.19","platform":"Javascript/Node.js"},"jarvis":{"version":"3.1.8","platform":"Javascript/Node.js"},"javascript":{"version":"7.1.6","platform":"Javascript/Node.js"},"kecontact":{"version":"2.0.2","platform":"Javascript/Node.js"},"signal-cmb":{"version":"0.3.0","platform":"Javascript/Node.js"},"socketio":{"version":"6.5.5","platform":"Javascript/Node.js"},"tr-064":{"version":"4.2.18","platform":"Javascript/Node.js"},"vis-materialdesign":{"version":"0.5.79","platform":"Javascript/Node.js"},"web":{"version":"6.1.10","platform":"Javascript/Node.js"},"ws":{"version":"2.5.8","platform":"Javascript/Node.js"},"zigbee2mqtt":{"version":"2.13.4","platform":"Javascript/Node.js"},"nut":{"version":"1.6.0","platform":"Javascript/Node.js"},"history":{"version":"3.0.1","platform":"Javascript/Node.js"}},"statesType":"jsonl","objectsType":"jsonl","noInstances":17,"compactMode":false,"noCompactInstances":0,"model":"ARMv7 Processor rev 10 (v7l)","cpus":4,"mem":2109505536,"ostype":"Linux","city":""}
================================== > LOG REDIRECT system.adapter.admin.0 => false [Process stopped]
================================== > LOG REDIRECT system.adapter.jarvis.0 => false [Process stopped]
================================== > LOG REDIRECT system.adapter.javascript.0 => false [Process stopped]
================================== > LOG REDIRECT system.adapter.javascript.1 => false [Process stopped]
================================== > LOG REDIRECT system.adapter.admin.0 => false [system.adapter.admin.0.logging]
================================== > LOG REDIRECT system.adapter.jarvis.0 => false [system.adapter.jarvis.0.logging]
================================== > LOG REDIRECT system.adapter.javascript.0 => false [system.adapter.javascript.0.logging]
================================== > LOG REDIRECT system.adapter.javascript.1 => false [system.adapter.javascript.1.logging]
^C
rainer@cubox:~/progs/iobroker$ docker exec -it iobroker /bin/bash
root@iobroker:/opt/iobroker#
root@iobroker:/opt/iobroker#
root@iobroker:/opt/iobroker#
root@iobroker:/opt/iobroker# iob maintenance restart -y
You are now going to call a restart of your container.
Restarting will work depending on the configured restart policy.
Stopping ioBroker...root@iobroker:/opt/iobroker#
root@iobroker:/opt/iobroker# iob maintenance on -y
You are now going to stop ioBroker and activate maintenance mode for this container.
Activating maintenance mode...
Stopping ioBroker...root@iobroker:/opt/iobroker#
root@iobroker:/opt/iobroker# iob maintenance restart -y
You are now going to call a restart of your container.
Restarting will work depending on the configured restart policy.
Container will be stopped or restarted in 5 seconds...
@buanet
Copy link
Owner

buanet commented Jan 3, 2024

Hi, can you please confirm if the issue still exists with actual beta image?
I made some changes to the maintenance script since v9.0.1 was released. Might be possible that this no longer exists...

Regards,
André

@buanet buanet changed the title maintenence restart -y does not work [Problem]: maintenence restart -y does not work Jan 3, 2024
@buanet buanet added the bug This issue is confirmed. label Jan 3, 2024
@FernetMenta
Copy link
Author

Hi André,

I tried beta.3 and noticed no difference in regard to the mentioned behavoir. If I exec to the container and call "iob maint restart -y" from the cmd line, it works. But when I call this from within a javascript it fails. After the script has run from the javascript adapter there is no iobroker owned process left:

root@iobroker:/opt/iobroker# pgrep --list-full -u iobroker
647 tail -f /dev/null

Now calling "iob maint restart -y" from the command line fails too. The script terminates with this line: https://github.com/buanet/ioBroker.docker/blob/beta/debian12/scripts/maintenance.sh#L158
(no idea why)

Regards,
Rainer

@buanet
Copy link
Owner

buanet commented Jan 3, 2024

Hallo Rainer,

mir sind heute leider die englischen Worte ausgegangen, daher switche (ups, da war wohl doch noch eins) ich jetzt mal in meine Muttersprache. Ich denke das ist ok, oder?

Wenn ich dich recht verstehe, dann scheitert mit der Beta jetzt nur noch der Aufruf aus einem ioBroker JavaScript heraus, richtig?
Das würde sich zumindest mit dem decken, was ich heute nachgestellt habe. Denn bei mir funktioniert der Aufruf (über die Kommandozeile) in jedem Fall/ Szenario korrekt und zuverlässig.

Ich weiß, dass ich zu dem Thema "Aufruf des Maintenance Scripts aus ioBroker heraus" schon mal eine Diskussion geführt habe. Ich habe verzweifelt gesucht, es aber leider nicht wieder gefunden. :(
Das Resultat war damals aber, dass es so in der aktuellen Form nicht funktionieren kann und ich dazu das Maintenance Script um-/ bzw. neubauen müsste um dies zu ermöglichen. Leider komme ich nicht mehr drauf, warum genau das so war!
Es hatte irgendwas damit zu tun, dass sich der Script-Aufruf beim Beenden von ioBroker selbst beendet hat.

Wenn meine Vermutung von oben bezüglich deines Problems zutrifft, würde ich den issue gerne von bug auf enhancement ändern und du bekommst von mir vorerst ein "works as designed". :) Ich nehme das Thema aber natürlich gerne als Feature Request mit auf meine To-Do-Liste!

MfG,
André

@buanet
Copy link
Owner

buanet commented Jan 3, 2024

Ach gucke mal da! 🙈
Hier übrigens der Eintrag auf meiner To-Do-Liste... (habe ich gefunden als ich es eintragen wollte)

image

Die Diskussion gab es vor nem halben Jahr offenbar im Discord Channel. Hatte mir sogar die Begründung raus kopiert.

MfG,
André

@buanet buanet added enhancement It's not a bug, but it's worth an enhancement. and removed bug This issue is confirmed. labels Jan 3, 2024
@buanet buanet changed the title [Problem]: maintenence restart -y does not work [Feature Request]: possibility to call a restart from inside ioBroker (e.g. javascript-adapter) Jan 3, 2024
@FernetMenta
Copy link
Author

Hallo André,

Wenn ich dich recht verstehe, dann scheitert mit der Beta jetzt nur noch der Aufruf aus einem ioBroker JavaScript heraus, richtig?

Ja, das stimmt zum Teil. Es gab keinen Unterschied von der beta zur v9.0.1. Es scheitert bei beiden aus den JavaScript heraus und funktioniert von der Kommandozeile. Komisch ist allerdings, dass wenn es erst mal gescheitert ist, es von der Kommandozeile auch nicht mehr geht. Wie kann man sich das erklären?

Wenn meine Vermutung von oben bezüglich deines Problems zutrifft, würde ich den issue gerne von bug auf enhancement ändern und du bekommst von mir vorerst ein "works as designed". :) Ich nehme das Thema aber natürlich gerne als Feature Request mit auf meine To-Do-Liste!

Ja, klingt gut. Danke!
Hast du schon eine Idee, wie man das lösen könnte? Evtl mit child_process.spawn mit detach direckt im Javascript arbeiten?

Viele Grüße,
Rainer

@FernetMenta
Copy link
Author

Ich habe jetzt eine Lösung, die funktioniert:

  var cp = require('child_process');
  var child = cp.spawn('bash', ['iob', 'maint', 'restart', '-y'], 
                        { detached: true, stdio: [ 'ignore', 'ignore', 'ignore' ] });
  child.unref();

@buanet buanet added the workaround available There is still a workaround available. label Jan 6, 2024
@buanet buanet self-assigned this Jan 26, 2024
@buanet buanet removed their assignment Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement It's not a bug, but it's worth an enhancement. workaround available There is still a workaround available.
Projects
None yet
Development

No branches or pull requests

2 participants