-
Notifications
You must be signed in to change notification settings - Fork 0
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 companieshouse/feature/daemon-management-…
…scripts Add daemon management scripts
- Loading branch information
Showing
4 changed files
with
186 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#!/bin/bash | ||
|
||
# Start mncq daemon. | ||
|
||
# -- Internal variables ------------------------------------------------------- | ||
|
||
script_name=$(basename "$0") | ||
|
||
default_interval="60" | ||
default_log_file="{{ tuxedo_logs_path }}/${USER}/cabsQTX.log" | ||
default_log_level="3" | ||
|
||
# -- General ------------------------------------------------------------------ | ||
|
||
check_user () { | ||
if [[ "${USER}" == "root" ]]; then | ||
echo "${script_name}: This script should be executed as a Tuxedo service user not root" | ||
exit 1 | ||
fi | ||
} | ||
|
||
check_daemon () { | ||
if [[ -n "$(pgrep -u ${USER} mncq)" ]]; then | ||
echo "${script_name}: mncq daemon is already running" >&2 | ||
exit 1 | ||
fi | ||
} | ||
|
||
start_daemon () { | ||
local interval="${1:-${default_interval}}" | ||
local log_level="${2:-${default_log_level}}" | ||
local log_file="${3:-${default_log_file}}" | ||
|
||
mncq "${interval}" "${log_level}" "${log_file}" | ||
} | ||
|
||
# -- Entrypoint --------------------------------------------------------------- | ||
|
||
main () { | ||
check_user | ||
check_daemon | ||
start_daemon "${@}" | ||
} | ||
|
||
main "${@}" |
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,56 @@ | ||
#!/bin/bash | ||
|
||
# Stop mncq daemon. | ||
|
||
# -- Internal variables ------------------------------------------------------- | ||
|
||
script_name=$(basename "$0") | ||
|
||
max_pid_wait_seconds="10" | ||
|
||
# -- General ------------------------------------------------------------------ | ||
|
||
check_user () { | ||
if [[ "${USER}" == "root" ]]; then | ||
echo "${script_name}: This script should be executed as a Tuxedo service user not root" | ||
exit 1 | ||
fi | ||
} | ||
|
||
check_daemon () { | ||
if [[ -z "$(pgrep -u ${USER} mncq)" ]]; then | ||
echo "${script_name}: mncq daemon is not running" >&2 | ||
exit 1 | ||
fi | ||
} | ||
|
||
stop_daemon () { | ||
local daemon_pid="$(pgrep -u ${USER} mncq)" | ||
|
||
echo "${script_name}: stopping mncq daemon" | ||
kill -s SIGTERM "${daemon_pid}" | ||
|
||
local pid_wait_attempts=0 | ||
|
||
while $(kill -0 "${daemon_pid}" 2>/dev/null); do | ||
if [[ "${pid_wait_attempts}" -gt "${max_pid_wait_seconds}" ]]; then | ||
echo "${script_name}: could not stop mncq daemon" | ||
exit 1 | ||
fi | ||
|
||
((pid_wait_attempts++)) | ||
sleep 1 | ||
done | ||
|
||
echo "${script_name}: mncq daemon stopped" | ||
} | ||
|
||
# -- Entrypoint --------------------------------------------------------------- | ||
|
||
main () { | ||
check_user | ||
check_daemon | ||
stop_daemon | ||
} | ||
|
||
main "${@}" |
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,37 @@ | ||
#!/bin/bash | ||
|
||
# Start packq daemon. | ||
|
||
# -- Internal variables ------------------------------------------------------- | ||
|
||
script_name=$(basename "$0") | ||
|
||
default_interval="60" | ||
default_log_file="{{ tuxedo_logs_path }}/${USER}/packQTX.log" | ||
default_log_level="3" | ||
|
||
# -- General ------------------------------------------------------------------ | ||
|
||
check_daemon () { | ||
if [[ -n "$(pgrep -u ${USER} packq)" ]]; then | ||
echo "${script_name}: packq daemon is already running" >&2 | ||
exit 1 | ||
fi | ||
} | ||
|
||
start_daemon () { | ||
local interval="${1:-${default_interval}}" | ||
local log_level="${2:-${default_log_level}}" | ||
local log_file="${3:-${default_log_file}}" | ||
|
||
packq "${interval}" "${log_level}" "${log_file}" | ||
} | ||
|
||
# -- Entrypoint --------------------------------------------------------------- | ||
|
||
main () { | ||
check_daemon | ||
start_daemon "${@}" | ||
} | ||
|
||
main "${@}" |
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,48 @@ | ||
#!/bin/bash | ||
|
||
# Stop packq daemon. | ||
|
||
# -- Internal variables ------------------------------------------------------- | ||
|
||
script_name=$(basename "$0") | ||
|
||
max_pid_wait_seconds="10" | ||
|
||
# -- General ------------------------------------------------------------------ | ||
|
||
check_daemon () { | ||
if [[ -z "$(pgrep -u ${USER} packq)" ]]; then | ||
echo "${script_name}: packq daemon is not running" >&2 | ||
exit 1 | ||
fi | ||
} | ||
|
||
stop_daemon () { | ||
local daemon_pid="$(pgrep -u ${USER} packq)" | ||
|
||
echo "${script_name}: stopping packq daemon" | ||
kill -s SIGTERM "${daemon_pid}" | ||
|
||
local pid_wait_attempts=0 | ||
|
||
while $(kill -0 "${daemon_pid}" 2>/dev/null); do | ||
if [[ "${pid_wait_attempts}" -gt "${max_pid_wait_seconds}" ]]; then | ||
echo "${script_name}: could not stop packq daemon" | ||
exit 1 | ||
fi | ||
|
||
((pid_wait_attempts++)) | ||
sleep 1 | ||
done | ||
|
||
echo "${script_name}: packq daemon stopped" | ||
} | ||
|
||
# -- Entrypoint --------------------------------------------------------------- | ||
|
||
main () { | ||
check_daemon | ||
stop_daemon | ||
} | ||
|
||
main "${@}" |