Creating a Linux Service

Linux OS Topics

Creating a Linux Service

Postby nwclasantha » Tue May 05, 2015 8:21 am

#!/bin/bash
# chkconfig: 345 90 10
# processname: tomcat_all
. /etc/rc.d/init.d/functions

LOCKFILE=/var/lock/subsys/tomcat_all
SCRIPT_LOC="/app/Tomcat_Maintain_Script"

case "$1" in
'start')
   if [ -f $LOCKFILE ]; then
       echo $0 already running.
       exit 1
   fi
       echo -n $"Starting tomcat_all....."
   nohup sh $SCRIPT_LOC/ROOR_sync.sh > /dev/null 2>&1 &
nohup sh $SCRIPT_LOC/swap.sh > /dev/null 2>&1 &
nohup sh $SCRIPT_LOC/upload_sync.sh > /dev/null 2>&1 &
nohup sh $SCRIPT_LOC/Tomcat_Auto_Maintain.sh > /dev/null 2>&1 &
       touch $LOCKFILE
   ;;
'stop')
   if [ ! -f $LOCKFILE ]; then
       echo $0 already stopping.
rm -rf $LOCKFILE
       exit 1
   fi
       echo -n $"Stopping tomcat_all......"
   ps -ef | grep "ROOT_sync.sh" | awk '{print $2}' | xargs kill > /dev/null 2>&1 &
ps -ef | grep "swap.sh" | awk '{print $2}' | xargs kill > /dev/null 2>&1 &
ps -ef | grep "upload_sync.sh" | awk '{print $2}' | xargs kill > /dev/null 2>&1 &
ps -ef | grep "Tomcat_Auto_Maintain.sh" | awk '{print $2}' | xargs kill > /dev/null 2>&1 &
       rm -rf $LOCKFILE
   ;;
'restart')
   $0 stop
   $0 start
echo -n $"Restarting tomcat_all......"
   ;;
'status')
   if [ -f $LOCKFILE ]; then
       echo $0 started.
   else
       echo $0 stopped.
   fi
   ;;
*)
   echo "Usage: $0 [start|stop|status]"
   exit 1
esac
exit 0
User avatar
nwclasantha
 
Posts: 75
Joined: Tue Apr 23, 2013 7:27 pm
Cash on hand: 5,884.10
Location: Malabe

Invitations sent: 0
Registered friends: 0
Reputation point: 13
Corporal

Re: Creating a Linux Service

Postby nwclasantha » Tue May 05, 2015 8:22 am

chmod +x /etc/rc.d/init.d/tomcat_all
chkconfig --add tomcat_all
chkconfig tomcat_all on
service tomcat_all start
User avatar
nwclasantha
 
Posts: 75
Joined: Tue Apr 23, 2013 7:27 pm
Cash on hand: 5,884.10
Location: Malabe

Invitations sent: 0
Registered friends: 0
Reputation point: 13
Corporal

Re: Creating a Linux Service

Postby Phonefix » Mon Sep 25, 2017 11:03 am

We need to create a Linux service which has to be run in the background. The service should run a java code.
User avatar
Phonefix
 
Posts: 5
Joined: Mon Sep 25, 2017 10:44 am
Cash on hand: 277.40
Location: United Kingdom

Invitations sent: 0
Registered friends: 0
Reputation point: 0
Lance Corporal


Return to Linux Center

Who is online

Users browsing this forum: No registered users and 2 guests

cron