Bug 66641 - PID file /var/run/program.pid not readable (yet?) after start. PIDFile + User&Group
Summary: PID file /var/run/program.pid not readable (yet?) after start. PIDFile + User...
Status: RESOLVED NOTABUG
Alias: None
Product: systemd
Classification: Unclassified
Component: general (show other bugs)
Version: unspecified
Hardware: All Linux (All)
: medium normal
Assignee: systemd-bugs
QA Contact: systemd-bugs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-07-06 11:31 UTC by Alexey Ivanov
Modified: 2013-07-06 14:09 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

Description Alexey Ivanov 2013-07-06 11:31:50 UTC
Example service file

[Unit]
Description=Daemon
After=syslog.target network.target

[Service]
Type=forking
User=programd2
Group=programd2
PIDFile=/var/run/programd2.pid
ExecStart=/usr/sbin/programd2 -D

[Install]
WantedBy=multi-user.target

I need to start service from the user. Also must have a pid file. But if i use User= Group= not able to create pid file in /var/run (No permission). In logs:
PID file /var/run/programd2.pid not readable (yet?) after start.

I believe that this is a problem systemd. Systemd should create pid as "root" and do it chown before Exec.

This is a very bad decision:
>> ExecPre=touch /var/run/program.pid
>> ExecPre=chown programd2:programd2/var/run/program.pid
>> Exec=/bin/su -s /bin/sh -c '/usr/sbin/programd2 -D' programd2
Comment 1 Zbigniew Jedrzejewski-Szmek 2013-07-06 12:42:35 UTC
If running a program as unprivileged user, you need to make sure that it has access to all the resources it needs.

Try sticking:
d /run/programd2 0755 programd2 programd2 - -
in /etc/tmpfiles.d/programd2.conf

and changing the unit file to have:
PIDFile=/run/programd2/programd2.pid
and updating the configuration for the program to actually write there.
Comment 2 Kay Sievers 2013-07-06 14:09:03 UTC
(In reply to comment #0)
> I believe that this is a problem systemd. Systemd should create pid as
> "root" and do it chown before Exec.

Also note, that systemd is not creating any PID file, it is just your
daemon that does that.

In general, we recommend getting rid of the need of all PID files, as they
are an outdated and pretty broken concept; they are not needed at all with
systemd, just minimally supported by it, as legacy, for stuff that still
needs it.


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.