summaryrefslogtreecommitdiff
diff options
authorJames Henstridge <james@jamesh.id.au>2019-05-27 11:39:53 +0800
committerJames Henstridge <james@jamesh.id.au>2019-06-25 17:29:25 +0800
commit1c767b829078a76eb157592e777bf50cc198bdb9 (patch)
tree0b2cba30f29f4bbcf31f8f51e7d612957abfad63
parent652a0a51e329f40d041a2a691e77ef1a62c7b564 (diff)
data: run snap session-agent as a systemd user session service.
Also add a unix socket for socket activation.
-rw-r--r--data/Makefile1
-rw-r--r--data/systemd-user/Makefile44
-rw-r--r--data/systemd-user/snapd.session-agent.service.in7
-rw-r--r--data/systemd-user/snapd.session-agent.socket8
4 files changed, 60 insertions, 0 deletions
diff --git a/data/Makefile b/data/Makefile
index 98467126fa..df23561cf8 100644
--- a/data/Makefile
+++ b/data/Makefile
@@ -1,5 +1,6 @@
all install clean:
$(MAKE) -C systemd $@
+ $(MAKE) -C systemd-user $@
$(MAKE) -C systemd-env $@
$(MAKE) -C dbus $@
$(MAKE) -C env $@
diff --git a/data/systemd-user/Makefile b/data/systemd-user/Makefile
new file mode 100644
index 0000000000..455dd7822c
--- /dev/null
+++ b/data/systemd-user/Makefile
@@ -0,0 +1,44 @@
+#
+# Copyright (C) 2019 Canonical Ltd
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 3 as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+SNAPD_ENVIRONMENT_FILE := /etc/environment
+BINDIR := /usr/bin
+SYSTEMDUSERUNITDIR := /usr/lib/systemd/user
+
+SYSTEMD_UNITS_GENERATED := $(wildcard *.in)
+# NOTE: sort removes duplicates so this gives us all the units, generated or otherwise
+SYSTEMD_UNITS = $(sort $(SYSTEMD_UNITS_GENERATED:.in=) $(wildcard *.service) $(wildcard *.timer) $(wildcard *.socket))
+
+.PHONY: all
+all: $(SYSTEMD_UNITS)
+
+.PHONY: install
+install:: $(SYSTEMD_UNITS)
+ # NOTE: old (e.g. 14.04) GNU coreutils doesn't -D with -t
+ install -d -m 0755 $(DESTDIR)/$(SYSTEMDUSERUNITDIR)
+ install -m 0644 -t $(DESTDIR)/$(SYSTEMDUSERUNITDIR) $^
+
+install::
+ install -d -m 0755 $(DESTDIR)/$(SYSTEMDUSERUNITDIR)/sockets.target.wants
+ ln -sf ../snapd.session-agent.socket $(DESTDIR)/$(SYSTEMDUSERUNITDIR)/sockets.target.wants/snapd.session-agent.socket
+
+.PHONY: clean
+clean:
+ rm -f $(SYSTEMD_UNITS_GENERATED:.in=)
+
+%: %.in
+ cat $< | \
+ sed s:@bindir@:$(BINDIR):g | \
+ cat > $@
diff --git a/data/systemd-user/snapd.session-agent.service.in b/data/systemd-user/snapd.session-agent.service.in
new file mode 100644
index 0000000000..4d1decad35
--- /dev/null
+++ b/data/systemd-user/snapd.session-agent.service.in
@@ -0,0 +1,7 @@
+[Unit]
+Description=Snapd's user session agent
+Requires=snapd.session-agent.socket
+
+[Service]
+Type=notify
+ExecStart=@bindir@/snap session-agent
diff --git a/data/systemd-user/snapd.session-agent.socket b/data/systemd-user/snapd.session-agent.socket
new file mode 100644
index 0000000000..51f91335a5
--- /dev/null
+++ b/data/systemd-user/snapd.session-agent.socket
@@ -0,0 +1,8 @@
+[Unit]
+Description=REST API socket for Snapd's user session agent
+
+[Socket]
+ListenStream=%t/snap-session.socket
+
+[Install]
+WantedBy=sockets.target