Kill Script
2010-Nov-22 00:19 UTC
[CentOS] 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. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.centos.org/pipermail/centos/attachments/20101121/4c348b9c/attachment-0001.html>
Les Mikesell
2010-Nov-22 01:10 UTC
[CentOS] 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 at gmail.com
Jorge Fábregas
2010-Nov-22 01:10 UTC
[CentOS] 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
John R Pierce
2010-Nov-22 01:18 UTC
[CentOS] 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.
On Sun, Nov 21, 2010 at 6:19 PM, Kill Script <killscript at gmail.com> 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.Have you looked at Java Service Wrapper: http://wrapper.tanukisoftware.com/doc/english/introduction.html Ultimately, you will be creating an init.d script as discussed in this thread, but this provides some java-specific features. -- Jeff