Making a Script to Start as a Service


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Making a Script to Start as a Service
# 1  
Old 01-22-2007
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  
Old 01-23-2007
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  
Old 01-24-2007
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  
Old 02-08-2007
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
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. AIX

Start script or service with boot on AIX 7.2

I have installed apache2, but not run with boot in AIX 7.2, how to make it run ? in AIX 7.1 i used : mkitab "apache:2:once:/usr/IBMAHS/bin/apachectl start > /dev/null 2>&1" ### ---> not work in AIX 7.2 (i use 0 in once, because appear emoticon when use :once) Did you know that you can use... (4 Replies)
Discussion started by: penchev
4 Replies

2. Solaris

How to make SMF service start last?

I need to start a service among the last on a freshly booted system. Via the manifest, I've made it dependent on very milestone on the computer yet the service still comes back with an error that a kstat variable in the kernel does not exist. I run it right the service process right there... (6 Replies)
Discussion started by: JWH
6 Replies

3. Shell Programming and Scripting

not able to start xvfb service via rc script

Hi , I am having this start script to start xvfb under rc3.d but it fails during system startup saying unable to open display. also manually if i try to execute the script , it does not work. But if i execute what ever is there in the script line by line on my SHELL , it starts well. ... (2 Replies)
Discussion started by: chidori
2 Replies

4. Red Hat

Can't start NTOP service/daemon

I have installed version of ntop 4.0.3 by guide. But I can't start ntop daemon/service. I didn't find a service file for starting. During the installation there was no problem only want to RRDTool so I installed that. Now there is no necessary package required. I didn't find in /etc/init.d/... (9 Replies)
Discussion started by: getrue
9 Replies

5. Red Hat

VSFTPD Service Failed to Start

Today I have installed VSFTPD but service is failing to start. We have been using standard FTP successful but need to introduce an FTPS option. I have run YUM install VSFTPD and everything appeared to load ok. (If I run rpm - qa | grep vsftpd I get vsftpd-2.0.5-16.el5_4.1 which I... (4 Replies)
Discussion started by: PaulComins
4 Replies

6. Red Hat

vsftpd service failed to start

hi, i am using RHEL 5 and i am not able to on the vsftp i have tried to on the vsftp service using command service vsftpd start Starting vsftpd for vsftpd: i am posting the content of my /etc/xinetd.d/vsftpd file # description: The vsftpd FTP... (2 Replies)
Discussion started by: u.n.i.x
2 Replies

7. UNIX for Dummies Questions & Answers

Need help making a start/stop script...

i have two separate scripts that work nicely to curl and generate two files.. one html and one txt so a total of four. When the script starts up i want it to: call and run shellscripta call and run shellscriptb sleep for about 40 seconds again run shellscripta again run shellscriptb check... (4 Replies)
Discussion started by: phpfreak
4 Replies

8. AIX

Q: how to start a service when system start

As topic, assume we have a service called "blahservice" and we can start it by: startsrc -s blahservice what is the best practice to run such command when system start? - directly use mkitab to add it into /etc/inittab or - drop startup scripts in /etc/rc.d/rcX.d I know they... (4 Replies)
Discussion started by: acerlinux
4 Replies

9. Shell Programming and Scripting

Start a service as user

Hi I need a service to be start as user after a reboot. My script in /etc/init.d contain the following: start() { su - $USER cd ${INSTALL_PATH}/bin ./MyApp -X exit return 0 } This function stops after su - $USER, I get user shell, and only if I manualy... (5 Replies)
Discussion started by: potro
5 Replies
Login or Register to Ask a Question