Startup process not starting in Arch Linux

0

I have problems starting some applications on boot that I have made to run an ArchLinux Environment (running in a VM).

I have some executable (programmed in C++ and Python) that must start when the VM (Oracle) starts Arch Linux.

I have programmed for this a shell script (that I have tested and I have also gave the required privileges) that starts this two processes (that they remains active forever in the session) and I have also designated a service that actually must start the Shell (in ../System/..) but even if the command systemctl enable/start/Status said that everything is ok I don’t see the processes (using ps command).

I am not sure but I could imagine that service start the process but in the end they are killed somehow even if the shell script the process are with &.

The strange thing is that the same routine that I have used to mount a folder is acceptable and it is ok but somehow (maybe inexperience) I cannot succeed to autostart this two process.

Here is my shell script:

 #!/bin/sh

/bin/python3  /myPath/firstexe &
/bin/python3 /myPath/secondexe &

The result of:

systemctl Status myservice.service

Is:

...
Process:ExecStart=.../myshell (Code=exited, Status=0/SUCCESS)
...

Could you help me to solve this problem?

Giovanni

Posted 2019-09-17T13:46:53.133

Reputation: 1

Answers

1

I am not sure but I could imagine that service start the process but in the end they are killed somehow even if the shell script the process are with &.

No, that is why they are killed.

A standard systemd service can have any number of processes in it, but it always needs to have exactly one "main" process. Systemd considers the service "running" when that process is running, and "stopped" when that process exits. Once the service stops (either on its own, or when you manually systemctl stop it), systemd kills all "leftover" processes that were launched by it.

This means that:

  1. You can only start one daemon per systemd .service – in your case, when there are two independent long-running processes, they should be managed as two separate .service files.

    (However, the service can have various subprocesses running at any time – e.g. worker processes – regardless of Type= or other service settings.)

  2. You shouldn't start the daemon through intermediary shellscripts. Systemd will end up tracking the script and not the daemon itself, so it will think the service has "exited" as soon as the script finishes.

  3. If the process tries to "daemonize" or "go into background" on its own, you need to tell systemd about what to expect, using the Type=forking option. In your case, however, that's not needed. (The default is Type=simple.)

  4. However, if the process doesn't "daemonize" on its own, forcing it with & is redundant – services already exist "in background", so to speak, and systemd can deal with daemonizing and non-daemonizing services equally well.

(Finally, there is an exception for "services" which are expected to do just a quick task and don't actually have a daemon – you can use Type=oneshot for those.)

user1686

Posted 2019-09-17T13:46:53.133

Reputation: 283 655

Thanks I will try to follow your advice an split into two services (without passing through a shell script) and deal with the forking type... really thanks – Giovanni – 2019-09-17T15:09:24.130

0

You are missing the full path to the scripts you are trying to run.

It seems to me that you should change firstexe and secondexe to be the full path to those files.

Go into the directory those are located in, type in pwd and that will give you the path to the working directory. Put that before firstexeandsecondexelike this; using/full/path/to/` as an example:

/full/path/to/firstexe

And:

/full/path/to/secondexe

I would also recommend you change your shell script “shebang” as follows:

#!/bin/sh

To this:

#!/bin/bash -l

Bash is the more common — and less limited — shell script and the -l will pass along environment variables to your script. This isn’t really the core of your issue, but I recommend it in general for shell scripts.

In summary, I would recommend using this version of your script; just change /full/path/to/ to be the actual full path to those scripts:

#!/bin/bash -l

/bin/python3 /full/path/to/firstexe &
/bin/python3 /full/path/to/secondexe &

JakeGould

Posted 2019-09-17T13:46:53.133

Reputation: 38 217

Thanks but I have the full path(I have forgot to mention).. The shell launched manually start regularly and the two process starts with no problem ...I also added the #!/bin/bash -l but nothing – Giovanni – 2019-09-17T14:55:55.047