Skip to content

Commit 8ea4d6c

Browse files
Add systemd service file
Allows openfortivpn to act as system service. The configuration is expected under $(sysconfdir)/openfortivpn/<NAME>.conf. https://www.freedesktop.org/software/systemd/man/daemon.html#Installing%20systemd%20Service%20Files
1 parent a171722 commit 8ea4d6c

4 files changed

Lines changed: 81 additions & 8 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ openfortivpn
1717
doc/*.1
1818
config.sub
1919
config.guess
20+
openfortivpn@.service

Makefile.am

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,33 +18,76 @@ openfortivpn_CPPFLAGS = -DSYSCONFDIR=\"$(sysconfdir)\" \
1818
openfortivpn_CPPFLAGS += $(OPENSSL_CFLAGS) $(LIBSYSTEMD_CFLAGS)
1919
openfortivpn_LDADD = $(OPENSSL_LIBS) $(LIBSYSTEMD_LIBS)
2020

21-
DISTCHECK_CONFIGURE_FLAGS = CFLAGS=-Werror
21+
PATHFILES =
22+
CLEAN_LOCALS =
23+
EXTRA_DIST = \
24+
autogen.sh \
25+
CHANGELOG.md \
26+
LICENSE \
27+
LICENSE.OpenSSL \
28+
README.md
2229

23-
confdir=$(sysconfdir)/@PACKAGE@
30+
DISTCHECK_CONFIGURE_FLAGS = \
31+
CFLAGS=-Werror \
32+
--with-systemdsystemunitdir=$$dc_install_base/$(systemdsystemunitdir)
33+
34+
# configuration file template
2435
datadir=$(prefix)/share/@PACKAGE@
2536
data_DATA=etc/openfortivpn/config.template
2637

38+
EXTRA_DIST += $(data_DATA)
39+
40+
# initial configuration file
41+
confdir=$(sysconfdir)/@PACKAGE@
42+
2743
etc/openfortivpn/config: $(srcdir)/etc/openfortivpn/config.template
2844
@$(MKDIR_P) etc/openfortivpn
2945
$(AM_V_GEN)$(SED) -e '/^#/n;/^\s*$$/n;s/^/# /' $(srcdir)/etc/openfortivpn/config.template >$@
3046

31-
install-data-hook: etc/openfortivpn/config
47+
install-data-hook: etc/openfortivpn/config lib/systemd/system/openfortivpn@.service
3248
if ! test -f $(DESTDIR)$(confdir)/config ; then \
3349
$(MKDIR_P) $(DESTDIR)$(confdir) ; \
3450
$(INSTALL) -m 600 etc/openfortivpn/config \
3551
$(DESTDIR)$(confdir)/config ; \
3652
fi
3753

54+
clean-local-config:
55+
-rm -f $(top_builddir)/etc/openfortivpn/config
56+
57+
CLEAN_LOCALS += clean-local-config
58+
59+
# systemd service file
60+
PATHFILES += lib/systemd/system/openfortivpn@.service
61+
62+
if HAVE_SYSTEMD
63+
lib/systemd/system/openfortivpn@.service: $(srcdir)/lib/systemd/system/openfortivpn@.service.in
64+
@$(MKDIR_P) lib/systemd/system
65+
$(AM_V_GEN)$(SED) -e 's|[@]BINDIR[@]|$(bindir)|g;s|[@]SYSCONFDIR[@]|$(sysconfdir)|g' $(srcdir)/lib/systemd/system/openfortivpn@.service.in >$@
66+
67+
systemdsystemunit_DATA = lib/systemd/system/openfortivpn@.service
68+
69+
clean-local-systemd:
70+
-rm -f $(top_builddir)/lib/systemd/system/openfortivpn@.service
71+
72+
CLEAN_LOCALS += clean-local-systemd
73+
endif
74+
75+
# man page
76+
PATHFILES += doc/openfortivpn.1
3877
dist_man_MANS = doc/openfortivpn.1
3978

4079
doc/openfortivpn.1: $(srcdir)/doc/openfortivpn.1.in
4180
@$(MKDIR_P) doc
4281
$(AM_V_GEN)$(SED) -e 's|[@]SYSCONFDIR[@]|$(sysconfdir)|g;s|[@]DATADIR[@]|$(datadir)|g' $(srcdir)/doc/openfortivpn.1.in >$@
4382

44-
all-local: etc/openfortivpn/config
83+
clean-local-man:
84+
-rm -f $(top_builddir)/doc/openfortivpn.1
4585

46-
clean-local:
47-
-rm -f etc/openfortivpn/config
48-
-rm -f doc/openfortivpn.1
86+
CLEAN_LOCALS += clean-local-man
87+
88+
89+
EXTRA_DIST += $(PATHFILES:=.in)
90+
91+
all-local: etc/openfortivpn/config
4992

50-
EXTRA_DIST = autogen.sh CHANGELOG.md LICENSE LICENSE.OpenSSL README.md doc/openfortivpn.1.in $(data_DATA)
93+
clean-local: $(CLEAN_LOCALS)

configure.ac

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,5 +452,22 @@ AS_IF([test "x$enable_resolvconf" = "xyes"], [
452452
AC_MSG_NOTICE([USE_RESOLVCONF... 0])
453453
])
454454

455+
# install systemd service file
456+
AC_ARG_WITH([systemdsystemunitdir],
457+
[AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files])],,
458+
[with_systemdsystemunitdir=auto])
459+
AS_IF([test "x$with_systemdsystemunitdir" = "xyes" -o "x$with_systemdsystemunitdir" = "xauto"], [
460+
def_systemdsystemunitdir=$($PKG_CONFIG --variable=systemdsystemunitdir systemd)
461+
462+
AS_IF([test "x$def_systemdsystemunitdir" = "x"],
463+
[AS_IF([test "x$with_systemdsystemunitdir" = "xyes"],
464+
[AC_MSG_ERROR([systemd support requested but pkg-config unable to query systemd package])])
465+
with_systemdsystemunitdir=no],
466+
[with_systemdsystemunitdir="$def_systemdsystemunitdir"])])
467+
AS_IF([test "x$with_systemdsystemunitdir" != "xno"],
468+
[AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])])
469+
AM_CONDITIONAL([HAVE_SYSTEMD], [test "x$with_systemdsystemunitdir" != "xno"])
470+
471+
455472
AC_CONFIG_COMMANDS([timestamp], [touch src/.dirstamp])
456473
AC_OUTPUT(Makefile)
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[Unit]
2+
Description=OpenFortiVPN for %I
3+
After=network-online.target
4+
5+
[Service]
6+
Type=simple
7+
PrivateTmp=true
8+
ExecStart=@BINDIR@/openfortivpn -c @SYSCONFDIR@/openfortivpn/%I.conf
9+
OOMScoreAdjust=-100
10+
11+
[Install]
12+
WantedBy=multi-user.target

0 commit comments

Comments
 (0)