You are not logged in.

#1 2012-11-14 19:00:23

dwheeler
Member
Registered: 2010-11-12
Posts: 21

[Solved] Overriding systemd Unit Files Isn't Working

I'm trying to set up some custom dependencies for various services, some of which are supported packages, some are custom packages I've developed. I am running into problems following the procedure described here - specifically, service files in /etc/systemd/system are ignored, and the only way to override them is to edit the files in /usr/lib/systemd/system. I have verified this issue on both a VPS instance and my desktop. Both systems were originally built well before systemd and have been converted to pure systemd systems. Does anyone else see these issues, or know of any reason this would be happening and/or how to resolve it?

Steps to reproduce. This example uses httpd and mysql, but I've tested it with several other services, always with the same results:

  1. Enable the service unit and create a new override:

    systemctl enable httpd.service
    rm /etc/systemd/system/multi-user.target.wants/httpd.service
    cp /usr/lib/systemd/system/httpd.service /etc/systemd/system/multi-user.target.wants/httpd.service
  2. Edit /etc/systemd/system/multi-user.target.wants/httpd.service, adding a line 'Wants=mysqld.service' to the [Unit] section.

  3. Make systemd changes effective, and verify them. The first command results in an error that says "Failed to issue method call: Invalid argument". The final command will show an empty list  ("Wants="), when it should list mysqld. Running systemd-delta also shows no override.

    systemctl reenable httpd
    systemctl daemon-reload
    systemctl show -p "Wants" httpd.service
  4. Change the replacement unit file to .include the packaged unit file:

    cat > /etc/systemd/system/multi-user.target.wants/httpd.service << __EOF
    .include /usr/lib/systemd/system/httpd.service
    
    [Unit]
    Wants=mysqld.service
    __EOF
  5. Repeat step #3, with the same results

  6. Reenable the package's unit:

    rm /etc/systemd/system/multi-user.target.wants/httpd.service
    systemctl enable httpd.service
  7. Edit the original unit file in /usr/lib/systemd/system/httpd.service, adding the 'Wants=myslqd.service' to the Unit section

  8. Repeat step 3

  9. Result is the correct and expected one this time ("Wants=myslqd.service")

Last edited by dwheeler (2012-11-14 19:53:10)

Offline

#2 2012-11-14 19:14:31

ataraxia
Member
From: Pittsburgh
Registered: 2007-05-06
Posts: 1,553

Re: [Solved] Overriding systemd Unit Files Isn't Working

You need to copy the file you want to change to /etc/systemd/system/ , not directly to the multi-user.target.wants/ subdirectory. The objects in the *.wants/ directories need to remain symlinks to the actual unit files. I made this same mistake when I was new to systemd.

Offline

#3 2012-11-14 19:17:43

falconindy
Developer
From: New York, USA
Registered: 2009-10-22
Posts: 4,111
Website

Re: [Solved] Overriding systemd Unit Files Isn't Working

Order matters here. Units are lazily loaded into memory on an as-needed basis.

1) copy the unit to /etc/systemd/system (NOT to the .wants dir)
2) systemctl daemon-reload
3) systemctl enable foo.service # or reenable if applicable

That's all you need to do.

Offline

#4 2012-11-14 19:52:47

dwheeler
Member
Registered: 2010-11-12
Posts: 21

Re: [Solved] Overriding systemd Unit Files Isn't Working

Thanks, using the correct directory fixed my issue! Guess I should have paid closer attention to the wiki page. smile

Offline

#5 2012-11-27 19:10:05

fusca
Member
Registered: 2008-01-16
Posts: 25

Re: [Solved] Overriding systemd Unit Files Isn't Working

Well...

I'm still having problems with .service custom files!

I want to customize the ExecStart from original cronie.service file, like this:

# cat /etc/systemd/system/cronie.service                                                                                         
.include /usr/lib/systemd/system/cronie.service                                                                                               

[Service]                                                                                                                                     
ExecStart=/usr/sbin/crond -n -s -m off

==============================

# systemctl restart cronie.service                                                       
Failed to issue method call: Unit cronie.service failed to load: Invalid argument. See system logs and 'systemctl status cronie.service' for details.

==============================

# systemd-delta                                                                                             
[OVERRIDDEN] /etc/systemd/system/cronie.service → /usr/lib/systemd/system/cronie.service

--- /usr/lib/systemd/system/cronie.service      2012-11-22 20:04:00.000000000 -0200
+++ /etc/systemd/system/cronie.service  2012-11-27 16:09:49.944085437 -0200
@@ -1,10 +1,3 @@
-[Unit]
-Description=Periodic Command Scheduler
-
+.include /usr/lib/systemd/system/cronie.service
[Service]
-ExecStart=/usr/sbin/crond -n
-ExecReload=/bin/kill -HUP $MAINPID
-Restart=always
-
-[Install]
-WantedBy=multi-user.target
+ExecStart=/usr/sbin/crond -n -s -m off

