From 7ffbf10adc3cf5c2867fb75546b146767ad95c78 Mon Sep 17 00:00:00 2001 From: Nils Werner Date: Thu, 25 May 2023 12:23:25 +0200 Subject: [PATCH 1/5] clamscan systemd unit and timer --- clamscan/CMakeLists.txt | 21 +++++++++++++++++++++ clamscan/clamav-clamscan@.service.in | 9 +++++++++ clamscan/clamav-clamscan@.timer.in | 11 +++++++++++ cmake/FindSYSTEMD.cmake | 17 +++++++++++++++-- 4 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 clamscan/clamav-clamscan@.service.in create mode 100644 clamscan/clamav-clamscan@.timer.in diff --git a/clamscan/CMakeLists.txt b/clamscan/CMakeLists.txt index ab0863544c..82e1dd1ca7 100644 --- a/clamscan/CMakeLists.txt +++ b/clamscan/CMakeLists.txt @@ -46,3 +46,24 @@ if(WIN32) else() install(TARGETS clamscan DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT programs) endif() + +if(SYSTEMD_FOUND) + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/clamav-clamscan@.service.in + ${CMAKE_CURRENT_BINARY_DIR}/clamav-clamscan@.service @ONLY) + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/clamav-clamscan@.timer.in + ${CMAKE_CURRENT_BINARY_DIR}/clamav-clamscan@.timer @ONLY) + install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/clamav-clamscan@.service + DESTINATION ${SYSTEMD_UNIT_DIR} COMPONENT programs) + install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/clamav-clamscan@.service + DESTINATION ${SYSTEMD_USER_UNIT_DIR} COMPONENT programs) + install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/clamav-clamscan@.timer + DESTINATION ${SYSTEMD_UNIT_DIR} COMPONENT programs) + install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/clamav-clamscan@.timer + DESTINATION ${SYSTEMD_USER_UNIT_DIR} COMPONENT programs) +endif() diff --git a/clamscan/clamav-clamscan@.service.in b/clamscan/clamav-clamscan@.service.in new file mode 100644 index 0000000000..30b4dbe785 --- /dev/null +++ b/clamscan/clamav-clamscan@.service.in @@ -0,0 +1,9 @@ +[Unit] +Description=ClamAV clamscan %I +Documentation=man:clamscan(1) man:clamscan.conf(5) https://docs.clamav.net/ + +[Service] +Nice=19 +IOSchedulingClass=idle +KillSignal=SIGINT +ExecStart=@prefix@/bin/clamscan --recursive=yes --infected --suppress-ok-results %I diff --git a/clamscan/clamav-clamscan@.timer.in b/clamscan/clamav-clamscan@.timer.in new file mode 100644 index 0000000000..ef880b4663 --- /dev/null +++ b/clamscan/clamav-clamscan@.timer.in @@ -0,0 +1,11 @@ +[Unit] +Description=Weekly ClamAV clamscan %I + +[Timer] +OnCalendar=weekly +AccuracySec=1h +RandomizedDelaySec=1h +Persistent=true + +[Install] +WantedBy=timers.target diff --git a/cmake/FindSYSTEMD.cmake b/cmake/FindSYSTEMD.cmake index 5c02947be6..0680fb1223 100644 --- a/cmake/FindSYSTEMD.cmake +++ b/cmake/FindSYSTEMD.cmake @@ -110,16 +110,29 @@ pkg_check_modules(SYSTEMD_PROGRAM QUIET systemd) if (SYSTEMD_PROGRAM_FOUND) if ("${SYSTEMD_UNIT_DIR}" STREQUAL "") - # Use pkg-config to look up the systemd unit install directory + # Use pkg-config to look up the systemd system unit install directory execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} --variable=systemdsystemunitdir systemd OUTPUT_VARIABLE SYSTEMD_UNIT_DIR) string(REGEX REPLACE "[ \t\n]+" "" SYSTEMD_UNIT_DIR "${SYSTEMD_UNIT_DIR}") endif() - message(STATUS "systemd services install dir: ${SYSTEMD_UNIT_DIR}") + message(STATUS "systemd system services install dir: ${SYSTEMD_UNIT_DIR}") + + if ("${SYSTEMD_USER_UNIT_DIR}" STREQUAL "") + # Use pkg-config to look up the systemd user unit install directory + execute_process(COMMAND ${PKG_CONFIG_EXECUTABLE} + --variable=systemduserunitdir systemd + OUTPUT_VARIABLE SYSTEMD_USER_UNIT_DIR) + string(REGEX REPLACE "[ \t\n]+" "" SYSTEMD_USER_UNIT_DIR "${SYSTEMD_USER_UNIT_DIR}") + endif() + + message(STATUS "systemd user services install dir: ${SYSTEMD_USER_UNIT_DIR}") else() if (SYSTEMD_UNIT_DIR) message (FATAL_ERROR "SYSTEMD_UNIT_DIR was defined but pkg-config was not able to find systemd!") endif() + if (SYSTEMD_USER_UNIT_DIR) + message (FATAL_ERROR "SYSTEMD_USER_UNIT_DIR was defined but pkg-config was not able to find systemd!") + endif() endif() From 7a260e26103d9277cb5c3c249dae6c71e3eb5d8b Mon Sep 17 00:00:00 2001 From: Nils Werner Date: Mon, 29 May 2023 11:04:41 +0200 Subject: [PATCH 2/5] Clamdscan service and timer --- clamdscan/CMakeLists.txt | 21 +++++++++++++++++++++ clamdscan/clamav-clamdscan@.service.in | 9 +++++++++ clamdscan/clamav-clamdscan@.timer.in | 11 +++++++++++ 3 files changed, 41 insertions(+) create mode 100644 clamdscan/clamav-clamdscan@.service.in create mode 100644 clamdscan/clamav-clamdscan@.timer.in diff --git a/clamdscan/CMakeLists.txt b/clamdscan/CMakeLists.txt index f300024431..134b5b3b3e 100644 --- a/clamdscan/CMakeLists.txt +++ b/clamdscan/CMakeLists.txt @@ -47,3 +47,24 @@ if(WIN32) else() install(TARGETS clamdscan DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT programs) endif() + +if(SYSTEMD_FOUND) + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/clamav-clamdscan@.service.in + ${CMAKE_CURRENT_BINARY_DIR}/clamav-clamdscan@.service @ONLY) + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/clamav-clamdscan@.timer.in + ${CMAKE_CURRENT_BINARY_DIR}/clamav-clamdscan@.timer @ONLY) + install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/clamav-clamdscan@.service + DESTINATION ${SYSTEMD_UNIT_DIR} COMPONENT programs) + install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/clamav-clamdscan@.service + DESTINATION ${SYSTEMD_USER_UNIT_DIR} COMPONENT programs) + install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/clamav-clamdscan@.timer + DESTINATION ${SYSTEMD_UNIT_DIR} COMPONENT programs) + install( + FILES ${CMAKE_CURRENT_BINARY_DIR}/clamav-clamdscan@.timer + DESTINATION ${SYSTEMD_USER_UNIT_DIR} COMPONENT programs) +endif() diff --git a/clamdscan/clamav-clamdscan@.service.in b/clamdscan/clamav-clamdscan@.service.in new file mode 100644 index 0000000000..3b69062d44 --- /dev/null +++ b/clamdscan/clamav-clamdscan@.service.in @@ -0,0 +1,9 @@ +[Unit] +Description=ClamAV clamdscan %I +Documentation=man:clamdscan(1) man:clamdscan.conf(5) https://docs.clamav.net/ + +[Service] +Nice=19 +IOSchedulingClass=idle +KillSignal=SIGINT +ExecStart=@prefix@/bin/clamdscan --infected --multiscan --fdpass %I diff --git a/clamdscan/clamav-clamdscan@.timer.in b/clamdscan/clamav-clamdscan@.timer.in new file mode 100644 index 0000000000..0e93bb0e1a --- /dev/null +++ b/clamdscan/clamav-clamdscan@.timer.in @@ -0,0 +1,11 @@ +[Unit] +Description=Weekly ClamAV clamdscan %I + +[Timer] +OnCalendar=weekly +AccuracySec=1h +RandomizedDelaySec=1h +Persistent=true + +[Install] +WantedBy=timers.target From d64f619a2f67184265948b1d44f5cd1f24256eb1 Mon Sep 17 00:00:00 2001 From: Nils Werner Date: Mon, 29 May 2023 11:32:20 +0200 Subject: [PATCH 3/5] clamav-clamscan remove unneeded systemd params --- clamdscan/clamav-clamdscan@.service.in | 3 --- clamscan/clamav-clamscan@.service.in | 1 - 2 files changed, 4 deletions(-) diff --git a/clamdscan/clamav-clamdscan@.service.in b/clamdscan/clamav-clamdscan@.service.in index 3b69062d44..9f595ac91b 100644 --- a/clamdscan/clamav-clamdscan@.service.in +++ b/clamdscan/clamav-clamdscan@.service.in @@ -3,7 +3,4 @@ Description=ClamAV clamdscan %I Documentation=man:clamdscan(1) man:clamdscan.conf(5) https://docs.clamav.net/ [Service] -Nice=19 -IOSchedulingClass=idle -KillSignal=SIGINT ExecStart=@prefix@/bin/clamdscan --infected --multiscan --fdpass %I diff --git a/clamscan/clamav-clamscan@.service.in b/clamscan/clamav-clamscan@.service.in index 30b4dbe785..b95cb3041e 100644 --- a/clamscan/clamav-clamscan@.service.in +++ b/clamscan/clamav-clamscan@.service.in @@ -5,5 +5,4 @@ Documentation=man:clamscan(1) man:clamscan.conf(5) https://docs.clamav.net/ [Service] Nice=19 IOSchedulingClass=idle -KillSignal=SIGINT ExecStart=@prefix@/bin/clamscan --recursive=yes --infected --suppress-ok-results %I From d9e5c46af3f0e712c700af5ad113621d5e88b607 Mon Sep 17 00:00:00 2001 From: Nils Werner Date: Thu, 1 Jun 2023 08:48:06 +0200 Subject: [PATCH 4/5] Use %f instead of %I because were dealing with paths --- clamdscan/clamav-clamdscan@.service.in | 4 ++-- clamdscan/clamav-clamdscan@.timer.in | 2 +- clamscan/clamav-clamscan@.service.in | 4 ++-- clamscan/clamav-clamscan@.timer.in | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/clamdscan/clamav-clamdscan@.service.in b/clamdscan/clamav-clamdscan@.service.in index 9f595ac91b..959129fbbc 100644 --- a/clamdscan/clamav-clamdscan@.service.in +++ b/clamdscan/clamav-clamdscan@.service.in @@ -1,6 +1,6 @@ [Unit] -Description=ClamAV clamdscan %I +Description=ClamAV clamdscan %f Documentation=man:clamdscan(1) man:clamdscan.conf(5) https://docs.clamav.net/ [Service] -ExecStart=@prefix@/bin/clamdscan --infected --multiscan --fdpass %I +ExecStart=@prefix@/bin/clamdscan --infected --multiscan --fdpass %f diff --git a/clamdscan/clamav-clamdscan@.timer.in b/clamdscan/clamav-clamdscan@.timer.in index 0e93bb0e1a..381fd93314 100644 --- a/clamdscan/clamav-clamdscan@.timer.in +++ b/clamdscan/clamav-clamdscan@.timer.in @@ -1,5 +1,5 @@ [Unit] -Description=Weekly ClamAV clamdscan %I +Description=Weekly ClamAV clamdscan %f [Timer] OnCalendar=weekly diff --git a/clamscan/clamav-clamscan@.service.in b/clamscan/clamav-clamscan@.service.in index b95cb3041e..2960611508 100644 --- a/clamscan/clamav-clamscan@.service.in +++ b/clamscan/clamav-clamscan@.service.in @@ -1,8 +1,8 @@ [Unit] -Description=ClamAV clamscan %I +Description=ClamAV clamscan %f Documentation=man:clamscan(1) man:clamscan.conf(5) https://docs.clamav.net/ [Service] Nice=19 IOSchedulingClass=idle -ExecStart=@prefix@/bin/clamscan --recursive=yes --infected --suppress-ok-results %I +ExecStart=@prefix@/bin/clamscan --recursive=yes --infected --suppress-ok-results %f diff --git a/clamscan/clamav-clamscan@.timer.in b/clamscan/clamav-clamscan@.timer.in index ef880b4663..d74c432ce8 100644 --- a/clamscan/clamav-clamscan@.timer.in +++ b/clamscan/clamav-clamscan@.timer.in @@ -1,5 +1,5 @@ [Unit] -Description=Weekly ClamAV clamscan %I +Description=Weekly ClamAV clamscan %f [Timer] OnCalendar=weekly From 6eb69cc87650deb6e8bcdcd6dee303d1300c89e4 Mon Sep 17 00:00:00 2001 From: Nils Werner Date: Thu, 1 Jun 2023 09:01:55 +0200 Subject: [PATCH 5/5] Reduce CPU load for clamdscan, just to be safe --- clamdscan/clamav-clamdscan@.service.in | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clamdscan/clamav-clamdscan@.service.in b/clamdscan/clamav-clamdscan@.service.in index 959129fbbc..01dc2a87ab 100644 --- a/clamdscan/clamav-clamdscan@.service.in +++ b/clamdscan/clamav-clamdscan@.service.in @@ -3,4 +3,6 @@ Description=ClamAV clamdscan %f Documentation=man:clamdscan(1) man:clamdscan.conf(5) https://docs.clamav.net/ [Service] +Nice=19 +IOSchedulingClass=idle ExecStart=@prefix@/bin/clamdscan --infected --multiscan --fdpass %f