Join GitHub today
GitHub is home to over 20 million developers working together to host and review code, manage projects, and build software together.
packaging: use templates for relevant systemd units #3084
Conversation
Conan-Kudo
suggested changes
Mar 24, 2017
•
This could be slightly simplified.
-
@SNAP_BINARY@is gratuitous and unnecessary. Currently, it is/usr/bin/snapeverywhere. However, if you want to template that, then I would suggest@bindir@/snapinstead. -
Same goes for
@SNAPD_BINARY@, though this change is necessary. I'd suggest@libexecdir@/snapd/snapdinstead. -
For consistency with the code, I would rename
@SNAP_BASEDIR@to@SNAP_MOUNTDIR@, to correspond to similar references in snap-confine and snapd.
|
I agree with @Conan-Kudo review |
|
@Conan-Kudo @zyga Update implementation according to your comments. |
| @@ -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
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.
| + 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
Mar 28, 2017
Collaborator
We also need to add this to the packaging/ubuntu-14.04/ part of the code, no?
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
Conan-Kudo
suggested changes
Mar 28, 2017
Since we're now using a Makefile, there's some small changes I'd like to see here.
| +BINDIR := /usr/bin | ||
| +LIBEXECDIR := /usr/lib | ||
| + | ||
| +all: |
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.
| + 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 | \ |
| -ExecStart=/usr/lib/snapd/snapd | ||
| -EnvironmentFile=/etc/environment | ||
| +ExecStart=@libexecdir@/snapd/snapd | ||
| +EnvironmentFile=@SNAPD_ENVIRONMENT_FILE@ |
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@
added some commits
Mar 24, 2017
| + 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
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. :)
| +data/systemd/snapd.autoimport.service | ||
| +data/systemd/snapd.refresh.service | ||
| +data/systemd/snapd.service | ||
| + |
Conan-Kudo
Mar 29, 2017
Contributor
Add data/systemd/snapd.system-shutdown.service to the .gitignore and I think we're all set.
| - 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
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
Mar 30, 2017
Contributor
I am fine with that. @Conan-Kudo requested to use SYSTEMDSYSTEMUNITDIR to match the name autotools is using.
| +LIBEXECDIR := /usr/lib | ||
| +SYSTEMDSYSTEMUNITDIR := /lib/systemd/system | ||
| + | ||
| +all: |
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)
?
| + 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
Apr 3, 2017
Collaborator
A bit of extra spaces here, not sure if that is on purpose or an accident.
Conan-Kudo
approved these changes
Apr 3, 2017
Looks good to me, only one change might be worth doing.
| +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
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.
| + | ||
| +install: $(SYSTEMD_UNITS) | ||
| + install -d ${DESTDIR}/${SYSTEMDSYSTEMUNITDIR} | ||
| + for u in ${SYSTEMD_UNITS} ; do \ |
zyga
Apr 4, 2017
Contributor
How about a one-liner:
install: $(SYSTEMD_UNITS)
$(foreach u,$^,install -D -m 0644 ${u} ${DESTDIR}/${SYSTEMDSYSTEMUNITDIR}/${u};)
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}
| + done | ||
| + | ||
| +clean: | ||
| + for u in ${SYSTEMD_UNITS_GENERATED} ; do \ |
| @@ -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 |
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
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 :)
| @@ -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
Apr 4, 2017
Contributor
You could change this to be data/systemd/*.service now, so that you don't have to keep updating this..
|
Super nice collaboration here, thanks all! I stepped by just for the wine |
morphis commentedMar 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.