How to use the daemon function in /etc/rc.d/init.d/functions
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How to use the daemon function in /etc/rc.d/init.d/functions
Hi,
I have a server program that is automatically started at startup. In my startup script I simply call the program. However, I would like a) to do things in as standard a way as possible b) have it verified that my program started by having a nice green [OK] at the right of the screen like everything else does.
I'm pretty sure I should be using the daemon function in /etc/rc.d/init.d/functions, but I can't find any documentation. Is it what I should be using and can anyone point me to a good manual or HOWTO, please?
The following is total guesswork. I think the daemon function will give me a nice green [OK] but it needs my program to store its pid in a file so that it can find the pid and know that my program has started. Am I right? If so, where does the pid file reside (typically if I do things in as standard way as possible)?
Is there anything else I need to know about using the daemon function?
Thank you. However, neither of these resources tell me what I need to know.
The first gives an example that uses daemon, but the only information it gives is
Quote:
The bash script functions daemon, killproc and status can all be found in the script /etc/rc.d/init.d/functions.
The second (which I came across earlier during my extensive Googling) also gives an example but is infuritaing in that it says
Quote:
The three functions I use in my script are killproc, status, and daemon. You have to be careful that you know both what the functions do, and what your application's default behavior is.
but doesn't give us that information or a link to where it can be found. It does give a snippet of info
Quote:
For example, the function that attempts to grab the PID of the running process, pidofproc, assumes that the process writes a pid file somewhere under /var/run.
but even that's incomplete. "Somewhere under /var/run"? Not complete documentation. My question is: where is the complete documentation?
pidofproc has a manpage. According to the manpage on my system, it checks for /var/run/<basename>.pid unless you supply the -p option to check a different location. If on your system, pidofproc is a bash function, it may be a wrapper that also looks in a directory, such as for /var/run/${basename%d}/${basename}.pid. You will need to read it to be certain. A functions script in /etc/init.d/ will probably be distro dependent. If there is a standard reference, you may try the Linux Standard Base. Also grep for function being called in scripts in /etc/init.d/. The usage will probably show you everything you want to know about the function.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.