From dcac6db7d7b5431c3c568508d1c279d18b9a084c Mon Sep 17 00:00:00 2001 From: Didier Raboud Date: Fri, 30 Mar 2012 14:48:42 +0200 Subject: [PATCH] Make the init.d scripts messages fancier by prepending them a [....] block. == Implementation == * The logging functions assign the status block as "[....]" when printing the log message. Concerned functions: - log_daemon_msg - log_action_begin_msg - log_begin_msg (despite not being a documented interface) * The log message conclusion functions replace the status block by either a green [ ok ], a yellow [warn] or a red [FAIL] by Concerned functions: - log_end_msg This is implemented as _pre/_post functions. == Documentation == * lsb-base.README.Debian is updated with the new _pre/_post functions. * lsb-base.NEWS gets a new entry with information meant for experimental users and init.d scripts maintainers. == Pseudo-headers == Closes: #416485 Reported-by: Alessio Not-used-but-useful-patch-by: Alessio Not-used-but-useful-patch-by: Nico Golde Idea-by: Mehdi Dogguy Signed-off-by: Didier Raboud --- debian/lsb-base.NEWS | 47 +++++++++++++++++++++++++++++++++++ debian/lsb-base.README.Debian | 4 +++ init-functions | 44 +++++++++++++++++++++++++++++--- 3 files changed, 92 insertions(+), 3 deletions(-) create mode 100644 debian/lsb-base.NEWS diff --git a/debian/lsb-base.NEWS b/debian/lsb-base.NEWS new file mode 100644 index 0000000..67e0632 --- /dev/null +++ b/debian/lsb-base.NEWS @@ -0,0 +1,47 @@ +lsb (4.1+Debian0+) UNRELEASED; urgency=low + + This version implements a new "fancy" output in the form of "[....] " + blocks prepended to the daemon status messages: + + Before: + Starting/stopping long daemon name: daemond daemon2d + After: + [....] Starting/stopping long daemon name: daemond daemon2d + + This block will become either a green [ ok ], a yellow [warn] + or a red [FAIL] depending on the daemon exit status. + + == How do I disable this? == + + This is currently implemented in /lib/lsb/init-functions as _pre and + _post functions. As such, they are overridable as function definitions + in the /etc/lsb-base-logging.sh configuration file; for example: + + log_daemon_msg_pre () { :; } + + It is also possible to completely disable the "Fancy output" by setting + the FANCYTTY variable to 0 in the same file. + + == Known bugs and plan for inclusion in unstable == + + * Daemons writing too much information on the screen (hence getting + their output spawned on multiple lines) won't get their [....] + replaced by [ ok ] as the replacement will happen on the last input + line. + * The above has the side-effect of hiding 7 characters of potentially + useful output. + * init.d scripts not using the /lib/lsb/init-functions provided + functions will (obviously) not get the fancy output. + + Feedback, ideas and help are welcome as bugs on the lsb-base package. + + Before including this change to unstable, the following changes will + most probably happen: + + * The implementation will move from _pre/_post functions to the + functions themselves. This is safe-guarded by the FANCYTTY global + variable anyway. + * The information from this NEWS file will get moved to README.Debian + (hence avoiding the gory details to stable-upgrading users). + + -- Didier Raboud Sat, 31 Mar 2012 17:06:27 +0200 diff --git a/debian/lsb-base.README.Debian b/debian/lsb-base.README.Debian index c10d827..ed4911b 100644 --- a/debian/lsb-base.README.Debian +++ b/debian/lsb-base.README.Debian @@ -165,6 +165,10 @@ logging functions: log_daemon_msg_pre log_daemon_msg_post +log_begin_msg_pre (since 4.1+Debian0+) +log_begin_msg_post (since 4.1+Debian0+) +log_action_begin_msg_pre (since 4.1+Debian0+) +log_action_begin_msg_post (since 4.1+Debian0+) log_end_msg_pre log_end_msg_post log_action_end_msg_post diff --git a/init-functions b/init-functions index 3be5648..91a79b4 100644 --- a/init-functions +++ b/init-functions @@ -260,10 +260,12 @@ get_lsb_header_val () { # int log_begin_message (char *message) log_begin_msg () { + log_begin_msg_pre "$@" if [ -z "${1:-}" ]; then return 1 fi /bin/echo -n "$@" + log_begin_msg_post "$@" } # Sample usage: @@ -358,7 +360,9 @@ log_action_msg () { } log_action_begin_msg () { + log_action_begin_msg_pre "$@" /bin/echo -n "$@..." + log_action_begin_msg_post "$@" } log_action_cont_msg () { @@ -389,11 +393,45 @@ log_action_end_msg () { } # Hooks for /etc/lsb-base-logging.sh -log_daemon_msg_pre () { :; } +log_daemon_msg_pre () { + if log_use_fancy_output; then + /bin/echo -n "[....] " + fi +} log_daemon_msg_post () { :; } -log_end_msg_pre () { :; } +log_begin_msg_pre () { + log_daemon_msg_pre "$@" +} +log_begin_msg_post() { :; } +log_end_msg_pre () { + if log_use_fancy_output; then + RED=$( $TPUT setaf 1) + GREEN=$( $TPUT setaf 2) + YELLOW=$( $TPUT setaf 3) + NORMAL=$( $TPUT op) + + $TPUT sc + $TPUT hpa 0 + /bin/echo -n "[" + if [ $1 -eq 0 ]; then + /bin/echo -ne "${GREEN} ok " + elif [ $1 -eq 255 ]; then + /bin/echo -ne "${YELLOW}warn" + else + /bin/echo -ne "${RED}FAIL" + fi + /bin/echo -ne "${NORMAL}]" + $TPUT rc + fi +} log_end_msg_post () { :; } -log_action_end_msg_pre () { :; } +log_action_begin_msg_pre () { + log_daemon_msg_pre "$@" +} +log_action_begin_msg_post () { :; } +log_action_end_msg_pre () { + log_end_msg_pre "$@" +} log_action_end_msg_post () { :; } FANCYTTY= -- 2.30.2