LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Making a script start with service? (https://www.linuxquestions.org/questions/linux-newbie-8/making-a-script-start-with-service-773628/)

your_shadow03 12-05-2009 03:40 AM

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/?

EricTRA 12-05-2009 03:48 AM

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

your_shadow03 12-05-2009 03:52 AM

Dude,

I am using RHEL and it doesnt have that file(ASAIK)

druuna 12-05-2009 03:54 AM

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.

rhadmn 12-05-2009 03:59 AM

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

EricTRA 12-05-2009 03:59 AM

Quote:

Originally Posted by your_shadow03 (Post 3780682)
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

your_shadow03 12-05-2009 04:13 AM

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

EricTRA 12-05-2009 04:17 AM

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

druuna 12-05-2009 04:19 AM

Hi,

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

Hope this helps.

your_shadow03 12-05-2009 04:35 AM

Eric,

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

Thanks Druuna,.

your_shadow03 12-05-2009 04:40 AM

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 !!!


your_shadow03 12-05-2009 04:45 AM

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

#chkconfig myscript on
service myscript does not support chkconfig

druuna 12-05-2009 04:47 AM

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....

your_shadow03 12-05-2009 04:49 AM

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


All times are GMT -5. The time now is 03:27 PM.