Re: Syntax check for a new service?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Feb 26, 2022 at 7:05 PM Tom Browder <tom.browder@xxxxxxxxx> wrote:
On Sat, Feb 26, 2022 at 09:38 Dave Howorth <systemd@xxxxxxxxxxxxxx> wrote:
On Sat, 26 Feb 2022 09:17:38 -0600
Tom Browder <tom.browder@xxxxxxxxx> wrote:
> Is there any way to get a plain syntax check of a potential new
> service file?

systemd-analyze verify FILE...

Thanks, Dave.

I'm apparently having problems with the executable file and I'm not sure if I need
the Type to be simple or oneshot.

The service I'm trying to create is to emulate a user at the CLI executing a script running in the foreground who never logs out.

The script loops infinitely listening and responding to a specific port behind an apache reverse proxy. The script is programmed to stop with a Ctr-C. It can be left with "nohup &" (but I'm not sure if that interferes with its design yet).

Right, that's basically how all services work. (It's not really something I would call "emulating a user" – that just feels backwards. It's more like *the user* with 'nohup' is emulating a service manager here...)

If the service remains running in foreground, it's Type=simple. (Services which go into background, i.e. have a 'daemonize' function, would be Type=forking.)

Type=oneshot is for "one-shot" tasks which do something relatively quick and exit; for example, if another unit had "After=an-oneshot.service", it would wait until that service *exits,* rather than until it's "started". It's not suitable for actual long-running services like yours – if you tried to use Type=oneshot, systemd would think your service was "starting" forever.
 

I do know I have to set an environment variable for the executable to find its libraries, and I'm not sure how to do that in the service file to emulate this:

    export MYLIB=/path/to/lib; /path/to/prog

I have tried both Type=oneshot and Type=simple but neither like the single ExecStart= line with that command.

Neither of them invoke /bin/sh to parse the command – the *shell* is what normally would interpret the "export ..." in a shell script, but that doesn't happen in systemd services. In all cases, ExecStart is minimally parsed by systemd itself and then just directly execve()'d.

Use the Environment= option to set environment variables.

--
Mantas Mikulėnas

[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux