mailarchive of the ptxdist mailing list
 help / color / mirror / Atom feed
From: Ladislav Michl <ladis@linux-mips.org>
To: ptxdist@pengutronix.de
Subject: [ptxdist] [PATCH v2] gpsd: Optionally install systemd unit files
Date: Sat, 25 Jan 2020 17:19:08 +0100	[thread overview]
Message-ID: <20200125161908.GA3281@lenoch> (raw)

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

                 reply	other threads:[~2020-01-25 16:19 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200125161908.GA3281@lenoch \
    --to=ladis@linux-mips.org \
    --cc=ptxdist@pengutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox