From 8b3b4835574f7f219fcd7ef967848e148969ae6d Mon Sep 17 00:00:00 2001 From: Jiri Hnidek Date: Tue, 1 Nov 2016 16:00:54 +0100 Subject: [PATCH] Updated cmake to install systemd unit files during make install. Fixed path to binary in unit files. --- CMakeLists.txt | 9 ++++++++- README.md | 11 +++++------ forking-daemon.service | 2 +- simple-daemon.service | 2 +- 4 files changed, 15 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3cad5b8..e58e927 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -34,6 +34,9 @@ add_subdirectory (src) # Directory with configuration files set (DAEMON_CONF_DIR "/etc/daemon") +# Directory with systemd unit files +set (SYSTEMD_UNIT_DIR "/usr/lib/systemd/system/") + # Macro for installing configuration files function(install_conf src dest) if(NOT IS_ABSOLUTE "${src}") @@ -61,4 +64,8 @@ function(install_conf src dest) endfunction(install_conf) # Install configuration file -install_conf (./daemon.conf ${DAEMON_CONF_DIR}) \ No newline at end of file +install_conf (./daemon.conf ${DAEMON_CONF_DIR}) + +# Install systemd unit files +install_conf (./simple-daemon.service ${SYSTEMD_UNIT_DIR}) +install_conf (./forking-daemon.service ${SYSTEMD_UNIT_DIR}) diff --git a/README.md b/README.md index fc75545..abde5b5 100644 --- a/README.md +++ b/README.md @@ -79,18 +79,17 @@ it will become real UNIX daemon. But this is not the way, how UNIX daemons are started nowdays. Some init scripts or service files are used for this purpose. -When you use Linux distribution using systemd, then you can try to copy -file `forking-daemon.service` or `simple-daemon.service` to directory: - - /usr/lib/systemd/system - -and then start daemon using +When you use Linux distribution using systemd, then you can try start daemon using systemctl start simple-daemon systemctl status simple-daemon systemctl reload simple-daemon systemctl stop simple-daemon +> Note: The unit files `simple-daemon.service` and `forking-daemon.service` +are copied to the directory `/usr/lib/systemd/system` during installation using +`make install` command. + When you use RedHat 4/5/6 or CentOS, then you can try to use init script: cp daemon.init /etc/rc.d/init.d/daemond diff --git a/forking-daemon.service b/forking-daemon.service index 4b4318d..2f3b801 100644 --- a/forking-daemon.service +++ b/forking-daemon.service @@ -4,7 +4,7 @@ Description=Example of forking daemon program [Service] Type=forking PIDFile=/var/run/daemon.pid -ExecStart=/usr/bin/daemon \ +ExecStart=/usr/local/bin/daemon \ --conf_file /etc/daemon/daemon.conf \ --log_file /var/log/daemon.log \ --pid_file /var/run/daemon.pid \ diff --git a/simple-daemon.service b/simple-daemon.service index a22a0c1..177b541 100644 --- a/simple-daemon.service +++ b/simple-daemon.service @@ -3,7 +3,7 @@ Description=Example of simple daemon program [Service] Type=simple -ExecStart=/usr/bin/daemon \ +ExecStart=/usr/local/bin/daemon \ --conf_file /etc/daemon/daemon.conf \ --log_file /var/log/daemon.log User=root