Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clamscan systemd service and timer #928

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions clamdscan/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}/[email protected]
${CMAKE_CURRENT_BINARY_DIR}/[email protected] @ONLY)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/[email protected]
${CMAKE_CURRENT_BINARY_DIR}/[email protected] @ONLY)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/[email protected]
DESTINATION ${SYSTEMD_UNIT_DIR} COMPONENT programs)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/[email protected]
DESTINATION ${SYSTEMD_USER_UNIT_DIR} COMPONENT programs)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/[email protected]
DESTINATION ${SYSTEMD_UNIT_DIR} COMPONENT programs)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/[email protected]
DESTINATION ${SYSTEMD_USER_UNIT_DIR} COMPONENT programs)
endif()
8 changes: 8 additions & 0 deletions clamdscan/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[Unit]
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
11 changes: 11 additions & 0 deletions clamdscan/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Unit]
Description=Weekly ClamAV clamdscan %f

[Timer]
OnCalendar=weekly
AccuracySec=1h
RandomizedDelaySec=1h
Persistent=true

[Install]
WantedBy=timers.target
21 changes: 21 additions & 0 deletions clamscan/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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}/[email protected]
${CMAKE_CURRENT_BINARY_DIR}/[email protected] @ONLY)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/[email protected]
${CMAKE_CURRENT_BINARY_DIR}/[email protected] @ONLY)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/[email protected]
DESTINATION ${SYSTEMD_UNIT_DIR} COMPONENT programs)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/[email protected]
DESTINATION ${SYSTEMD_USER_UNIT_DIR} COMPONENT programs)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/[email protected]
DESTINATION ${SYSTEMD_UNIT_DIR} COMPONENT programs)
install(
FILES ${CMAKE_CURRENT_BINARY_DIR}/[email protected]
DESTINATION ${SYSTEMD_USER_UNIT_DIR} COMPONENT programs)
endif()
8 changes: 8 additions & 0 deletions clamscan/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[Unit]
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 %f
11 changes: 11 additions & 0 deletions clamscan/[email protected]
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[Unit]
Description=Weekly ClamAV clamscan %f

[Timer]
OnCalendar=weekly
AccuracySec=1h
RandomizedDelaySec=1h
Persistent=true

[Install]
WantedBy=timers.target
17 changes: 15 additions & 2 deletions cmake/FindSYSTEMD.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It may also be nice to have the main CMakeList.txt summary print out this variable next to the other one:

${_} unit directory ${e}${SYSTEMD_UNIT_DIR}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nils-werner I think we forgot about this.

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()
Loading