LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Daemons and init script question (https://www.linuxquestions.org/questions/linux-newbie-8/daemons-and-init-script-question-608037/)

c_golan 12-20-2007 01:38 AM

Daemons and init script question
 
I have an executable (for example foo.exe) which listen to a port. This executable gets the port number as a parameter (only two ports are valid). Simultaneously two instances of the executable can run (each listen to a different port).
I tought using two different init scripts,different only in the port number they are passing to the executable.
My question:
what is the syntax of passing the parameter to the executable (the call to daemon - i'm using /etc/rc.d/init.d/functions)?

Please pay attention to the fact that I need also the ability to use stop for stopping the daemon but only the instance with the specific parameter (as the second one if running should keep running).

Thanks in advance

unSpawn 12-20-2007 01:55 AM

Initscripts often source an initscript config file in /etc/sysconfig, and there's nothing against making your own if it doesn't, so if you use a slightly different (initscript and) configname for the second instance you could source it with ". /etc/sysconfig/${daemonname}_one" in the initscript, use (example) "PORT=3000000" in "/etc/sysconfig/${daemonname}_one" and then use the $PORT variable in the initscript where it should be supplied. Don't forget to use chkconfig to add symlinks for runlevels.

c_golan 12-20-2007 03:07 AM

config file
 
OK - Let's say I'm using the config file. When the user wants to stop the specific instance of the daemon, he uses the initscript with the parameter "stop" and the daemon is "killed" according to the pid file.
But the problem is with the "status" - If I need to check if the specific instance is up, how should I check it only for the specific instance? Relying only on the specific pid or lock file is not good enough, since when the instance crashed for some reason, these files are not deleted altought the instance is down.

Any ideas?

Thanks

unSpawn 12-21-2007 04:32 AM

How about reworking the status to use 'pgrep -f' to find the commandline that includes $PORT? I know it works for me.

c_golan 12-22-2007 11:58 PM

Thanks. I'll try it.


All times are GMT -5. The time now is 06:51 PM.