packaging: use templates for relevant systemd units #3084

Merged
merged 12 commits into from Apr 5, 2017

Conversation

Projects
None yet
5 participants
Contributor

morphis commented Mar 24, 2017

To make packaging across different distributionis a bit easier we
now use templates for some of our systemd units and replace things
which are in a different location with sed at build time.

Conan-Kudo suggested changes Mar 24, 2017 edited

This could be slightly simplified.

  1. @SNAP_BINARY@ is gratuitous and unnecessary. Currently, it is /usr/bin/snap everywhere. However, if you want to template that, then I would suggest @bindir@/snap instead.

  2. Same goes for @SNAPD_BINARY@, though this change is necessary. I'd suggest @libexecdir@/snapd/snapd instead.

  3. For consistency with the code, I would rename @SNAP_BASEDIR@ to @SNAP_MOUNTDIR@, to correspond to similar references in snap-confine and snapd.

Contributor

zyga commented Mar 25, 2017

I agree with @Conan-Kudo review

Contributor

morphis commented Mar 27, 2017

@Conan-Kudo @zyga Update implementation according to your comments.

Looks good to me! 👍

Looks good, some questions though.

packaging/ubuntu-16.04/rules
@@ -90,6 +90,16 @@ override_dh_auto_build:
cd cmd && ( ./configure --prefix=/usr --libexecdir=/usr/lib/snapd $(VENDOR_ARGS))
$(MAKE) -C cmd all
+ # Generate the real systemd units out of the available templates
+ cat data/systemd/snapd.service.in | \
@mvo5

mvo5 Mar 28, 2017

Collaborator

We might consider putting the sed details into a Makefile in data/systemd - and then call make -C data/systemd SNAPD_ENVIRONMENT_FILE=foo libexecdir=bar SNAP_MOUNTDIR=foobar here. This avoid that we duplicate the sed rules in all the packaging we do.

@morphis

morphis Mar 28, 2017

Contributor

Makes sense. Will add this.

packaging/ubuntu-16.04/rules
+ cat data/systemd/snapd.refresh.service.in | \
+ sed s:@bindir@:/usr/bin:g | \
+ sed s:@SNAP_MOUNTDIR@:/snap:g > data/systemd/snapd.refresh.service
+ cat data/systemd/snapd.autoimport.service.in | \
@mvo5

mvo5 Mar 28, 2017

Collaborator

We also need to add this to the packaging/ubuntu-14.04/ part of the code, no?

@morphis

morphis Mar 28, 2017

Contributor

We don't have to. The packaging/ubtunu-14.04 ships its own version of the systemd units and doesn't install those from data/systemd

Since we're now using a Makefile, there's some small changes I'd like to see here.

data/systemd/Makefile
+BINDIR := /usr/bin
+LIBEXECDIR := /usr/lib
+
+all:
@Conan-Kudo

Conan-Kudo Mar 28, 2017

Contributor

If we're going to use a Makefile, I would rather see it take a DESTDIR parameter and install the generated units to the correct place.

Add an install target, and have it write the real units to SYSTEMDSYSTEMUNITDIR (matching autotools name for this). Since you're doing the Ubuntu thing by default, this would be defined as /lib/systemd/system, whereas on RPM systems, I would pass in %{_unitdir} to ensure it went to the right place.

data/systemd/Makefile
+ sed s:@libexecdir@:${LIBEXECDIR}:g | \
+ sed s:@SNAPD_ENVIRONMENT_FILE@:${SNAPD_ENVIRONMENT_FILE}:g > snapd.service
+ cat snapd.refresh.service.in | \
+ sed s:@bindir@:/usr/bin:g | \
@Conan-Kudo

Conan-Kudo Mar 28, 2017

Contributor

You meant to have it use ${BINDIR} here.

data/systemd/snapd.service.in
-ExecStart=/usr/lib/snapd/snapd
-EnvironmentFile=/etc/environment
+ExecStart=@libexecdir@/snapd/snapd
+EnvironmentFile=@SNAPD_ENVIRONMENT_FILE@
@Conan-Kudo

Conan-Kudo Mar 28, 2017

Contributor

