From c462174bc4f32a90a9ed2ae656f8d428bfc4405c Mon Sep 17 00:00:00 2001 From: Greg Beard Date: Sun, 29 Sep 2024 15:38:46 +0100 Subject: [PATCH] feat: Adds runit service and systemd unit files --- CMakeLists.txt | 2 ++ init/CMakeLists.txt | 45 +++++++++++++++++++++++++++++++ init/runit/run.in | 9 +++++++ init/systemd/gpufanctl.service.in | 14 ++++++++++ 4 files changed, 70 insertions(+) create mode 100644 init/CMakeLists.txt create mode 100644 init/runit/run.in create mode 100644 init/systemd/gpufanctl.service.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 1ae0efa..e83f3cf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -49,4 +49,6 @@ if(GPUFANCTL_ENABLE_TESTS) add_subdirectory(tests) endif() +add_subdirectory(init) + install(TARGETS gpufanctl) diff --git a/init/CMakeLists.txt b/init/CMakeLists.txt new file mode 100644 index 0000000..7b1d2bd --- /dev/null +++ b/init/CMakeLists.txt @@ -0,0 +1,45 @@ +configure_file( + runit/run.in + sv/gpufanctl/run + @ONLY +) + +configure_file( + systemd/gpufanctl.service.in + systemd/user/gpufanctl.service + @ONLY +) + +include(GNUInstallDirs) + +# Installs the runit service. Not installed by default. Requires... +# +# ``` +# $ cmake --install . --component gpufanctl-runit +# ``` +install( + FILES "${CMAKE_CURRENT_BINARY_DIR}/sv/gpufanctl/run" + DESTINATION "${CMAKE_INSTALL_SYSCONFDIR}/sv/gpufanctl" + PERMISSIONS + OWNER_READ OWNER_WRITE OWNER_EXECUTE + GROUP_READ GROUP_EXECUTE + WORLD_READ WORLD_EXECUTE + COMPONENT gpufanctl-runit + EXCLUDE_FROM_ALL +) + +# Installs the systemd unit file. Not installed by default. Requires... +# +# ``` +# $ cmake --install . --component gpufanctl-systemd +# ``` +install( + FILES "${CMAKE_CURRENT_BINARY_DIR}/systemd/user/gpufanctl.service" + DESTINATION "lib/systemd/user/gpufanctl.service" + PERMISSIONS + OWNER_READ OWNER_WRITE + GROUP_READ + WORLD_READ + COMPONENT gpufanctl-systemd + EXCLUDE_FROM_ALL +) diff --git a/init/runit/run.in b/init/runit/run.in new file mode 100644 index 0000000..2c761fa --- /dev/null +++ b/init/runit/run.in @@ -0,0 +1,9 @@ +#!/bin/sh + +exec 2>&1 + +if [ -r ./conf ]; then + . ./conf +fi + +exec @CMAKE_INSTALL_FULL_BINDIR@/gpufanctl ${OPTS} "${CURVE_DEFINITION}" diff --git a/init/systemd/gpufanctl.service.in b/init/systemd/gpufanctl.service.in new file mode 100644 index 0000000..f1088d6 --- /dev/null +++ b/init/systemd/gpufanctl.service.in @@ -0,0 +1,14 @@ +[Unit] +Description=GPU fan control +After=multi-user.target + +[Service] +Type=simple +ExecStart=@CMAKE_INSTALL_FULL_BINDIR@/gpufanctl +Restart=always +RestartSec=5s +StandardOutput=journal +StandardError=journal + +[Install] +WantedBy=multi-user.target