Linux Forums - Linux Help,Advice & support community:LinuxSolved.com

Linux in General => Linux Development & Programming => Topic started by: sridip on August 10, 2005, 10:07:05 AM

Title: How to run a shell script using service command
Post by: sridip on August 10, 2005, 10:07:05 AM
I want to run a shell script using service command
as service <script> start
    service <script> stop
how can i do this ?
Title: using service
Post by: misterscorp on October 07, 2005, 04:45:10 PM
Hi,
  Just write the script to do your specific function & put the shell file in the /etc/rc.d/ directory
  Before writing the script file just get a glance of how the other service deamons are written. For example if you have webmin(Administration tool) installed in your linux box you can go and find its script in /etc/rc.d/rc5.d/
the name of the file would be S99webmin
plz do read that file. You will get the idea how they are invoking a deamon using service command. Actually they will be having a seperate file that can handle the start|stop|restart and how these functionalities are acheived can be better undestood if you read that script file.


I think this would have satisfied your questions,
 :D :D  8)
Title: How to run a shell script using service command
Post by: dragoncity99 on May 07, 2006, 01:13:36 PM
Ok make sure u know what u r doing sridip.

U must make sure ur Linux distro is either using

System V or BSD style of managing runlevel.

System V is normally used, coz it's cool way of handling runlevels.

BSD which is used by Slackware is different.


I suggest u do a reading first on this topic. If ur using distros such as RedHat/SUSE which uses System V,

U need to add ur script into /etc/rc.d/init.d directory.

/etc/rc0.d
/etc/rc1.d
/etc/rc2.d
/etc/rc3.d
/etc/rc4.d
/etc/rc5.d
are all symbolics to that script in /etc/rc.d/init.d

u don't have to manually create it. There are tools that help u to do it, if ur using Redhat
Title: How to run a shell script using service command
Post by: dragoncity99 on May 07, 2006, 01:17:10 PM
Sorry for reposting, but if u want to just get things done and not challenging urself or being curious, a QUICK FIX, will be:

1. Run the script in background
# ./yourShellScript.sh &

2. That's it. If you wanna stop it, u can just find the PID, using:
# ps aux | grep yourShellScript.sh

3. Kill the pid:
# kill -9 PID-OF-YOUR-SHELL-SCRIPT