mailarchive of the ptxdist mailing list
 help / color / mirror / Atom feed
* [ptxdist] [PATCH v2] gpsd: Optionally install systemd unit files
@ 2020-01-25 16:19 Ladislav Michl
  0 siblings, 0 replies; only message in thread
From: Ladislav Michl @ 2020-01-25 16:19 UTC (permalink / raw)
  To: ptxdist

Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
---
 Changes:
 -v2: provide default service files in projectroot

 Note, udev rules and sysv init script are left as an excercise
 for respective users (I do not have hardware to test with) :)
 Also eventual chrony dependency is ommited.

 projectroot/usr/lib/systemd/system/gpsd.service   | 11 +++++++++++
 projectroot/usr/lib/systemd/system/gpsd.socket    | 15 +++++++++++++++
 .../usr/lib/systemd/system/gpsdctl@.service       | 12 ++++++++++++
 rules/gpsd.in                                     | 11 +++++++++++
 rules/gpsd.make                                   | 15 +++++++++++++++
 5 files changed, 64 insertions(+)
 create mode 100644 projectroot/usr/lib/systemd/system/gpsd.service
 create mode 100644 projectroot/usr/lib/systemd/system/gpsd.socket
 create mode 100644 projectroot/usr/lib/systemd/system/gpsdctl@.service

diff --git a/projectroot/usr/lib/systemd/system/gpsd.service b/projectroot/usr/lib/systemd/system/gpsd.service
new file mode 100644
index 000000000..53c0b96bb
--- /dev/null
+++ b/projectroot/usr/lib/systemd/system/gpsd.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=GPS (Global Positioning System) Daemon
+Requires=gpsd.socket
+
+[Service]
+Type=forking
+ExecStart=/usr/sbin/gpsd @ARGS@
+
+[Install]
+WantedBy=multi-user.target
+Also=gpsd.socket
diff --git a/projectroot/usr/lib/systemd/system/gpsd.socket b/projectroot/usr/lib/systemd/system/gpsd.socket
new file mode 100644
index 000000000..bc7682116
--- /dev/null
+++ b/projectroot/usr/lib/systemd/system/gpsd.socket
@@ -0,0 +1,15 @@
+[Unit]
+Description=GPS (Global Positioning System) Daemon Sockets
+
+[Socket]
+ListenStream=/var/run/gpsd.sock
+ListenStream=[::1]:2947
+ListenStream=127.0.0.1:2947
+# To allow gpsd remote access, start gpsd with the -G option and
+# uncomment the next two lines:
+# ListenStream=[::1]:2947
+# ListenStream=0.0.0.0:2947
+SocketMode=0600
+
+[Install]
+WantedBy=sockets.target
diff --git a/projectroot/usr/lib/systemd/system/gpsdctl@.service b/projectroot/usr/lib/systemd/system/gpsdctl@.service
new file mode 100644
index 000000000..24d291408
--- /dev/null
+++ b/projectroot/usr/lib/systemd/system/gpsdctl@.service
@@ -0,0 +1,12 @@
+[Unit]
+Description=Manage %I for GPS daemon
+Requires=gpsd.socket
+BindsTo=dev-%i.device
+After=dev-%i.device
+
+[Service]
+Type=oneshot
+Environment="GPSD_SOCKET=/var/run/gpsd.sock"
+RemainAfterExit=yes
+ExecStart=/usr/bin/gpsdctl add /dev/%I
+ExecStop=/usr/bin/gpsdctl remove /dev/%I
diff --git a/rules/gpsd.in b/rules/gpsd.in
index ba0edb7bc..e1c4442d6 100644
--- a/rules/gpsd.in
+++ b/rules/gpsd.in
@@ -256,6 +256,17 @@ menu "install options"
 		  queries with a format that is substantially easier to
 		  parse than the NMEA 0183 emitted by most GPS receivers.
 
+	config GPSD_SYSTEMD_UNIT
+		bool
+		default y
+		depends on INITMETHOD_SYSTEMD && GPSD_GPSD
+		prompt "systemd unit files for gpsd"
+
+	config GPSD_GPSD_ARGS
+		string
+		depends on GPSD_SYSTEMD_UNIT
+		prompt "gpsd arguments"
+
 	config GPSD_GPS2UDP
 		bool
 		prompt "gps2udp"
diff --git a/rules/gpsd.make b/rules/gpsd.make
index ac95b0af6..e1242eeb7 100644
--- a/rules/gpsd.make
+++ b/rules/gpsd.make
@@ -162,6 +162,21 @@ $(STATEDIR)/gpsd.targetinstall:
 ifdef PTXCONF_GPSD_GPSD
 	@$(call install_copy, gpsd, 0, 0, 0755, -, /usr/sbin/gpsd)
 endif
+ifdef PTXCONF_GPSD_SYSTEMD_UNIT
+	@$(call install_alternative, gpsd, 0, 0, 644, \
+		/usr/lib/systemd/system/gpsd.service)
+	@$(call install_replace, gpsd, \
+		/usr/lib/systemd/system/gpsd.service, \
+		@ARGS@, $(PTXCONF_GPSD_GPSD_ARGS))
+	@$(call install_link, gpsd, ../gpsd.service, \
+		/usr/lib/systemd/system/multi-user.target.wants/gpsd.service)
+	@$(call install_alternative, gpsd, 0, 0, 644, \
+		/usr/lib/systemd/system/gpsd.socket)
+ifdef PTXCONF_GPSD_GPSCTL
+	@$(call install_alternative, gpsd, 0, 0, 644, \
+		/usr/lib/systemd/system/gpsdctl@.service)
+endif
+endif
 ifdef PTXCONF_GPSD_PYTHON
 	@$(call install_glob, gpsd, 0, 0, -, \
 		/usr/lib/python$(PYTHON3_MAJORMINOR), *.so *.py)
-- 
2.25.0


_______________________________________________
ptxdist mailing list
ptxdist@pengutronix.de

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-01-25 16:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-25 16:19 [ptxdist] [PATCH v2] gpsd: Optionally install systemd unit files Ladislav Michl

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox