FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > CentOS > CentOS

 
 
LinkBack Thread Tools
 
Old 11-21-2010, 11:19 PM
Kill Script
 
Default best way to start and shutdown programs in CentOS?

I have a Java program that I want to start up with every boot, but I'm unsure how to do it.
There are two bootup scripts that start manually (script1.sh and script2.sh), and when the server gets shutdown, we have another script that we run (shutdownscript.sh) so that the DB does not get corrupted.



_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 11-22-2010, 12:10 AM
Les Mikesell
 
Default best way to start and shutdown programs in CentOS?

On 11/21/10 6:19 PM, Kill Script wrote:
> I have a Java program that I want to start up with every boot, but I'm unsure
> how to do it.
>
> There are two bootup scripts that start manually (script1.sh and script2.sh),
> and when the server gets shutdown, we have another script that we run
> (shutdownscript.sh) so that the DB does not get corrupted.
>

The RedHat/Centos way of doing things is to have init scripts in
/etc/rc.d/init.d that take at least start, stop, and restart as arguments for
each program that should start automatically. Then for the runlevels where you
want them to start you have a symlink where the name starts with S and the rest
is a number to make it sort alphabetically into the order that things should
start in /etc/rc?.d (where the ? is the runlevel). Likewise add links starting
with 'K' in the levels where the process should be stopped. There is a
convention for comments in the scripts so that 'checkconfig program on' can make
the links for you. Look through some of the other scripts to see how they work.

--
Les Mikesell
lesmikesell@gmail.com
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 11-22-2010, 12:10 AM
Jorge Fábregas
 
Default best way to start and shutdown programs in CentOS?

On Sunday 21 November 2010 20:19:59 Kill Script wrote:
> I have a Java program that I want to start up with every boot, but I'm
> unsure how to do it.

Put the call to your script on this file:

/etc/rc.d/rc.local


HTH,
Jorge
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 11-22-2010, 12:18 AM
John R Pierce
 
Default best way to start and shutdown programs in CentOS?

On 11/21/10 4:19 PM, Kill Script wrote:
> I have a Java program that I want to start up with every boot, but I'm
> unsure how to do it.
>
> There are two bootup scripts that start manually (script1.sh and
> script2.sh), and when the server gets shutdown, we have another script
> that we run (shutdownscript.sh) so that the DB does not get corrupted.
>

centos uses sysVinit.

you would create a script in /etc/rc.d/init.d/ called yourjavathing,
which takes the parameter {start|stop} and optionally
{reload|restart|status} ... this script would include the header lines
for chkconfig. its run by init as the root user (but without any user
login profiles). If you want your javathing to run as a different
user, you should invoke your script1.sh and script2.sh via su someuser
-c "/path/to/script1.sh" ...

once this script exists, and you test it by invoking it as
"/etc/rc.d/init.d/yourjavathing start" (and "... stop", etc), then

chkconfig --on yourjavathing

will configure the OS to run it automatically at the runlevels that your
chkconfig header lines specify. and,

service yourjavathing start

(or stop, etc) will manually start and stop the service.
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 11-22-2010, 01:20 AM
Kill Script
 
Default best way to start and shutdown programs in CentOS?

On Sun, Nov 21, 2010 at 8:18 PM, John R Pierce <pierce@hogranch.com> wrote:

you would create a script in /etc/rc.d/init.d/ * called yourjavathing, which takes the parameter {start|stop} and optionally {reload|restart|status} ... *this script would include the header lines for chkconfig. * its run by init as the root user (but without any user login profiles). * If you want your javathing to run as a different user, you should invoke your script1.sh and script2.sh via su someuser -c "/path/to/script1.sh" ...

Thank you! This was very helpful.*


once this script exists, and you test it by invoking it as "/etc/rc.d/init.d/yourjavathing start" (and "... stop", etc), then



* * chkconfig --on yourjavathing



will configure the OS to run it automatically at the runlevels that your chkconfig header lines specify. *and,



* *service yourjavathing start



(or stop, etc) will manually start and stop the service.

Googling, I found this example: *
http://www.linuxjournal.com/article/4445

