The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
.
google unix.com



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

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 01-22-2007
S.Vishwanath S.Vishwanath is offline
Registered User
  
 

Join Date: Jan 2001
Posts: 48
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.
  #2 (permalink)  
Old 01-23-2007
tayyabq8's Avatar
tayyabq8 tayyabq8 is offline Forum Advisor  
Moderator
  
 

Join Date: Nov 2004
Location: Bahrain
Posts: 578
Two ways to acheive this:

1) Put your shell commands in a startup file in /etc/rc2.d directly, keep in mind that files residing in /etc/rc2.d follow some rules i.e. filenames starting with S are startup scripts while starting with K are kill scripts, after S or K prefix there comes a 2 digit number like S10 or S65, it tells rc the sequence of startup scripts, so I'll suggest you to give it a name like S99xyz so that it runs in the last and doesn't disturb any other sequence and also is displayed at the bottom of the list of directory.

2)Second way is that create a symbolic link for your script suppose it is at path /home/t1.sh and /etc/rc2.d/S99t1.sh(Startup file)

Choose the best which suits your situation.

Regards,
Tayyab
  #3 (permalink)  
Old 01-24-2007
sb008 sb008 is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 384
Quote:
Originally Posted by tayyabq8
Two ways to acheive this:

1) Put your shell commands in a startup file in /etc/rc2.d directly, keep in mind that files residing in /etc/rc2.d follow some rules i.e. filenames starting with S are startup scripts while starting with K are kill scripts, after S or K prefix there comes a 2 digit number like S10 or S65, it tells rc the sequence of startup scripts, so I'll suggest you to give it a name like S99xyz so that it runs in the last and doesn't disturb any other sequence and also is displayed at the bottom of the list of directory.

2)Second way is that create a symbolic link for your script suppose it is at path /home/t1.sh and /etc/rc2.d/S99t1.sh(Startup file)

Choose the best which suits your situation.

Regards,
Tayyab

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
  #4 (permalink)  
Old 02-08-2007
munna_dude munna_dude is offline
Registered User
  
 

Join Date: Jan 2007
Posts: 21
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
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 05:15 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0