Monday, May 13, 2024
8
rated 0 times [  8] [ 0]  / answers: 1 / hits: 4262  / 2 Years ago, thu, september 1, 2022, 10:12:11

A lot of services in CentOS look like this (except green and red, respectively):



$ sudo service blah start
Starting blah: [ OK ]
$ sudo service notrunning stop
Stopping notrunning: [FAILED]


This happens because the /etc/init.d scripts use utility scripts in /etc/rc.d/init.d/functions called success and failure. Here's a snippet from /etc/init.d/sshd in CentOS:



echo -n $"Starting $prog: "
$SSHD $OPTIONS && success || failure


My question is: is there a ubuntu equivalent? I could copy the scripts over, but they're more complicated than you'd think, and why reinvent the wheel if I don't have to?


More From » command-line

 Answers
0

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
}

[ ... ]

[#22978] Friday, September 2, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mance

Total Points: 198
Total Questions: 105
Total Answers: 128

Location: South Georgia
Member since Mon, Aug 16, 2021
3 Years ago
;