This should probably be made non-mandatory, like we do for the Fedora units.

That is:

EnvironmentFile=-@SNAPD_ENVIRONMENT_FILE@

Simon Fels added some commits Mar 24, 2017

packaging: use templates for relevant systemd units
To make packaging across different distributionis a bit easier we
now use templates for some of our systemd units and replace things
which are in a different location with sed at build time.
data/systemd/Makefile
+ install --mode=0644 snapd.autoimport.service ${DESTDIR}/${SYSTEMDSYSTEMUNITDIR}
+ install --mode=0644 *.socket ${DESTDIR}/${SYSTEMDSYSTEMUNITDIR}
+ install --mode=0644 snapd.service ${DESTDIR}/${SYSTEMDSYSTEMUNITDIR}
+ install --mode=0644 snapd.system-shutdown.service ${DESTDIR}/${SYSTEMDSYSTEMUNITDIR}
@Conan-Kudo

Conan-Kudo Mar 28, 2017

Contributor

This is new to me. This should be templated too, even if it doesn't currently apply to non-snappy systems. You never know who is going to make a snap-based system. :)

.gitignore
+data/systemd/snapd.autoimport.service
+data/systemd/snapd.refresh.service
+data/systemd/snapd.service
+
@Conan-Kudo

Conan-Kudo Mar 29, 2017

Contributor

Add data/systemd/snapd.system-shutdown.service to the .gitignore and I think we're all set.

Looks good to me.

