LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   write a script to start a service..how?? (https://www.linuxquestions.org/questions/linux-newbie-8/write-a-script-to-start-a-service-how-61796/)

yenonn 05-25-2003 08:39 PM

write a script to start a service..how??
 
i have done a squid installation and it was working quite ok for the time being.
now, i want to create a starting script and put it into directory /etc/rc.d/init.d, such that it will auto-start when the machine is booting.
so, the question is that any idea in creating this kind of script. where should i refer to? any example of script to let me customize it in order to suit my need? i never have experiences before this.

thanks!!!!

Azmeen 05-25-2003 08:52 PM

create a text file and write this in it:

Code:

#!/bin/bash

/path/to/your/app --with-whatever --flags

That's be basic structure... you can use different shells at the shebang (the #!/bin/bash part in the example above).

whansard 05-25-2003 08:53 PM

create a text file of what you would have
to type to start squid and save it in init.d as
a name you would remember. like squidder.
use chmod +x filename to make the file
executable.
in the runlevel that you use. maybe 3,
make a softlink from inside /etc/rc.d/rc.d
to the file squidder, called S99squidder
like
ln -s /etc/rc.d/init.d/squidder /etc/rc.d/rc.3/S99squidder
then it will start last in runlevel 3

yenonn 05-25-2003 09:12 PM

what is the purpose of having a starting point at runlevel 3??
then, what if i want to stop the service when the system is shutting down?
will this my squid service be listed in "Service" screen list?
and how to make stop, restart function for that service?
thanks!

whansard 05-25-2003 09:20 PM

i just guessed that your default runlevel is 3.
to make a start stop and restart service is more
complicated.
take one of the other scripts in /etc/init.d, copy it
and rename it, and edit it to suit your needs.
to have a service specifcally killed in a runlevel,
like shutdown which is 6, you make a link to a script
that kills squid, or you make your script more complex,
so that it checks how it is called.
start the kill script name with K.

yenonn 05-25-2003 09:37 PM

how to determine my runlevel is 3? any command prompt that will comfirm my runlevel? confusing... u mean my script will content start, restart and stop command prompts...
and then, i have to make a link to rc.3 for start and restart purposes, subsequently, i have to make another link to rc.6 for stop purpose, with prefix "k" for that link's name?
i have took a glance over the rest of the scripts in /etc/rc.d/init.d. they are all look complicated... i have no idea in how to edit them...can u give an example of script that will showing a skeleton on how to customize it? thanks again!!!!!

Azmeen 05-26-2003 05:14 AM

Runlevel 3 is the default runlevel during multi-user bootup. ie. if you bootup "normally", you'll be at runlevel 3.

To edit your rc.3 script, just open it up and insert this line:

/path/to/squid --arguments

where /path/to/squid is the full path to this squid application, and --arguments is any additional arguments you need to append to it (not necessary depending on how you normally run squid).


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