Add specific system callbacks to future proof priority order

This commit is contained in:
Nick Chambers 2021-07-05 19:16:09 -05:00 committed by Nick Chambers
parent d02f5d27ca
commit 85694429ee
1 changed files with 27 additions and 8 deletions

35
rowbot
View File

@ -155,13 +155,17 @@ get_option trigger \`
get_option dev yes get_option dev yes
### ###
# bootup sequence # bootup/shutdown sequence
### ###
on_first_001_bootup() { on_sys_first_001_bootup() {
log_info "rowbot's pid is %d" "$$" log_info "rowbot's pid is %d" "$$"
} }
on_sys_exit_999_bootup() {
log_info "Theres a lot of beauty in ordinary things. Isnt that kind of the point?"
}
### ###
# logger # logger
### ###
@ -200,7 +204,7 @@ log_has_level() {
return 1 return 1
} }
on_init_001_log() { on_sys_init_001_log() {
declare -gA log_levels=( [debug]=1 [info]=2 [warn]=3 [error]=4 ) declare -gA log_levels=( [debug]=1 [info]=2 [warn]=3 [error]=4 )
get_option log-level info get_option log-level info
@ -223,8 +227,9 @@ on_init_001_log() {
fi fi
} }
on_exit_zzz_log() { on_sys_exit_999_log() {
if [[ -v log_fd ]] && (( log_fd != 1 )); then if [[ -v log_fd ]] && (( log_fd != 1 )); then
log_debug "shutting logger down"
exec {log_fd}>&- exec {log_fd}>&-
fi fi
} }
@ -249,7 +254,7 @@ net_send() {
log_debug "sending line: %s" "$fmt" log_debug "sending line: %s" "$fmt"
} }
on_init_002_net() { on_sys_init_002_net() {
get_option server irc.libera.chat get_option server irc.libera.chat
get_option tls no get_option tls no
@ -261,8 +266,8 @@ on_init_002_net() {
fi fi
} }
on_first_002_net() { on_sys_first_002_net() {
local irc_sock conn_args local conn_args
if [[ ${config[tls]} = no ]]; then if [[ ${config[tls]} = no ]]; then
log_info "rowbot is connecting to irc://%s:%s" "${config[server]}" "${config[port]}" log_info "rowbot is connecting to irc://%s:%s" "${config[server]}" "${config[port]}"
@ -297,13 +302,23 @@ on_first_002_net() {
fi fi
} }
on_sys_exit_998_net() {
if [[ ${config[tls]} = no ]]; then
log_info "rowbot is closing the connection to irc://%s:%s" "${config[server]}" "${config[port]}"
exec {irc_sock}>&-
else
log_info "rowbot is closing the connection to ircs://%s:%s" "${config[server]}" "${config[port]}"
rm -rf -- "$sock_dir"
fi
}
### ###
# cleanup # cleanup
### ###
cleanup() { cleanup() {
log_info "Theres a lot of beauty in ordinary things. Isnt that kind of the point?"
run_callbacks on_exit_ run_callbacks on_exit_
run_callbacks on_sys_exit_
} }
trap cleanup EXIT trap cleanup EXIT
@ -314,6 +329,7 @@ trap cleanup EXIT
reload_config() { reload_config() {
local setting setting_name local setting setting_name
run_callbacks on_sys_before_
run_callbacks on_before_ run_callbacks on_before_
for setting in "${!config[@]}"; do for setting in "${!config[@]}"; do
@ -335,10 +351,13 @@ trap reload_hup HUP
# initialization sequence # initialization sequence
### ###
run_callbacks on_sys_init_
run_callbacks on_init_ run_callbacks on_init_
if is_reloaded; then if is_reloaded; then
run_callbacks on_sys_after_
run_callbacks on_after_ run_callbacks on_after_
else else
run_callbacks on_sys_first_
run_callbacks on_first_ run_callbacks on_first_
fi fi