packaging/ubuntu-16.04/rules
- install --mode=0644 data/systemd/*.socket debian/snapd/$(SYSTEMD_UNITS_DESTDIR)
- install --mode=0644 data/systemd/snapd.service debian/snapd/$(SYSTEMD_UNITS_DESTDIR)
- install --mode=0644 data/systemd/snapd.system-shutdown.service debian/snapd/$(SYSTEMD_UNITS_DESTDIR)
+ $(MAKE) -C data/systemd install DESTDIR=$(CURDIR)/debian/snapd/ SYSTEMSYSTEMUNITDIR=$(SYSTEMD_UNITS_DESTDIR)
@mvo5

mvo5 Mar 30, 2017

Collaborator

The SYSTEMSYSTEMUNITDIR appears to be missing a D - which highlights that maybe it should use _ ? To make it easier to read and to be more consistent we could just use the same name as in the rules file: SYSTEMD_UNITS_DESTDIR ? (unless there is a good reason for the different name of course).

@morphis

morphis Mar 30, 2017

Contributor

I am fine with that. @Conan-Kudo requested to use SYSTEMDSYSTEMUNITDIR to match the name autotools is using.

Contributor

morphis commented Mar 31, 2017

@mvo5 @zyga Can you guys have another look at this?

Small comments

data/systemd/Makefile
+LIBEXECDIR := /usr/lib
+SYSTEMDSYSTEMUNITDIR := /lib/systemd/system
+
+all:
@mvo5

mvo5 Apr 3, 2017

Collaborator

I was thinking about if this could be made more make-ish. What do you think about something like the bits below:

SYSTEMD_UNITS := $(patsubst %.service.in,%.service,$(wildcard *.service.in))

%.service: %.service.in
	cat $< | \
		sed s:@libexecdir@:${LIBEXECDIR}:g | \
		sed s:@SNAPD_ENVIRONMENT_FILE@:${SNAPD_ENVIRONMENT_FILE}:g | \
		sed s:@bindir@:${BINDIR}:g | \
		sed s:@SNAP_MOUNTDIR@:${SNAP_MOUNTDIR}:g  | \
	cat > $@


install: $(SYSTEMD_UNITS)

?

@morphis

morphis Apr 3, 2017

Contributor

Fine for me. Let me add that.

data/systemd/Makefile
+ cat snapd.service.in | \
+ sed s:@libexecdir@:${LIBEXECDIR}:g | \
+ sed s:@SNAPD_ENVIRONMENT_FILE@:${SNAPD_ENVIRONMENT_FILE}:g > snapd.service
+ cat snapd.refresh.service.in | \
@mvo5

mvo5 Apr 3, 2017

Collaborator

A bit of extra spaces here, not sure if that is on purpose or an accident.

mvo5 approved these changes Apr 3, 2017

Very nice, thanks for doing this work!

Looks good to me, only one change might be worth doing.

data/systemd/Makefile
+install: $(SYSTEMD_UNITS)
+ install -d ${DESTDIR}/${SYSTEMDSYSTEMUNITDIR}
+ install -m 0644 snapd.refresh.timer ${DESTDIR}/${SYSTEMDSYSTEMUNITDIR}
+ install -m 0644 snapd.refresh.service ${DESTDIR}/${SYSTEMDSYSTEMUNITDIR}
@Conan-Kudo

Conan-Kudo Apr 3, 2017

Contributor

You could probably simplify this further with wildcards, so that we don't need to know the exact names of all the services, since you've done the same for generating them.

@morphis

morphis Apr 4, 2017

Contributor

Done

zyga approved these changes Apr 4, 2017

Some comments, feel free to land if addressed

data/systemd/Makefile
+
+install: $(SYSTEMD_UNITS)
+ install -d ${DESTDIR}/${SYSTEMDSYSTEMUNITDIR}
+ for u in ${SYSTEMD_UNITS} ; do \
@zyga

zyga Apr 4, 2017

Contributor

How about a one-liner:

install: $(SYSTEMD_UNITS)
    $(foreach u,$^,install -D -m 0644 ${u} ${DESTDIR}/${SYSTEMDSYSTEMUNITDIR}/${u};)
@mvo5

mvo5 Apr 4, 2017

Collaborator

or maybe just make install install it all in one go?

install: $(SYSTEMD_UNTIS)
  install -m 0644 -D -t ${DESTDIR}/${SYSTEMDSYSTEMUNITDIR} ${SYSTEMD_UNTIS}
data/systemd/Makefile
+ done
+
+clean:
+ for u in ${SYSTEMD_UNITS_GENERATED} ; do \
@zyga

zyga Apr 4, 2017

Contributor

Ditto:

clean:
    rm -f ${SYSTEMD_UNITS_GENERATED}
data/systemd/snapd.refresh.service.in
@@ -2,10 +2,10 @@
Description=Automatically refresh installed snaps
After=network-online.target snapd.socket
Requires=snapd.socket
-ConditionPathExistsGlob=/snap/*/current
+ConditionPathExistsGlob=@SNAP_MOUNTDIR@/*/current
@zyga

zyga Apr 4, 2017

Contributor

snap-confine's build system calls this SNAP_MOUNT_DIR

@mvo5 mvo5 added this to the 2.24 milestone Apr 4, 2017

zyga and others added some commits Apr 4, 2017

+all: ${SYSTEMD_UNITS}
+
+install: $(SYSTEMD_UNITS)
+ $(foreach u,$^,install -D -m 0644 ${u} ${DESTDIR}/${SYSTEMDSYSTEMUNITDIR}/${u};)
@mvo5

mvo5 Apr 4, 2017

Collaborator

I slightly prefer install -D -m 0644 -t ${DESTDIR}/${SYSTEMDSYSTEMUNITDIR} ${SYSTEMD_UNITS} (not tested but should work) - feels less arcane to me. But I will not sweat over it :)

Just a small tweak, if you want. :)

.gitignore
@@ -30,6 +30,12 @@ cmd/system-shutdown/unit-tests
# manual pages
cmd/*/*.[1-9]
+# auto-generated systemd units
+data/systemd/snapd.autoimport.service
@Conan-Kudo

Conan-Kudo Apr 4, 2017

Contributor

You could change this to be data/systemd/*.service now, so that you don't have to keep updating this..

Looks excellent to me.

Contributor

niemeyer commented Apr 5, 2017

Super nice collaboration here, thanks all!

I stepped by just for the wine 🥂.

@mvo5 mvo5 merged commit 3de3b56 into snapcore:master Apr 5, 2017

6 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
xenial-amd64 autopkgtest finished (success)
Details
xenial-i386 autopkgtest finished (success)
Details
xenial-ppc64el autopkgtest finished (success)
Details
yakkety-amd64 autopkgtest finished (success)
Details
zesty-amd64 autopkgtest finished (success)
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment