Skip to content

Commit

Permalink
Add systemd service file
Browse files Browse the repository at this point in the history
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
  • Loading branch information
DimitriPapadopoulos committed Apr 10, 2020
1 parent 8b0c235 commit 021e0ef
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 3 deletions.
16 changes: 13 additions & 3 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,33 @@ etc/openfortivpn/config: $(srcdir)/etc/openfortivpn/config.template
@$(MKDIR_P) etc/openfortivpn
$(AM_V_GEN)$(SED) -e '3,$$ s/^/# /' $(srcdir)/etc/openfortivpn/config.template >$@

install-data-hook: etc/openfortivpn/config
lib/systemd/system/openfortivpn@.service: $(srcdir)/lib/systemd/system/openfortivpn@.service.in
$(MKDIR_P) lib/systemd/system
$(SED) -e 's|[@]SYSCONFDIR[@]|$(sysconfdir)|g' $(srcdir)/lib/systemd/system/openfortivpn@.service.in >$@

install-data-hook: etc/openfortivpn/config lib/systemd/system/openfortivpn@.service
if ! test -f $(DESTDIR)$(confdir)/config ; then \
$(MKDIR_P) $(DESTDIR)$(confdir) ; \
$(INSTALL) -m 600 etc/openfortivpn/config \
$(DESTDIR)$(confdir)/config ; \
fi
if HAVE_SYSTEMD
$(MKDIR_P) $(systemdsystemunitdir)
$(INSTALL) lib/systemd/system/openfortivpn@.service \
$(systemdsystemunitdir)
endif

dist_man_MANS = doc/openfortivpn.1

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

all-local: etc/openfortivpn/config
all-local: etc/openfortivpn/config lib/systemd/system/openfortivpn@.service

clean-local:
-rm -f etc/openfortivpn/config
-rm -f lib/systemd/system/openfortivpn@.service
-rm -f doc/openfortivpn.1

EXTRA_DIST = autogen.sh CHANGELOG.md LICENSE LICENSE.OpenSSL README.md doc/openfortivpn.1.in $(data_DATA)
EXTRA_DIST = autogen.sh CHANGELOG.md LICENSE LICENSE.OpenSSL README.md doc/openfortivpn.1.in $(data_DATA) lib/systemd/system/openfortivpn@.service
16 changes: 16 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -452,5 +452,21 @@ AS_IF([test "x$enable_resolvconf" = "xyes"], [
AC_MSG_NOTICE([USE_RESOLVCONF... 0])
])

# install systemd service file
AC_ARG_WITH([systemdsystemunitdir],
[AS_HELP_STRING([--with-systemdsystemunitdir=DIR], [Directory for systemd service files])],,
[with_systemdsystemunitdir=auto])
AS_IF([test "x$with_systemdsystemunitdir" = "xyes" -o "x$with_systemdsystemunitdir" = "xauto"], [
def_systemdsystemunitdir=$($PKG_CONFIG --variable=systemdsystemunitdir systemd)
AS_IF([test "x$def_systemdsystemunitdir" = "x"],
AS_IF([test "x$with_systemdsystemunitdir" = "xyes"],
[AC_MSG_ERROR([systemd support requested but pkg-config unable to query systemd package])])
with_systemdsystemunitdir=no],
[with_systemdsystemunitdir="$def_systemdsystemunitdir"])])
AS_IF([test "x$with_systemdsystemunitdir" != "xno"],
[AC_SUBST([systemdsystemunitdir], [$with_systemdsystemunitdir])])
AM_CONDITIONAL([HAVE_SYSTEMD], [test "x$with_systemdsystemunitdir" != "xno"])

AC_CONFIG_COMMANDS([timestamp], [touch src/.dirstamp])
AC_OUTPUT(Makefile)
12 changes: 12 additions & 0 deletions lib/systemd/system/openfortivpn@.service.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[Unit]
Description=OpenFortiVPN for %I
After=network-online.target

[Service]
Type=simple
PrivateTmp=true
ExecStart=/usr/bin/openfortivpn -c @SYSCONFDIR@/openfortivpn/%I.conf
OOMScoreAdjust=-100

[Install]
WantedBy=multi-user.target

0 comments on commit 021e0ef

Please sign in to comment.