LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-10-2014, 01:28 AM   #1
gillecaluim
LQ Newbie
 
Registered: Oct 2014
Posts: 2

Rep: Reputation: Disabled
centos init.d script PIPESTATUS


I'm trying to tweak a wpa_supplicant init.d script and can't figure out why I can't get the green [OK] to show even though the start script is successful. Here's the start block:

exec="/usr/sbin/wpa_supplicant"
prog=$(basename $exec)
conf="/etc/wifi.conf"
lockfile=/var/lock/subsys/$prog
interface="wlan0"

[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

start() {
echo -n $"Starting wifi service on wlan0 ..."
ifdown wlan0
$prog -c $conf -i $interface -B > dev/null 2>&1
retval=${PIPESTATUS[0]}
echo
[ $retval -eq 0 ] && touch $lockfile
return $retval
}

if I get rid of the > dev/null 2>&1 and set retval=$? the green [OK] is displayed along with some non-critical warnings

I've tested ${PIPESTATUS[0]} and it is 0...meaning success but the green [OK] doesn't show.

I know this isn't really all that important but I want to know why this doesn't work?

Last edited by gillecaluim; 10-10-2014 at 01:30 AM.
 
Old 10-10-2014, 01:18 PM   #2
gillecaluim
LQ Newbie
 
Registered: Oct 2014
Posts: 2

Original Poster
Rep: Reputation: Disabled
Solved

Well I finally realized the problem with generating the init.d green [OK]. the success/failure of running the program is checked within the daemon or killproc function (contained within /etc/rc.d/init.d/functions ) rather than taking the return exit code of the init.d script.
so, to fix this here is my revised startup script:

...
exec="/usr/sbin/wpa_supplicant"
prog=$(basename $exec)
conf="/etc/wifi.conf"
lockfile=/var/lock/subsys/$prog
interface="wlan0"

[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog

start() {
echo -n $"Starting wifi service on "$interface" ..."
ifdown wlan0
daemon $prog -c $conf -i $interface -B > dev/null 2>&1
retval=${PIPESTATUS[0]}
[ $retval -eq 0 ] && daemon touch $lockfile
echo
[ $retval -eq 0 ] && ifup $interface
[ $retval -eq 0 ] && tail -n 16 /var/lib/dhclient/dhclient-wlan0.leases | head -n 12
return $retval
}
...

as you can see I've checked the return status of daemon wpa_supplicant with the PIPESTATUS[0] and then use to start everything else up if successful. Notice I've used daemon touch $lockfile, which generates the green [OK] for me. Hope this helps anyone else in the mystery of the init.d scripts
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] why init script cannot source init tools unless session root linuxecho Linux - Newbie 8 02-17-2014 06:17 PM
understanding $PIPESTATUS Garrett85 Programming 3 10-31-2012 11:16 AM
[SOLVED] Bash Shell - PIPESTATUS mrm5102 Linux - Newbie 3 04-07-2011 09:40 AM
[SOLVED] init script, centos/rhel, lighttpd, specify user s2cuts Linux - General 2 10-02-2009 08:31 PM
CentOS 4 (Fedora Core) init script - create PID file cejennings_cr Linux - Newbie 1 07-10-2006 09:22 AM


All times are GMT -5. The time now is 03:43 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration