Mender standalone execute without tty hangs, because it expects an enter at the end

Hello,

I’m trying to call the command sudo mender -install /path/to/artifact.mender from a subprocess.
The command is working and it executes the update, but it hangs at 100% so it won’t finish with “Done” like when I execute it directly in the terminal

nohup command:
nohup sudo mender -install /home/username/update/nodered/nodered-artifact-1.2-b5.mender > /home/username/loginstall 2>&1 &

nohub output:
Installing Artifact of size 9902592... time="2020-02-26T09:03:19Z" level=info msg="no public key was provided for authenticating the artifact" module=installer ................................ 10% 1024 KiB ................................ 21% 2048 KiB ................................ 31% 3072 KiB ................................ 42% 4096 KiB ................................ 52% 5120 KiB ................................ 63% 6144 KiB ................................ 74% 7168 KiB ................................ 84% 8192 KiB ................................ 95% 9216 KiB .............. 100% 9670 KiB

command in terminal:
sudo mender -install /path/to/artifact.mender

output in terminal:
INFO[0000] no public key was provided for authenticating the artifact module=installer ................................ 10% 1024 KiB ................................ 21% 2048 KiB ................................ 31% 3072 KiB ................................ 42% 4096 KiB ................................ 52% 5120 KiB ................................ 63% 6144 KiB ................................ 74% 7168 KiB ................................ 84% 8192 KiB ................................ 95% 9216 KiB .............. 100% 9670 KiB Use -commit to update, or -rollback to roll back the update.

How can I solve this?

@oleorhagen any thoughts here? I have no ideas.

I’m gonna need some more context here I think.

What do you mean by Done @Qfine. Does the process never finish? What shows up in you process list (i.e., ps -a).

What sort of update is it?

I don’t initially see anything wrong here I think

Hello,

It seems like I’ve found the problem, but no solution to solve this.

I’m starting the script from “node-red” which creates a child process and this child process is not completely detached from the parent process, which is “node-red”. So the script then starts the mender installer and the update module does the following: stops node-red, copy unzipped files to the new directory and starts node-red again. At the time the node-red instance is stopped, the mender updater stops to work because the command is triggered by the parent process.

I thought that nohup will solve this problem by detaching the process from the child. I also tried it with disown or also with a Node.JS Application, which creates a child process and then detaches this process.
But nothing seems to work :frowning: .

Does anyone have an idea to solve this?

Thank you in advance

cheers,
Qfine

I’m afraid I’m unfamiliar with Node-Red. Looks interesting though.

May I ask why you are running Mender in standalone from Node red, instead of in daemon-mode?

If it’s a systemd system, you could try using systemd-run, which will put the process in its own cgroup. It’s sometimes a bit tricky to get it to do the right thing though, you may need to experiment with some arguments (maybe -P or --scope) to get the right behavior. The man page is your friend.

1 Like

Ok I’m confused now.
If I run mender in daemon-mode, how I then call the client to trigger a mender update?

I was just only using mender as a “command” and triggered it from console, but now I need some more automatic logic to call the updater based on some events.

I always thought the daemon mode is only useful, when it’s used in managed mode with mender server. But we don’t use a mender server. The devices are running all standalone.

I see.

Yes, if you want to explicitly control when an update is run, standalone mode is for you. I was just curious :wink:

Sry, if I caused you some confusion here

Ok I’ve found a workaround.
The problem is, that I can’t detach the mender command from the node-red parent process. So and if the update process run, the node-red service is stopped, which affects the mender installation process as a child process it self.
I also tried to detach the process with different methods, like fork and also as subprocess with python.

Now I’ve written an FIFO listener which listen to commands and triggers the mender update procedure.
The listener is written in python and is running as a deamon process on startup.
From node-red I’m pushing the command to the running listener which than executes the mender update process. This seems to work stable, but still needs also some security handling.

If someone is interested in this, I can share it, but I think this is a bit off-topic and has nothing to do with mender it self.

Thank you everyone for the help!

cheers,
Qfine

1 Like

I think it sounds like an interesting little widget to read about :slight_smile:

Ok sure, it’s nothing special and needs a lot of more improvements.

#!/bin/python
import os
import errno
from subprocess import Popen

FIFO = '/home/username/scripts/updater/mendercommandfifo'

try:
    os.mkfifo(FIFO)
except OSError as oe:
    if oe.errno != errno.EEXIST:
        raise

def fireUpCommand(cmd):
    devnull = open(os.devnull, 'wb')
    print(cmd)
    Popen(cmd.split(), stdout=devnull, stderr=devnull)

while True:
    print("Opening FIFO...")
    with open(FIFO) as fifo:
        print("FIFO opened")
        while True:
            data = fifo.read()
            if len(data) == 0:
                print("Writer closed")
                break
            fireUpCommand(data)
1 Like