Jacob Keller
2013-07-12 23:50:39 UTC
This patch adds a systemd service unit for ptp4l. Currently does not allow
systemd to create any sockets, as this becomes really tricky since there are so
many types of configuration. The initial systemd service will be kept very
simple.
The actual service file is generated in order to include the prefix variables
from the makefile to get included in the systemd service file.
Signed-off-by: Jacob Keller <***@intel.com>
---
makefile | 14 ++++++++++++--
ptp4l.8 | 7 +++++++
ptp4l.service.in | 12 ++++++++++++
3 files changed, 31 insertions(+), 2 deletions(-)
create mode 100644 ptp4l.service.in
diff --git a/makefile b/makefile
index 71dcf0c..96cb0b7 100644
--- a/makefile
+++ b/makefile
@@ -28,6 +28,7 @@ INC = -I$(KBUILD_OUTPUT)/usr/include
VER = -DVER=$(version)
CFLAGS = -Wall $(VER) $(INC) $(DEBUG) $(FEAT_CFLAGS) $(EXTRA_CFLAGS)
LDLIBS = -lm -lrt $(EXTRA_LDFLAGS)
+SRV = ptp4l.service
PRG = ptp4l pmc phc2sys hwstamp_ctl
OBJ = bmc.o clock.o clockadj.o config.o fault.o fsm.o ptp4l.o mave.o \
msg.o phc.o pi.o port.o print.o raw.o servo.o sk.o stats.o tlv.o tmtab.o \
@@ -43,9 +44,16 @@ VPATH = $(srcdir)
prefix = /usr/local
sbindir = $(prefix)/sbin
mandir = $(prefix)/man
+etcdir = $(prefix)/etc
man8dir = $(mandir)/man8
+srvdir = /lib/systemd/system/
-all: $(PRG)
+all: $(PRG) $(SRV)
+
+ptp4l.service: ptp4l.service.in
+ cat $(<) | sed \
+ -e 's_@@sbindir@@_$(sbindir)_g' \
+ -e 's_@@etcdir@@_$(etcdir)_g' >$(@)
ptp4l: $(OBJ)
@@ -70,10 +78,12 @@ force:
install: $(PRG)
mkdir -p $(sbindir) $(man8dir)
install $(PRG) $(sbindir)
+ install -p -m 644 $(SRV) $(srvdir)
install -p -m 644 -t $(man8dir) $(PRG:%=%.8)
+ cp default.cfg $(etcdir)/ptp4l.cfg
clean:
- rm -f $(OBJECTS) $(DEPEND)
+ rm -f $(OBJECTS) $(DEPEND) $(SRV)
distclean: clean
rm -f $(PRG)
diff --git a/ptp4l.8 b/ptp4l.8
index 6f42c1c..2f14b5a 100644
--- a/ptp4l.8
+++ b/ptp4l.8
@@ -395,6 +395,13 @@ of local clock in use. The value is purely informational, having no
effect on the outcome of the Best Master Clock algorithm, and is
advertised when the clock becomes grand master.
+.SH SYSTEMD SERVICE FILE
+
+.B ptp4l.service
+is a systemd service file for use with the systemd init system. This service
+file can be used with systemd and its utilities to manage the ptp4l daemon
+process.
+
.SH TIME SCALE USAGE
.B ptp4l
diff --git a/ptp4l.service.in b/ptp4l.service.in
new file mode 100644
index 0000000..53aed3b
--- /dev/null
+++ b/ptp4l.service.in
@@ -0,0 +1,12 @@
+[Unit]
+Description=LinuxPTP daemon for the IEEE 1588 Time Sync protocol
+After=network.target
+
+[Service]
+# Note that YOU will have to modify ptp4l.cfg to suit your needs. The default
+# configuration will not even start correctly, because it does not specify an
+# interface.
+ExecStart=@@sbindir@@/ptp4l -f @@etcdir@@/ptp4l.cfg -m
+
+[Install]
+WantedBy=multi-user.target
systemd to create any sockets, as this becomes really tricky since there are so
many types of configuration. The initial systemd service will be kept very
simple.
The actual service file is generated in order to include the prefix variables
from the makefile to get included in the systemd service file.
Signed-off-by: Jacob Keller <***@intel.com>
---
makefile | 14 ++++++++++++--
ptp4l.8 | 7 +++++++
ptp4l.service.in | 12 ++++++++++++
3 files changed, 31 insertions(+), 2 deletions(-)
create mode 100644 ptp4l.service.in
diff --git a/makefile b/makefile
index 71dcf0c..96cb0b7 100644
--- a/makefile
+++ b/makefile
@@ -28,6 +28,7 @@ INC = -I$(KBUILD_OUTPUT)/usr/include
VER = -DVER=$(version)
CFLAGS = -Wall $(VER) $(INC) $(DEBUG) $(FEAT_CFLAGS) $(EXTRA_CFLAGS)
LDLIBS = -lm -lrt $(EXTRA_LDFLAGS)
+SRV = ptp4l.service
PRG = ptp4l pmc phc2sys hwstamp_ctl
OBJ = bmc.o clock.o clockadj.o config.o fault.o fsm.o ptp4l.o mave.o \
msg.o phc.o pi.o port.o print.o raw.o servo.o sk.o stats.o tlv.o tmtab.o \
@@ -43,9 +44,16 @@ VPATH = $(srcdir)
prefix = /usr/local
sbindir = $(prefix)/sbin
mandir = $(prefix)/man
+etcdir = $(prefix)/etc
man8dir = $(mandir)/man8
+srvdir = /lib/systemd/system/
-all: $(PRG)
+all: $(PRG) $(SRV)
+
+ptp4l.service: ptp4l.service.in
+ cat $(<) | sed \
+ -e 's_@@sbindir@@_$(sbindir)_g' \
+ -e 's_@@etcdir@@_$(etcdir)_g' >$(@)
ptp4l: $(OBJ)
@@ -70,10 +78,12 @@ force:
install: $(PRG)
mkdir -p $(sbindir) $(man8dir)
install $(PRG) $(sbindir)
+ install -p -m 644 $(SRV) $(srvdir)
install -p -m 644 -t $(man8dir) $(PRG:%=%.8)
+ cp default.cfg $(etcdir)/ptp4l.cfg
clean:
- rm -f $(OBJECTS) $(DEPEND)
+ rm -f $(OBJECTS) $(DEPEND) $(SRV)
distclean: clean
rm -f $(PRG)
diff --git a/ptp4l.8 b/ptp4l.8
index 6f42c1c..2f14b5a 100644
--- a/ptp4l.8
+++ b/ptp4l.8
@@ -395,6 +395,13 @@ of local clock in use. The value is purely informational, having no
effect on the outcome of the Best Master Clock algorithm, and is
advertised when the clock becomes grand master.
+.SH SYSTEMD SERVICE FILE
+
+.B ptp4l.service
+is a systemd service file for use with the systemd init system. This service
+file can be used with systemd and its utilities to manage the ptp4l daemon
+process.
+
.SH TIME SCALE USAGE
.B ptp4l
diff --git a/ptp4l.service.in b/ptp4l.service.in
new file mode 100644
index 0000000..53aed3b
--- /dev/null
+++ b/ptp4l.service.in
@@ -0,0 +1,12 @@
+[Unit]
+Description=LinuxPTP daemon for the IEEE 1588 Time Sync protocol
+After=network.target
+
+[Service]
+# Note that YOU will have to modify ptp4l.cfg to suit your needs. The default
+# configuration will not even start correctly, because it does not specify an
+# interface.
+ExecStart=@@sbindir@@/ptp4l -f @@etcdir@@/ptp4l.cfg -m
+
+[Install]
+WantedBy=multi-user.target