Linux - Auto init Scripts -2

Add Startup Script or Service with Linux on Bootup

Here is an example of how to create a startup script or service that will auto load on Linux machine boot, in this example I am running a process called "testjava.jar".
 First, create a file "testjava" (or name you desire) in the directory

 /etc/init.d >> touch /etc/init.d/testjava

Now, edit the file:

nano /etc/init.d/testjava

and add your script like:

#! /bin/sh

case "$1" in
    cd /home/test
    /usr/bin/java -jar testjava.jar &
     killall -v java
exit 0

You can find out where the location of java command is by using the "which" command like:

>> which java

Next, make the file executable:

>> chmod +x /etc/init.d/testjava

Now you should be able to run commands like:

>> /etc/init.d/testjava start
>> /etc/init.d/testjava stop

Now add the script or service to the auto load at bootup, this is Ubuntu example:

 >> update-rc.d testjava defaults

Or on other Linux use:

>> chkconfig --add testjava

If you wanted to remove the registered startup use (Ubuntu example):

>> rm -fv /etc/rc*/*testjava

Or on other Linux use:

>> chkconfig --del testjavaAnd show configured for startup:

>> chkconfig -- list

Adarsh Kumar
AK Technosoft Corp.

Big thanks to this blog author

Web Analytics