From 40ed982079e9af7c5c1bfc84fc33a29698066e77 Mon Sep 17 00:00:00 2001 From: Ron Isaacson Date: Tue, 30 Jun 2020 01:22:37 -0400 Subject: [PATCH] Fix systemd unit file generation --- src/CMakeLists.txt | 18 ++++++++++++++++++ src/vpnbridge/CMakeLists.txt | 7 +------ src/vpnclient/CMakeLists.txt | 7 +------ src/vpnserver/CMakeLists.txt | 7 +------ systemd/softether-vpnbridge.service | 10 +++++----- systemd/softether-vpnclient.service | 10 +++++----- systemd/softether-vpnserver.service | 10 +++++----- 7 files changed, 36 insertions(+), 33 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5568fe42..4d78ef5f 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -23,6 +23,24 @@ if(UNIX) RENAME ${component} ) endmacro(install_wrapper_script) + + # Same approach for systemd unit files + # + macro(install_unit_file component) + file(GENERATE OUTPUT ${BUILD_DIRECTORY}/softether-${component}.service + CONTENT "# placeholder\n" + ) + + install(CODE "set(DIR \"\${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBEXECDIR}\")\nconfigure_file(${TOP_DIRECTORY}/systemd/softether-${component}.service ${BUILD_DIRECTORY}/softether-${component}.service)" + COMPONENT ${component} + ) + + install(FILES ${BUILD_DIRECTORY}/softether-${component}.service + COMPONENT ${component} + DESTINATION ${CMAKE_INSTALL_SYSTEMD_UNITDIR} + PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ + ) + endmacro(install_unit_file) endif() if(BUILD_TYPE STREQUAL "Debug") diff --git a/src/vpnbridge/CMakeLists.txt b/src/vpnbridge/CMakeLists.txt index 5a6da417..f0129f13 100644 --- a/src/vpnbridge/CMakeLists.txt +++ b/src/vpnbridge/CMakeLists.txt @@ -41,11 +41,6 @@ if(UNIX) install_wrapper_script("vpnbridge") if(NOT "${CMAKE_INSTALL_SYSTEMD_UNITDIR}" STREQUAL "") - configure_file(${TOP_DIRECTORY}/systemd/softether-vpnbridge.service ${CMAKE_BINARY_DIR}/systemd/softether-vpnbridge.service) - install(FILES ${CMAKE_BINARY_DIR}/systemd/softether-vpnbridge.service - COMPONENT "vpnbridge" - DESTINATION ${CMAKE_INSTALL_SYSTEMD_UNITDIR} - PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ - ) + install_unit_file("vpnbridge") endif() endif() diff --git a/src/vpnclient/CMakeLists.txt b/src/vpnclient/CMakeLists.txt index 1cfa798e..71c5c351 100644 --- a/src/vpnclient/CMakeLists.txt +++ b/src/vpnclient/CMakeLists.txt @@ -41,11 +41,6 @@ if(UNIX) install_wrapper_script("vpnclient") if(NOT "${CMAKE_INSTALL_SYSTEMD_UNITDIR}" STREQUAL "") - configure_file(${TOP_DIRECTORY}/systemd/softether-vpnclient.service ${CMAKE_BINARY_DIR}/systemd/softether-vpnclient.service) - install(FILES ${CMAKE_BINARY_DIR}/systemd/softether-vpnclient.service - COMPONENT "vpnclient" - DESTINATION ${CMAKE_INSTALL_SYSTEMD_UNITDIR} - PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ - ) + install_unit_file("vpnclient") endif() endif() diff --git a/src/vpnserver/CMakeLists.txt b/src/vpnserver/CMakeLists.txt index d7d0b525..e4caaed6 100644 --- a/src/vpnserver/CMakeLists.txt +++ b/src/vpnserver/CMakeLists.txt @@ -41,11 +41,6 @@ if(UNIX) install_wrapper_script("vpnserver") if(NOT "${CMAKE_INSTALL_SYSTEMD_UNITDIR}" STREQUAL "") - configure_file(${TOP_DIRECTORY}/systemd/softether-vpnserver.service ${CMAKE_BINARY_DIR}/systemd/softether-vpnserver.service) - install(FILES ${CMAKE_BINARY_DIR}/systemd/softether-vpnserver.service - COMPONENT "vpnserver" - DESTINATION ${CMAKE_INSTALL_SYSTEMD_UNITDIR} - PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ - ) + install_unit_file("vpnserver") endif() endif() diff --git a/systemd/softether-vpnbridge.service b/systemd/softether-vpnbridge.service index c9fa2b73..b4d3cc8c 100644 --- a/systemd/softether-vpnbridge.service +++ b/systemd/softether-vpnbridge.service @@ -1,13 +1,13 @@ [Unit] Description=SoftEther VPN Bridge After=network.target auditd.service -ConditionPathExists=!${CPACK_PACKAGING_INSTALL_PREFIX}/libexec/softether/vpnbridge/do_not_run +ConditionPathExists=!@DIR@/softether/vpnbridge/do_not_run [Service] Type=forking -EnvironmentFile=-${CPACK_PACKAGING_INSTALL_PREFIX}/libexec/softether/vpnbridge -ExecStart=${CPACK_PACKAGING_INSTALL_PREFIX}/libexec/softether/vpnbridge/vpnbridge start -ExecStop=${CPACK_PACKAGING_INSTALL_PREFIX}/libexec/softether/vpnbridge/vpnbridge stop +EnvironmentFile=-@DIR@/softether/vpnbridge +ExecStart=@DIR@/softether/vpnbridge/vpnbridge start +ExecStop=@DIR@/softether/vpnbridge/vpnbridge stop KillMode=process Restart=on-failure @@ -16,7 +16,7 @@ PrivateTmp=yes ProtectHome=yes ProtectSystem=full ReadOnlyDirectories=/ -ReadWriteDirectories=-${CPACK_PACKAGING_INSTALL_PREFIX}/libexec/softether/vpnbridge +ReadWriteDirectories=-@DIR@/softether/vpnbridge CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_NET_BROADCAST CAP_NET_RAW CAP_SYS_NICE CAP_SYSLOG CAP_SETUID [Install] diff --git a/systemd/softether-vpnclient.service b/systemd/softether-vpnclient.service index ff47b2a4..6bac5267 100644 --- a/systemd/softether-vpnclient.service +++ b/systemd/softether-vpnclient.service @@ -1,13 +1,13 @@ [Unit] Description=SoftEther VPN Client After=network.target auditd.service -ConditionPathExists=!${CPACK_PACKAGING_INSTALL_PREFIX}/libexec/softether/vpnclient/do_not_run +ConditionPathExists=!@DIR@/softether/vpnclient/do_not_run [Service] Type=forking -EnvironmentFile=-${CPACK_PACKAGING_INSTALL_PREFIX}/libexec/softether/vpnclient -ExecStart=${CPACK_PACKAGING_INSTALL_PREFIX}/libexec/softether/vpnclient/vpnclient start -ExecStop=${CPACK_PACKAGING_INSTALL_PREFIX}/libexec/softether/vpnclient/vpnclient stop +EnvironmentFile=-@DIR@/softether/vpnclient +ExecStart=@DIR@/softether/vpnclient/vpnclient start +ExecStop=@DIR@/softether/vpnclient/vpnclient stop KillMode=process Restart=on-failure @@ -16,7 +16,7 @@ PrivateTmp=yes ProtectHome=yes ProtectSystem=full ReadOnlyDirectories=/ -ReadWriteDirectories=-${CPACK_PACKAGING_INSTALL_PREFIX}/libexec/softether/vpnclient +ReadWriteDirectories=-@DIR@/softether/vpnclient CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_NET_BROADCAST CAP_NET_RAW CAP_SYS_NICE CAP_SYSLOG CAP_SETUID [Install] diff --git a/systemd/softether-vpnserver.service b/systemd/softether-vpnserver.service index c22ca58e..15427ad6 100644 --- a/systemd/softether-vpnserver.service +++ b/systemd/softether-vpnserver.service @@ -1,14 +1,14 @@ [Unit] Description=SoftEther VPN Server After=network.target auditd.service -ConditionPathExists=!${CPACK_PACKAGING_INSTALL_PREFIX}/libexec/softether/vpnserver/do_not_run +ConditionPathExists=!@DIR@/softether/vpnserver/do_not_run [Service] Type=forking TasksMax=16777216 -EnvironmentFile=-${CPACK_PACKAGING_INSTALL_PREFIX}/libexec/softether/vpnserver -ExecStart=${CPACK_PACKAGING_INSTALL_PREFIX}/libexec/softether/vpnserver/vpnserver start -ExecStop=${CPACK_PACKAGING_INSTALL_PREFIX}/libexec/softether/vpnserver/vpnserver stop +EnvironmentFile=-@DIR@/softether/vpnserver +ExecStart=@DIR@/softether/vpnserver/vpnserver start +ExecStop=@DIR@/softether/vpnserver/vpnserver stop KillMode=process Restart=on-failure @@ -17,7 +17,7 @@ PrivateTmp=yes ProtectHome=yes ProtectSystem=full ReadOnlyDirectories=/ -ReadWriteDirectories=-${CPACK_PACKAGING_INSTALL_PREFIX}/libexec/softether/vpnserver +ReadWriteDirectories=-@DIR@/softether/vpnserver CapabilityBoundingSet=CAP_NET_ADMIN CAP_NET_BIND_SERVICE CAP_NET_BROADCAST CAP_NET_RAW CAP_SYS_NICE CAP_SYSLOG CAP_SETUID [Install]