==============================

# systemctl status cronie.service
cronie.service - Periodic Command Scheduler                                                                                                   
          Loaded: error (Reason: Invalid argument)
          Active: inactive (dead)
          CGroup: name=systemd:/system/cronie.service

Nov 27 13:52:59 xpto systemd[1]: Starting Periodic Command Scheduler...
Nov 27 13:52:59 xpto systemd[1]: Started Periodic Command Scheduler.
Nov 27 13:52:59 xpto /usr/sbin/crond[309]: (CRON) INFO (running with inotify support)
Nov 27 14:01:01 xpto /usr/sbin/crond[8216]: pam_unix(crond:session): session opened for user root by (uid=0)
Nov 27 14:01:01 xpto /USR/SBIN/CROND[8217]: (root) CMD (run-parts /etc/cron.hourly)

==============================

What am I doing wrong?

Thanks in advance.

Offline

#6 2012-11-28 08:59:49

Gilrain
Member
From: France
Registered: 2011-12-24
Posts: 7

Re: [Solved] Overriding systemd Unit Files Isn't Working

fusca wrote:

I'm still having problems with .service custom files!
I want to customize the ExecStart from original cronie.service file, like this:
[...]
What am I doing wrong?

Nothing, it's a limitation of systemd. Exec* commands can't be overridden, only stacked when using "Type=oneshot".
You need to copy the entire file to /etc/systemd/system/ and make your changes there. Don't forget to issue "systemctl reenable cronie.service" to update the link in multi-user.target.wants.

Last edited by Gilrain (2012-11-28 09:00:26)

Offline

#7 2012-11-28 12:25:37

fusca
Member
Registered: 2008-01-16
Posts: 25

Re: [Solved] Overriding systemd Unit Files Isn't Working

Gilrain wrote:
fusca wrote:

I'm still having problems with .service custom files!
I want to customize the ExecStart from original cronie.service file, like this:
[...]
What am I doing wrong?

Nothing, it's a limitation of systemd. Exec* commands can't be overridden, only stacked when using "Type=oneshot".
You need to copy the entire file to /etc/systemd/system/ and make your changes there. Don't forget to issue "systemctl reenable cronie.service" to update the link in multi-user.target.wants.

Thanks Gilrain!

Can you tell me if systemd's team will fix this limitation in a near future?

Offline

#8 2012-11-28 12:31:41

Gilrain
Member
From: France
Registered: 2011-12-24
Posts: 7

Re: [Solved] Overriding systemd Unit Files Isn't Working

No idea but I hope they do. Having to constantly compare service files after each upgrade of cronie and co. is becoming bothersome. Luckily there's systemd-delta...

Offline

#9 2014-02-06 18:53:43

frank
Member
From: Karlsruhe/Germany
Registered: 2014-02-06
Posts: 8

Re: [Solved] Overriding systemd Unit Files Isn't Working

Although the problem seems to be solved, I solved a similar problem with tftp server (tftp-hpa 5.2-4) like this.

Let me explain some of my thoughts first:

1. The unit file /usr/lib/systemd/system/tftpd.service contains

...
[Service]
ExecStart=/usr/bin/in.tftpd -s /srv/tftp/
...

2. I want a different directory (/home/frank/tftp/ instead of /srv/tftp/).
3. I don't want to create a full copy of /usr/lib/systemd/system/tftpd.service in /etc/systemd/system/, because it will override all settings. That means, later updates of /usr/lib/systemd/system/tftpd.service would be masked completely.
3. OTOH, I also don't want to edit the global unit file /usr/lib/systemd/system/tftpd.service because I fear problems if the tftp-hpa package is updated.

That's why I created a drop-in directory and a .conf file in /etc/systemd/system/tftpd.service.d/tftpdir.conf to override exactly ExecStart:

[Service]
ExecStart=
ExecStart=/usr/bin/in.tftpd -s /home/frank/tftp/

You have do clear ExecStart= first before you can override it.
Lennart Poettering mentioned this trick on Bugzilla in comment 9  and its implementation in comment 12.

Offline

#10 2016-06-30 05:30:13

mikael
Member
From: Slovakia
Registered: 2011-05-22
Posts: 27
Website

Re: [Solved] Overriding systemd Unit Files Isn't Working

For me the following worked

sudo cp /usr/lib/systemd/system/httpd.service /etc/systemd/system
sudo vim /etc/systemd/system/httpd.service
sudo systemctl daemon-reload
sudo systemctl restart httpd.service

For locating the unit file I just used

locate httpd.service

Offline

#11 2016-06-30 06:34:13

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: [Solved] Overriding systemd Unit Files Isn't Working

Thread is over four years old and marked solved. Please don't necrobump: https://wiki.archlinux.org/index.php/Co … bumping.22



Closing


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

Board footer

Powered by FluxBB