I'm running svnserve on a Fedora 17 machine with the following systemd service file:

Description=Subversion Server
After=syslog.target network.target

ExecStart=/usr/bin/svnserve --daemon --pid-file=/run/svnserve/svnserve.pid -r /repos/svn


This works fine as long as /var/run/svnserve is owned by svn:svn, but breaks on reboot when that ownership is reset to root:root. What I want is to add a pre-launch step that chowns the directory.

Unfortunately I can't find any real documentation on systemd unit files, but I saw that some were using 'ExecStartPre', so I tried this:

ExecStartPre=/bin/chown svn:svn /run/svnserve

Sadly this fails with an 'operation not permitted' error, so it looks like ExecStartPre also runs as the user specified in the unit file.

I also tried having the unit file run as root, then starting svnserve as the svn user via su, but that produced a vague error about the command-line being invalid.

How can systemd units perform actions as root prior to executing as a specific user?

closed as too localized by Michael Hampton, Ward, Jacob, Khaled, mdpc Feb 26 '13 at 20:13

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. If this question can be reworded to fit the rules in the help center, please edit the question.

  • You report this as a bug. The permissions should already be correct on the /run directory and the pid file, but lots of these broke with the switch to systemd and the /usr move. – Michael Hampton Feb 25 '13 at 21:14
  • @MichaelHampton I don't believe this is how it came out of the box. IIRC (this was set up a while back) svnserve doesn't come with a service wrapper, so this was something that we wrote ourselves. – DNS Feb 25 '13 at 21:24
  • 1
    Subversion on Fedora certainly does come with this. It looks fairly similar to yours, though I would recommend you use the original. yum reinstall subversion – Michael Hampton Feb 25 '13 at 21:28
  • If you gave your su command line we may be able to solve that problem. – Hauke Laging Feb 26 '13 at 3:48
  • 1
    PermissionsStartOnly=false will cause all ExecStartPre and ExecStartPost commands to ignore User and run as root. – Charles Duffy Apr 4 '17 at 15:04

The subversion package in Fedora is using systemd's tmpfiles mechanism to create /run/svnserve at boot with root ownership (since the packaged .service file apparently runs the daemon as root). You could copy /usr/lib/tmpfiles.d/svnserve.conf to /etc/tmpfiles.d/svnserve.conf and change the owner. See man tmpfiles.d for details.

  • 1
    Aha; I had no idea that tmpfiles mechanism existed. Thank you! – DNS Feb 26 '13 at 12:33

You could make ExecStartPre a sudo call to a script and configure the user svn for this script.

  • Can't use sudo; there is no TTY when running systemd units. – DNS Feb 26 '13 at 12:32
  • Why should sudo need a tty if no password is needed? – Hauke Laging Feb 26 '13 at 15:26
  • I don't know exactly, but I had tried that idea, and the system logged an error stating that sudo requires a TTY. – DNS Feb 26 '13 at 17:12
  • 1
    Moreover, setting PermissionsStartOnly=false will in and of itself tell systemd to run ExecStartPre and ExecStartPost processes as root. – Charles Duffy Apr 4 '17 at 15:03
  • 2
    @Davos, in that case, just use a preceding + for the ExecStartPre; ExecStartPre=+/path/to/thing-to-run-as-root; that way you're applying a change only to that one specific command, not making global modifications at all. – Charles Duffy Dec 18 '17 at 16:08

Not the answer you're looking for? Browse other questions tagged or ask your own question.