You are not logged in.

#1 2013-08-02 17:25:40

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

[SOLVED] Systemd service files: sourcing other service files?

Is there a way to "source" one systemd service file from another, so that the service inherits all settings from the other file? The purpose would be to override or append select fields as a quasi-patch of the other file, e.g.

<source foo.service>
[section]
key=new_value

I was sure that I had seen this somewhere, but I can't find it. Did I make this up, or is my search-fu simply weak?


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#2 2013-08-02 17:30:14

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: [SOLVED] Systemd service files: sourcing other service files?

You can use the drop in replacement stuff.  So for example, if you wanted to use a different port for the sshd.socket, you should create /etc/systemd/system/sshd.socket.d/newsocket.conf with:

[Socket]
ListenStream=
ListenStream=12345 

I wondered about this for a long time, and this is what I have found others doing. It seems to work.  Although, I don't think you can append to a field like a bash variable or anything like that.

Edit: Otherwise, you can use the .include way as well.  Though I am not sure if this gives you the same replacement ability as I have never tried it.  But you would just create a new service file, named whatever, and you would tell it ".include /usr/lib/systemd/system/original.service".  This way also gives you the ability to include the contents of that other service in a totally differently named unit.

Last edited by WonderWoofy (2013-08-02 17:31:54)

Offline

#3 2013-08-02 17:39:27

Xyne
Administrator/PM
Registered: 2008-08-03
Posts: 6,963
Website

Re: [SOLVED] Systemd service files: sourcing other service files?

@WonderWoofy
Thanks. The .include command is what I have seen before. I just couldn't remember the name of it. It is only briefly mentioned here in the systemd.unit man page.

I wasn't aware of the first method. Do you have a link to the documentation?


edit: In the end, I found the first method to be the most convenient.

Last edited by Xyne (2013-08-02 17:59:57)


My Arch Linux StuffForum EtiquetteCommunity Ethos - Arch is not for everyone

Offline

#4 2013-08-02 21:16:00

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: [SOLVED] Systemd service files: sourcing other service files?

I don't know that it is actually documented at this point in time.  At least I haven't seen any.  The only reason I know about it is beacuse I subscribe to [systemd-devel].  But it was briefly touched on in the announcement when it was first introduced. 

I know that the .include method is documented very briefly in one of the man pages, but it doesn't really go into depth about how to use it.  I do seem to recall a nice write up about it on Lennart's blog though.  But it seems as though the intent of the systemd.unit.d (what they are calling "drop-in" modifications/replacements) is intended to replace the .include way.  Though I am basing that statement off of the general attitude toward each on the mailing list, and I have seen no official word on this.

The nice thing about using .include is that you can use systemd-delta to see the changes made using that method.  And while the systemd.unit.d changes are noted in that output, it is nothing more than simply indicating that there has been modification.  The .include stuff actually has a full "diff -u" style output.

Offline

Board footer

Powered by FluxBB