and I think that I can easily modify this Oracle init.d example
http://www.linuxjournal.com/files/linuxjournal.com/linuxjournal/articles/044/4445/4445l1.html


_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 11-22-2010, 01:36 PM
Brian Mathis
 
Default best way to start and shutdown programs in CentOS?

2010/11/21 Jorge Fábregas <jorge.fabregas@gmail.com>:
> On Sunday 21 November 2010 20:19:59 Kill Script wrote:
>> I have a Java program that I want to start up with every boot, but I'm
>> unsure how to do it.
>
> Put the call to your script on this file:
>
> /etc/rc.d/rc.local
>
>
> HTH,
> Jorge

It may be tempting to use the rc.local, but that's the quick and dirty
way and not good for the long-term sustainability and management of a
system. There's no way to individually control any service running
from there, and no way to stop it on shutdown.
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 11-22-2010, 06:37 PM
Kill Script
 
Default best way to start and shutdown programs in CentOS?

On Mon, Nov 22, 2010 at 9:36 AM, Brian Mathis <brian.mathis@gmail.com> wrote:

It may be tempting to use the rc.local, but that's the quick and dirty

way and not good for the long-term sustainability and management of a

system. *There's no way to individually control any service running

from there, and no way to stop it on shutdown.

Yeah, thank you. *I talked with the person who wrote the Java program, and he essentially said the same thing.
I'm looking through his suggestions now, and he suggested a shutdown script. I others who have examples with pid.txt and "dirname $0". *Not sure what these are and am googling them now.

_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 11-22-2010, 07:04 PM
Les Mikesell
 
Default best way to start and shutdown programs in CentOS?

On 11/22/2010 1:37 PM, Kill Script wrote:
>
>
> It may be tempting to use the rc.local, but that's the quick and dirty
> way and not good for the long-term sustainability and management of a
> system. There's no way to individually control any service running
> from there, and no way to stop it on shutdown.
>
>
> Yeah, thank you. I talked with the person who wrote the Java program,
> and he essentially said the same thing.
>
> I'm looking through his suggestions now, and he suggested a shutdown
> script. I others who have examples with pid.txt and "dirname $0". Not
> sure what these are and am googling them now.

Standard init scripts use some common functions to write the process ID
of the running program in a standard place so the 'stop' operation can
find it. A side effect of this is that if you have multiple instances
of a program running you have to have separate init scripts with
different names to control them. Also, you generally need root access
to start/stop with this facility. If your program doesn't otherwise
need root access and you want an ordinary user to have control you may
want to do it some other way.

--
Les Mikesell
lesmikesell@gmail.com
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 11-22-2010, 10:24 PM
Jorge Fábregas
 
Default best way to start and shutdown programs in CentOS?

On Monday 22 November 2010 10:36:31 Brian Mathis wrote:
> It may be tempting to use the rc.local, but that's the quick and dirty
> way and not good for the long-term sustainability and management of a
> system. There's no way to individually control any service running
> from there, and no way to stop it on shutdown.

I totally agree. My suggestion was based on the assumption that the OP didn't
have much system-administration experience and using rc.local was definitely
the easiest way out.

I should have warned him of the alternate correct method though...Fortunately
he has been nicely informed by others.

--
Jorge
_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 
Old 11-23-2010, 12:03 AM
John R Pierce
 
Default best way to start and shutdown programs in CentOS?

On 11/21/10 6:20 PM, Kill Script wrote:
>
> and I think that I can easily modify this Oracle init.d example
>
> http://www.linuxjournal.com/files/linuxjournal.com/linuxjournal/articles/044/4445/4445l1.html
>

note that example is suffering from some HTML formatting issues.
Specifically, the lines like...

su-$ORA_OWNER -c $ORA_HOME/bin/dbstart

should be

su - $ORA_OWNER -c $ORA_HOME/bin/dbstart


(noting the spaces on either side of the first dash ...)


_______________________________________________
CentOS mailing list
CentOS@centos.org
http://lists.centos.org/mailman/listinfo/centos
 

Thread Tools




All times are GMT. The time now is 02:34 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2007 - 2008, www.linux-archive.org