Skip to content

Commit 021e0ef

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 8b0c235 commit 021e0ef

3 files changed

Lines changed: 41 additions & 3 deletions

File tree

Makefile.am

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,23 +28,33 @@ etc/openfortivpn/config: $(srcdir)/etc/openfortivpn/config.template
2828
@$(MKDIR_P) etc/openfortivpn
2929
$(AM_V_GEN)$(SED) -e '3,$$ s/^/# /' $(srcdir)/etc/openfortivpn/config.template >$@
3030

31-
install-data-hook: etc/openfortivpn/config
31+
lib/systemd/system/openfortivpn@.service: $(srcdir)/lib/systemd/system/openfortivpn@.service.in
32+
$(MKDIR_P) lib/systemd/system
33+
$(SED) -e 's|[@]SYSCONFDIR[@]|$(sysconfdir)|g' $(srcdir)/lib/systemd/system/openfortivpn@.service.in >$@
34+
35+
install-data-hook: etc/openfortivpn/config lib/systemd/system/openfortivpn@.service
3236
if ! test -f $(DESTDIR)$(confdir)/config ; then \
3337
$(MKDIR_P) $(DESTDIR)$(confdir) ; \
3438
$(INSTALL) -m 600 etc/openfortivpn/config \
3539
$(DESTDIR)$(confdir)/config ; \
3640
fi
41+
if HAVE_SYSTEMD
42+
$(MKDIR_P) $(systemdsystemunitdir)
43+
$(INSTALL) lib/systemd/system/openfortivpn@.service \
44+
$(systemdsystemunitdir)
45+
endif
3746

3847
dist_man_MANS = doc/openfortivpn.1
3948

4049
doc/openfortivpn.1: $(srcdir)/doc/openfortivpn.1.in
4150
@$(MKDIR_P) doc
4251
$(AM_V_GEN)$(SED) -e 's|[@]SYSCONFDIR[@]|$(sysconfdir)|g;s|[@]DATADIR[@]|$(datadir)|g' $(srcdir)/doc/openfortivpn.1.in >$@
4352

44-
all-local: etc/openfortivpn/config
53+
all-local: etc/openfortivpn/config lib/systemd/system/openfortivpn@.service
4554

4655
clean-local:
4756
-rm -f etc/openfortivpn/config
57+
-rm -f lib/systemd/system/openfortivpn@.service
4858
-rm -f doc/openfortivpn.1
4959

50-
EXTRA_DIST = autogen.sh CHANGELOG.md LICENSE LICENSE.OpenSSL README.md doc/openfortivpn.1.in $(data_DATA)
60+
EXTRA_DIST = autogen.sh CHANGELOG.md LICENSE LICENSE.OpenSSL README.md doc/openfortivpn.1.in $(data_DATA) lib/systemd/system/openfortivpn@.service

configure.ac

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,5 +452,21 @@ 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+
455471
AC_CONFIG_COMMANDS([timestamp], [touch src/.dirstamp])
456472
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=/usr/bin/openfortivpn -c @SYSCONFDIR@/openfortivpn/%I.conf
9+
OOMScoreAdjust=-100
10+
11+
[Install]
12+
WantedBy=multi-user.target

0 commit comments

Comments
 (0)