Make the init.d scripts messages fancier by prepending them a [....] block.
authorDidier Raboud <odyx@debian.org>
Fri, 30 Mar 2012 12:48:42 +0000 (14:48 +0200)
committerDidier Raboud <odyx@debian.org>
Sat, 31 Mar 2012 16:46:19 +0000 (18:46 +0200)
== 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 <alga777@gmail.com>
Not-used-but-useful-patch-by: Alessio <alga777@gmail.com>
Not-used-but-useful-patch-by: Nico Golde <nion@debian.org>
Idea-by: Mehdi Dogguy <mehdi@debian.org>
Signed-off-by: Didier Raboud <odyx@debian.org>
debian/lsb-base.NEWS [new file with mode: 0644]
debian/lsb-base.README.Debian
init-functions

diff --git a/debian/lsb-base.NEWS b/debian/lsb-base.NEWS
new file mode 100644 (file)
index 0000000..67e0632
--- /dev/null
@@ -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 <odyx@debian.org>  Sat, 31 Mar 2012 17:06:27 +0200
index c10d8275922c2a8926c13e1d3a37306c9b83098c..ed4911bbb4be53e743f32db8424b679eb723849b 100644 (file)
@@ -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
index 3be5648fb3cf9e1fdcd10901f1493035456741f4..91a79b48e7c0bf1c7dc00c4bb35f28cad3bb02ce 100644 (file)
@@ -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=