-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from vijs/feature/cli
Initial version of auto renew daemon
- Loading branch information
Showing
12 changed files
with
939 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
project(certifierd) | ||
|
||
file(GLOB SOURCES "*.c") | ||
|
||
add_executable(${PROJECT_NAME} ${SOURCES}) | ||
target_link_libraries(${PROJECT_NAME} certifier) | ||
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/internal_headers) | ||
|
||
# The rule to install daemon binary | ||
install (TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin) | ||
|
||
# Directory with systemd unit files | ||
set (SYSTEMD_UNIT_DIR "/usr/lib/systemd/system") | ||
|
||
set (SYSTEMV_UNIT_DIR "/etc/init.d") | ||
|
||
# Default directory for log file | ||
set (DAEMON_LOG_DIR "/var/log/certifier") | ||
|
||
# Default directory for PID file | ||
set (DAEMON_PID_DIR "/run/certifier") | ||
|
||
# Default directory for certificates | ||
set (DAEMON_CERTS_DIR "/etc/certifier/certificates") | ||
|
||
# Macro for installing configuration files | ||
function(install_conf src dest) | ||
if(NOT IS_ABSOLUTE "${src}") | ||
set(src "${CMAKE_CURRENT_SOURCE_DIR}/${src}") | ||
endif() | ||
get_filename_component(src_name "${src}" NAME) | ||
if (NOT IS_ABSOLUTE "${dest}") | ||
set(dest "${CMAKE_INSTALL_PREFIX}/${dest}") | ||
endif() | ||
install(CODE " | ||
if(NOT EXISTS \"\$ENV{DESTDIR}${dest}/${src_name}\") | ||
#file(INSTALL \"${src}\" DESTINATION \"${dest}\") | ||
message(STATUS \"Installing: \$ENV{DESTDIR}${dest}/${src_name}\") | ||
execute_process(COMMAND \${CMAKE_COMMAND} -E copy \"${src}\" | ||
\"\$ENV{DESTDIR}${dest}/${src_name}\" | ||
RESULT_VARIABLE copy_result | ||
ERROR_VARIABLE error_output) | ||
if(copy_result) | ||
message(FATAL_ERROR \${error_output}) | ||
endif() | ||
else() | ||
message(STATUS \"Skipping : \$ENV{DESTDIR}${dest}/${src_name}\") | ||
endif() | ||
") | ||
endfunction(install_conf) | ||
|
||
if (NOT ${SYSTEMV_DAEMON}) | ||
# Install systemd unit files | ||
install_conf (./certifierd.service ${SYSTEMD_UNIT_DIR}) | ||
elseif(${SYSTEMV_DAEMON}) | ||
set(PROGRAM_PERMISSIONS_DEFAULT | ||
OWNER_WRITE OWNER_READ OWNER_EXECUTE | ||
GROUP_READ GROUP_EXECUTE | ||
WORLD_READ WORLD_EXECUTE) | ||
|
||
# Install systemv unit files | ||
install(FILES certifierd.init DESTINATION ${SYSTEMV_UNIT_DIR} PERMISSIONS ${PROGRAM_PERMISSIONS_DEFAULT} RENAME certifierd) | ||
|
||
install(CODE "set(CMAKE_INSTALL_PREFIX \"${CMAKE_INSTALL_PREFIX}\")") | ||
install(SCRIPT InstallScript.cmake ${SYSTEMV_UNIT_DIR}) | ||
endif() | ||
|
||
# Create empty directory for default log file | ||
install(DIRECTORY DESTINATION ${DAEMON_LOG_DIR}) | ||
|
||
# Create empty directory for default PID file | ||
install(DIRECTORY DESTINATION ${DAEMON_PID_DIR}) | ||
|
||
# Create empty directory for certificates to be renewed | ||
install(DIRECTORY DESTINATION ${DAEMON_CERTS_DIR}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
if("${CMAKE_INSTALL_PREFIX}" STREQUAL "/") | ||
execute_process(COMMAND update-rc.d certifierd defaults | ||
RESULT_VARIABLE Result | ||
OUTPUT_VARIABLE Output | ||
ERROR_VARIABLE Error) | ||
if(Result EQUAL 0) | ||
message(STATUS "Ran update-rc.d as CMAKE_INSTALL_PREFIX == \"/\"") | ||
else() | ||
message(FATAL_ERROR "Result - ${Result}\nOutput - ${Output}\nError - Error") | ||
endif() | ||
else() | ||
message(STATUS "Not running update-rc.d as CMAKE_INSTALL_PREFIX != \"/\"") | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#!/bin/sh | ||
# | ||
# /etc/init.d/certifierd | ||
# | ||
# Init script for Certifier daemon | ||
# | ||
# chkconfig: 2345 20 80 | ||
# description: LibCertifier Daemon that renews certificates automatically once a day | ||
|
||
### BEGIN INIT INFO | ||
# Provides: certifierd | ||
# Required-Start: $rsyslog | ||
# Required-Stop: | ||
# Should-Start: | ||
# Should-Stop: | ||
# Default-Start: 2 3 4 5 | ||
# Default-Stop: 0 1 6 | ||
# Short-Description: start and stop example of daemon | ||
# Description: Example of UNIX daemon | ||
### END INIT INFO | ||
|
||
# Source function library. | ||
. /lib/lsb/init-functions | ||
|
||
prog="certifierd" | ||
app="/usr/bin/$prog" | ||
lock_file="/var/lock/subsys/$prog" | ||
log_file="/var/log/$prog.log" | ||
conf_file="/etc/certifier/libcertifier.cfg" | ||
|
||
start() { | ||
echo -n $"Starting $prog: " | ||
start_daemon -p $lock_file $app --conf-file $conf_file --log-file $log_file --daemon | ||
RETVAL=$? | ||
[ $RETVAL -eq 0 ] && touch $lock_file | ||
echo | ||
return $RETVAL | ||
} | ||
|
||
stop() { | ||
echo -n $"Stopping $prog: " | ||
killproc -p $lock_file $prog -INT | ||
RETVAL=$? | ||
echo | ||
[ $RETVAL -eq 0 ] && rm -f $lock_file | ||
return $RETVAL | ||
} | ||
|
||
restart() { | ||
stop | ||
start | ||
} | ||
|
||
reload() { | ||
restart | ||
} | ||
|
||
force_reload() { | ||
restart | ||
} | ||
|
||
rh_status() { | ||
status_of_proc -p $lock_file "$prog process" | ||
} | ||
|
||
rh_status_q() { | ||
rh_status >/dev/null 2>&1 | ||
} | ||
|
||
case "$1" in | ||
start) | ||
rh_status_q && exit 0 | ||
$1 | ||
;; | ||
stop) | ||
rh_status_q || exit 0 | ||
$1 | ||
;; | ||
restart) | ||
$1 | ||
;; | ||
reload) | ||
rh_status_q || exit 7 | ||
$1 | ||
;; | ||
force-reload) | ||
force_reload | ||
;; | ||
status) | ||
rh_status | ||
;; | ||
condrestart|try-restart) | ||
rh_status_q || exit 0 | ||
restart | ||
;; | ||
*) | ||
echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}" | ||
exit 2 | ||
esac | ||
|
||
exit $? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
[Unit] | ||
Description=LibCertifier Daemon that renews certificates automatically once a day | ||
|
||
[Service] | ||
Type=simple | ||
ExecStart=/usr/bin/certifierd \ | ||
--conf-file /etc/certifier/libcertifier.cfg \ | ||
--log-file /var/log/certifier/certifierd.log | ||
ExecReload=/bin/kill -HUP $MAINPID | ||
|
||
[Install] | ||
WantedBy=multi-user.target |
Oops, something went wrong.