Linux init Daemons

 To have a script run when a Debian based Linux distribution boots, place it in /etc/init.d/ and make it executable.

See the Tomcat example below for command and script details. In the example, the start and stop scripts included with Tomcat are used to manage the service.

Sample init.d script for Tomcat

sudo apt-get install openjdk-7-jre-headless

sudo mkdir /opt/apache/tomcat

cd /opt/apache/tomcat

sudo tar -xzf /home/dhdadmin/Workspace/apache-tomcat-7.0.29.tar.gz

# place the following into /etc/init.d/tomcat

export JAVA_HOME=/opt/jdk/oracle/jdk1.7.0_07

case $1 in
        sh /opt/apache/tomcat/apache-tomcat-7.0.29/bin/
        sh /opt/apache/tomcat/apache-tomcat-7.0.29/bin/
        sh /opt/apache/tomcat/apache-tomcat-7.0.29/bin/
        sh /opt/apache/tomcat/apache-tomcat-7.0.29/bin/
exit 0

# setup tomcat as a service
sudo chmod 755 /etc/init.d/tomcat
sudo update-rc.d tomcat defaults

# for Grails apps that cause out of memory issues add this to bin/
JAVA_OPTS="-d64 -server -Xms256m -Xmx2030m -Djava.awt.headless=true -XX:PermSize=128m -XX:MaxPermSize=160m -XX:+UseConcMarkSweepGC -XX:+CMSIncrementalMode";	

Manually Starting and Stopping the Deamon

Here are the commands, for this example, to manually start and stop the init daemon:

sudo /etc/init.d/tomcat start

sudo /etc/init.d/tomcat stop

The service command also supports starting and stopping:

$ sudo service tomcat start            

Removing the init Deamon Starting up at Reboot

To remove the example tomcat init deamon, execute this command:

sudo update-rc.d -f tomcat remove
Date Created: 2014-08-23 14:41:07 -0500 (Sat, 23 Aug 2014)

back    |    top