LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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-19-2016, 08:23 AM   #1
NotionCommotion
Member
 
Registered: Aug 2012
Posts: 789

Rep: Reputation: Disabled
When should functions be used in shell script?


Often I see functions inserted into a daemon shell script. For instance, consider the following two.

Code:
. /etc/rc.d/init.d/functions
Reference my 2.2 Apache script /etc/init.d/httpd

Code:
. /lib/lsb/init-functions
Reference http://www.thegeekstuff.com/2012/03/lsbinit-script/


What are the difference between these two libraries(?) that are being inserted? How does one determine which should be used? I don't seem to have /lib/lsb/... on my Centos box. Am I missing something?


Also, within the shell script, how are these functions being used? For instance, within /etc/rc.d/init.d/functions, I see kilproc() {...}, and within /etc/init.d/httpd, I see the following two lines of code.

Code:
killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd
LSB=1 killproc -p ${pidfile} $httpd -HUP
Thank you
 
Old 10-19-2016, 09:16 AM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,912

Rep: Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513Reputation: 1513
Part of the problem you are having is that RH doesn't follow the LSB.

The next part depends on which CentOS version you are using - RH/CentOS as of release 7, no longer use either one. They are using systemd run units instead, and not using init.d for anything, and are not using shell scripts.

The intent of the functions is to provide a common method of interfacing with the init process and interfacing with the administrator. Because the two different methods are available, it all depends on which "standard" you follow.
 
Old 10-19-2016, 09:49 AM   #3
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,785
Blog Entries: 19

Rep: Reputation: 4525Reputation: 4525Reputation: 4525Reputation: 4525Reputation: 4525Reputation: 4525Reputation: 4525Reputation: 4525Reputation: 4525Reputation: 4525Reputation: 4525
The init functions in lib usually handle satellite scripts like the ifup and ifdown commands. The ones in /etc are for the actual startup scripts.

Last edited by hazel; 10-19-2016 at 09:52 AM.
 
  


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
Shell script or scripts which can do some functions Amerika Linux - Newbie 17 08-14-2011 11:11 AM
How to properly exit functions in Shell Script? Jude Terror Programming 5 01-27-2009 03:15 PM
passing parameters to functions in shell script kushalkoolwal Programming 1 09-28-2005 02:40 PM
shell script functions iNET_boss Linux - General 1 08-10-2005 04:41 PM
PHP -- How to execute a shell script from PHP using FTP functions?? zoonalex Programming 3 07-29-2004 11:51 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:24 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
Open Source Consulting | Domain Registration