Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #173419 > unrolled thread

systemd

Started byPol Hallen <deben@fuckaround.org>
First post2016-10-11 20:30 +0200
Last post2016-10-11 21:20 +0200
Articles 3 — 3 participants

Back to article view | Back to linux.debian.user


Contents

  systemd Pol Hallen <deben@fuckaround.org> - 2016-10-11 20:30 +0200
    Re: system d Brian <ad44@cityscape.co.uk> - 2016-10-11 21:10 +0200
    PID files of services vs. systemd (was: Re: systemd) Christian Seiler <christian@iwakd.de> - 2016-10-11 21:20 +0200

#173419 — systemd

FromPol Hallen <deben@fuckaround.org>
Date2016-10-11 20:30 +0200
Subjectsystemd
Message-ID<sr9Yl-1IC-13@gated-at.bofh.it>
Hi all, after upgraded oldstable to stable it happens that systemd 
doesn't create PID file of these packages:

openvpn
smartmontools

and maybe others... I auditing now...

any idea to have PID file of openvpn and smartmontools?

thanks for help!

Pol

[toc] | [next] | [standalone]


#173420 — Re: system d

FromBrian <ad44@cityscape.co.uk>
Date2016-10-11 21:10 +0200
SubjectRe: system d
Message-ID<sraB3-2b0-7@gated-at.bofh.it>
In reply to#173419
On Tue 11 Oct 2016 at 20:04:43 +0200, Pol Hallen wrote:

> Hi all, after upgraded oldstable to stable it happens that systemd doesn't
> create PID file of these packages:
> 
> openvpn
> smartmontools
> 
> and maybe others... I auditing now...
> 
> any idea to have PID file of openvpn and smartmontools?
> 
> thanks for help!

As Michael Biebl said in reply to your mail to debian-systemd:

  This is a bug tracker, not a user support forum.
  Please try the debian-user mailing list for such support questions next
  time.

  If the services in question don't have a pidfile, that's usually an
  indication that they don't use Type=forking, which is perfectly valid.

  Anyway, there is no bug in systemd here. So closing.

There could be a clue in that response for you to investigate. Perhaps
you could do that and report here. Better to provide than just ask for
"any idea". Audit away.

P.S. Your posting seems to live up to your domain name.

-- 
Brian.

[toc] | [prev] | [next] | [standalone]


#173421 — PID files of services vs. systemd (was: Re: systemd)

FromChristian Seiler <christian@iwakd.de>
Date2016-10-11 21:20 +0200
SubjectPID files of services vs. systemd (was: Re: systemd)
Message-ID<sraKJ-2ef-3@gated-at.bofh.it>
In reply to#173419
On 10/11/2016 08:04 PM, Pol Hallen wrote:
> Hi all, after upgraded oldstable to stable it happens that systemd
> doesn't create PID file of these packages:
> 
> openvpn
> smartmontools

There's a general misconception here: systemd never creates pid
files for daemons.

The PIDFile= setting in a unit file is a setting that tells
systemd where to look for PID files that it reads in to find
out the main PID of a forking process.

A bit of background: systemd has a concept called "main pid" of
a process. If you use KillMode=process or something along the
lines of ExecReload=/bin/kill -HUP $MAINPID, systemd will
automatically use the main pid of the service for these
operations. Also, a non-main process exiting in a service is
not considered a problem from a systemd perspective, but the
main process exiting is. In a very simple case, the main pid of
a service is trivial: if there's only one pid in a service,
that's the main pid.

However, there are other services that start multiple processes,
and there it's not necessarily easy to determine what the main
process of that service is. In these situations, systemd has
the ability to read pid files (that were written by the service
_itself_ after startup) to determine the main pid. The sequence
would be:

 - systemd starts the program
 - the program forks
 - the fork initializes
 - the program writes the pid file
 - the original process exits
 - systemd notices that, considers the forking service
   initialized, and reads in the pid file

If a forking service doesn't write a pid file, systemd will try
to guess the main process (see the GuessMainPID= setting)
instead. If there's only a single process in the service, that's
going to work reliably, but if there are multiple processes it
might not.

Also, if you don't use Type=forking but other service types,
then PID files are irrelevant from a systemd perspective - and
the PIDFile= setting is ignored. For example, if you have a
Type=notify unit, then the process spawned by systemd will not
exit (startup completion notification is done via the sd-notify
protocol instead) during regular operations, so that's going to
be the main pid of the unit.


Now for your units: I don't have openvpn installed, so I'd have
to check (and am too lazy right now to do so), but for
smartmontools the service is of Type=simple, so nothing forks
there. (smartd is called with -n, with leaves it in the
foreground.) There's simply no need for a PID file here, as the
main pid of the process is trivially known to systemd.

Now if you want to know the main PID of any given running
service for yourself, outside of systemd, then you don't need
a pid file anymore, you can query systemd dynamically,
regardless of service type:

systemctl show -p MainPID smartd.service

for use in scripting you can also do:

PID=$(systemctl show -p MainPID smartd.service 2>/dev/null | cut -d= -f2)
  (will be empty on error, e.g. service not running)

Hope that helps.

Regards,
Christian

[toc] | [prev] | [standalone]


Back to top | Article view | linux.debian.user


csiph-web