![]() |
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Start a service as user | potro | Shell Programming and Scripting | 5 | 04-17-2008 02:19 AM |
| How to supress a UI popup at the time of Service start up in solaris-10 | krevathi1912 | SUN Solaris | 5 | 11-24-2007 02:20 PM |
| Unable to start cluster service in redhat 5 | santhoshb | Red Hat | 0 | 08-07-2007 07:19 AM |
| Need help making a script | npereira | Shell Programming and Scripting | 2 | 01-06-2007 01:14 PM |
| AIX 5.3: Start Service on System startup | dennis.kuehl | UNIX for Advanced & Expert Users | 1 | 07-25-2006 03:32 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
||||
|
Making a Script to Start as a Service
Hi,
I have a shell script t1.sh. on my solaris box. So, what are the steps required to make this script run as a Service, when the system re-starts. (for ex:- at run level 3). I know that I should use the rc.d folders. But I don't know the exact steps. Kindly explain, Thanks in Advance. Vishwa. |
|
||||
|
Quote:
Do not put the script in the /etc/rc2.d directory, but in the /etc/init.d directory. In /etc/rc2.d you create a link to the script in /etc/init.d The script t1.sh should like something like this. #!/bin/sh # it is common to write start stop scripts in the bourne shell # for scripts which are started after all file systems are mounted it doesn't # really matter. For scripts which are started before, you could end up with # a problem if that shell is located on a filesystem different than "/" case $1 in start) # your code to start the service ;; stop) # your code to stop the service esac or use functions #!/usr/bin do_start() { # your code to start the service } do_stop() ( # your code to stop the service } case $i in start) do_start ;; stop) do_stop ;; esac Next you create a link in the /etc/rc2.d directory ln -s /etc/init.d/t1.sh /etc/rc2.d/S99t1.sh In general files in the /etc/rc<num>.d directory look like: Snn<name> Knn<name> The S indicates the service should be started. The K indicates the service should be stopped. nn are 2 digits, and they indicate the order in which services are started or stopped. Like indicated, 99 would be fine, that way your service is started after all other services. <name> is usually the same as the name of the script in the /etc/init.d directory. if /etc/rc2.d/S99t1.sh is linked to /etc/init.d/t1.sh the boot sequence will make sure that when entering run level 2 (that is why the link is in the rc2.d directory), the script /etc/init.d/t1.sh is started with the argument start. Similar the boot sequence will make sure that all links in a rc<num>.d directory which start with a K will result in executing the script in the /etc/init.d directory they are linked to with as argument "stop" upon entering the run level <num>. Depending on what kind of service your script will start it is proper to have a "kill" link as well. Suppose the service is a database, you want the database to be shut down properly, when the system goes down. To accomplish that you create a K01t1.sh link to /etc/init.d/t1.sh in /etc/rc1.d and/or rc0.d The reason to put the script in the /etc/init.d directory and to create links in the /etc/rc<num>.d directory is that you do not want to have several copies of the same script in those directories. Instead you use links. This way, if you want to change your script, you only need to change it in /etc/init.d Too often it happens that people put the scripts themselves in several /etc/rc<num>.d directories. And after 2 years not even 2 of those copies are identical any more. /etc/init.d and /etc/rc<num>.d should be used as they are intented to be used. T |
|
||||
|
how
hi all
but how it is possible. it is not working well. my application is 'example' how can i run this is in startup. it contains the code #!bin/sh cd /bin ./example i am using fedora4 can you please show me the way thank you in advance |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|