Ubuntu equivalent of CentOS success / failure
I think the functions you are looking for are sourced from /lib/lsb/init-functions
, and named log_success_msg
and log_failure_msg
:
$ . /lib/lsb/init-functions
$ log_success_msg foo
* foo
$ log_failure_msg foo
* foo
In this output, the first *
is grey, the second is red (error case). Not extremely colorful, just enoug to get the point across...
From /lib/lsb/init-functions
:
[ ... ]
log_success_msg () {
if [ -n "${1:-}" ]; then
log_begin_msg $@
fi
log_end_msg 0
}
log_failure_msg () {
if [ -n "${1:-}" ]; then
log_begin_msg $@ "..."
fi
log_end_msg 1 || true
}
[ ... ]
You could use the functions provided by the lsb-base
package in /lib/lsb/init-functions
. I have seen init.d
scripts sourcing that file and then using the functions within, such as log_end_msg
:
$ (. /lib/lsb/init-functions; log_end_msg 1)
...fail!
$ (. /lib/lsb/init-functions; log_end_msg 0)
...done.
For example, a snippet from /etc/init.d/ssh
(case
for start
):
if start-stop-daemon --start --quiet --oknodo --pidfile /var/run/sshd.pid --exec /usr/sbin/sshd -- $SSHD_OPTS; then
log_end_msg 0 || true
else
log_end_msg 1 || true
fi