1

I'm running ubuntu 16.04.

Let's say I want the system to run "mkdir /var/log/servicename" before starting the service (needed due to having /var/log in tmpfs).

Previously, with upstart, I edited the conffile /etc/init/servicename to add commands to it.

Now the service is being run through systemd, and the init config file for it, /lib/systemd/system/servicename is not a conffile, i.e. if edited it will be replaced on a package update.

What is the recommended way to solve this problem?

0

One solution that I found but don't really like:

  • Copy the package's service file to a new name: cp /lib/systemd/system/$servicename.service /lib/systemd/system/$servicename-my.service.
  • Edit the new service file: add ExecStartPre=... next to the ExecStart: sed -i "s_^ExecStart=_ExecStartPre=/bin/mkdir -p /var/log/$servicename\nExecStart=_" /lib/systemd/system/$servicename-my.service
  • Disable the old service, enable the new one: systemctl stop $servicename; systemctl disable $servicename; systemctl enable $servicename-my; systemctl start $servicename-my.

The main reason I don't like this solution is needing a file outside of /etc, which would be considered “cruft” by the corresponding tools.

Also, not extensively tested.

Edit1:

Correction: by documentation it should be possible to put the modified service file in /etc/systemd/system/ without renaming it. Will test later.

Another tangentially related problem: PermissionsStartOnly=yes might not work correctly.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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