0

I have created this systemctl job,

[Unit]
Description=Evercam Media
After=network.target

[Service]
Type=forking
User=root
Group=root
WorkingDirectory=/opt/evercam_media
ExecStart=/opt/evercam_media/bin/evercam_media start
ExecStop=/opt/evercam_media/bin/evercam_media stop
Restart=always
RestartSec=5
Environment=LANG=en_US.UTF-8
SyslogIdentifier=evercam_media

[Install]
WantedBy=multi-user.target

It's working perfectly, as I want it to work, But I want to show some log on start and stop, as when we start or stop the upstart job, it shows us, the job is stopped or waiting, But it's not showing anything, Can we add few logs like "Its started" or Its stopped, something like this?

Also when I see the status of this job while doing systemctl status evercam_media.service, it shows me

● evercam_media.service - Evercam Media
   Loaded: loaded (/etc/systemd/system/evercam_media.service; enabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Tue 2017-11-07 10:53:40 CET; 1h 3min ago
  Process: 25830 ExecStop=/opt/evercam_media/bin/evercam_media stop (code=exited, status=0/SUCCESS)
  Process: 25692 ExecStart=/opt/evercam_media/bin/evercam_media start (code=exited, status=0/SUCCESS)
 Main PID: 25728 (code=exited, status=1/FAILURE)

Active: Failed??

Why it's not saying its stopped instead of failed? any help would be appreciated thanks.

1 Answer 1

0

The systemd unit is set to Type=forking and ExecStop= is used with an asynchronous command.

Which means systemd will kill the main process right after

/opt/evercam_media/bin/evercam_media stop
exits. And Restart=always is used instead of Restart=on-failure.

As it states in the documentation:

Note that it is usually not sufficient to specify a command for this setting that only asks the service to terminate (for example, by queuing some form of termination signal for it), but does not wait for it to do so. Since the remaining processes of the services are killed according to KillMode= and KillSignal= as described above immediately after the command exited, this may not result in a clean stop. The specified command should hence be a synchronous operation, not an asynchronous one.

There's multiple approaches you can take to fix this. Use TimeoutSec= or use a kill signal that doesn't make evercam_media return 1 or find a way to make your ExecStop= synchronous.

As for log messages refer to verbosity flags for evercam_media.

4
  • your answer is totally ununderstandable :) sorry but I didnt understand it at all. Commented Nov 7, 2017 at 13:09
  • I'm wondering if Type=forking is correct. Does the evercam_media program background itself when started from a command line, or does it stay in the foreground? If the latter, Type should not be set to forking. Commented Nov 7, 2017 at 13:58
  • It does. As seen in the OPs screens there is a separate process for the server and the start/end processes exited.
    – jdwolf
    Commented Nov 8, 2017 at 2:00
  • 1
    OP try putting "TimeoutSec=2s" in your unit file and see if that fixes your issue. To do what you're doing you should read more of the systemd documentation.
    – jdwolf
    Commented Nov 8, 2017 at 2:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .