LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 12-05-2009, 03:40 AM   #1
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,466
Blog Entries: 6

Rep: Reputation: 51
Making a script start with service?


I have a script which I want to start as:
Code:
service service-name start
Is it enough to put the script under /etc/init.d/?
 
Old 12-05-2009, 03:48 AM   #2
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297
Hi,

No, it is not. Normally there is a file called skeleton in the /etc/init.d directory. You can use that as an example (or base) to create your own.

Kind regards,

Eric
 
Old 12-05-2009, 03:52 AM   #3
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,466

Original Poster
Blog Entries: 6

Rep: Reputation: 51
Dude,

I am using RHEL and it doesnt have that file(ASAIK)
 
Old 12-05-2009, 03:54 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

If you want to automatically start a service at (re)boot time you need to:

1) put the script in the init.d (depends on the distro if this is /etc/init.d or the correct /etc/rc.d/init.d),
2) make links to the appropriate runlevels.

Point number 2 can be done by hand, but most distro's have a utility for it. Red hat uses chkconfig. This would add the service to runlevels 3, 4 and 5: /sbin/chkconfig ––level 345 [name] on.

You mention more then one distro in your profile, so you need to check what the command is for your distro.

If you want to do it by hand:

cd /etc/rc.d/init.d
ln -s <service> ../rc3.d/SXXservice
ln -s <service> ../rc3.d/Kyyservice


The S reflect a start, the K reflects a kill. The xx and yy are numbers and point to the time the service needs starting (S10service will be started before S20service).

Hope this helps.
 
Old 12-05-2009, 03:59 AM   #5
rhadmn
Member
 
Registered: Oct 2009
Location: Bangalore
Distribution: Redhat Linux, Solaris, CentOS
Posts: 35

Rep: Reputation: 1
Hi,

Kindly requesting you to please update your exact requirement.Do u want the services to be started via the script ? If YES ..is there any specific days/time etc ?


Regards,
rhadmn
 
Old 12-05-2009, 03:59 AM   #6
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297
Quote:
Originally Posted by your_shadow03 View Post
Dude,

I am using RHEL and it doesnt have that file(ASAIK)
You didn't mention that now did you?

Then look at one of the scripts in there, copy it and edit to your likings. Then if you want to start it automatically at boot, follow the steps indicated by Druuna.

Kind regards,

Eric
 
Old 12-05-2009, 04:13 AM   #7
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,466

Original Poster
Blog Entries: 6

Rep: Reputation: 51
Guys,
I just have script which I want to start at boot time.
So what I understand is :
Code:
RHEL
------------------
#cp myscript /etc/init.d/
#chkconfig --level 345 myscript on
That's it Right?

All if I want to start I will do:
service myscript start
 
Old 12-05-2009, 04:17 AM   #8
EricTRA
LQ Guru
 
Registered: May 2009
Location: Gibraltar, Gibraltar
Distribution: Fedora 20 with Awesome WM
Posts: 6,805
Blog Entries: 1

Rep: Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297Reputation: 1297
Not very familiar with RedHat but in my opinion if you're giving a parameter 'start' to a command then that command must now what it has to do. If you just copy your script to the init.d directory and it's not written to accept arguments like start|stop and so on, then you'll not be able to execute:
Code:
service yourscript start
That's why I pointed you at the skeleton file. If that doesn't exist on your server then copy an existing one in that directory and change it to call your script.

Kind regards,

Eric
 
Old 12-05-2009, 04:19 AM   #9
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Maybe this article will help: Managing Initscripts with Red Hat's chkconfig

Hope this helps.
 
Old 12-05-2009, 04:35 AM   #10
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,466

Original Poster
Blog Entries: 6

Rep: Reputation: 51
Eric,

chkconfig --add myscript is something which will make this script work as service.

Thanks Druuna,.
 
Old 12-05-2009, 04:40 AM   #11
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,466

Original Poster
Blog Entries: 6

Rep: Reputation: 51
But when I did:

Code:
[root@rs init.d]# chkconfig --add myscript
service myscript does not support chkconfig
[root@rs init.d]#

I only wrote a script myscript:
#cat myscript
#!/bin/sh
service nfs stop
Am I doing anything wrong?

Surprisingly,

Code:
#service myscript start
Shutting down NFS mountd:                                  [  OK  ]
Shutting down NFS daemon:                                  [  OK  ]
Shutting down NFS services:                                [  OK  ]

When I ran the above command without chkconfig --add option.
It worked !!!

Last edited by your_shadow03; 12-05-2009 at 04:42 AM.
 
Old 12-05-2009, 04:45 AM   #12
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,466

Original Poster
Blog Entries: 6

Rep: Reputation: 51
Also,
I am unable to add up this service at boot time:

#chkconfig myscript on
service myscript does not support chkconfig
 
Old 12-05-2009, 04:47 AM   #13
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi again,

I think you need to add something like this to your script:

#chkconfig: 2345 80 05
#description: Oracle 8 Server


The second line is the discription, the first tells chkconfig which runlevels the script needs to start/stop the 80 and 05 in the example are the start (80 -> S80oracle) point and the stop point (K05oracle).

The above is (an obvious?) example....
 
Old 12-05-2009, 04:49 AM   #14
your_shadow03
Senior Member
 
Registered: Jun 2008
Location: Germany
Distribution: Slackware
Posts: 1,466

Original Poster
Blog Entries: 6

Rep: Reputation: 51
The Link:
http://blog.code-head.com/service-x-...port-chkconfig
saved my Day.
Thanks
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to register auto start/stop service script with chkconfig travellers Linux - Software 8 06-15-2009 11:02 AM
How to run a script that will automatically start FTP service after installation? reshmpv Linux - Newbie 2 08-18-2008 07:56 AM
script to start a service using ssh brazilian_user Linux - General 6 11-09-2006 11:14 AM
Making a program/service ( MySQL ) start up on boot ( FC3 ) karmazilla Fedora 6 06-27-2005 10:19 AM
write a script to start a service..how?? yenonn Linux - Newbie 6 05-26-2003 05:14 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration