#!/bin/sh
EJAVA=/usr/local/jdk1.8.10_10/bin/java
EHOME=/service/appRoot
EPROG=myapp
ELOG=$EHOME/log
ELIB=$EHOME/lib
ECONTEXT=$EHOME/bin
EMAIN=com.entry.MainApplication
PID_NAME=$EHOME/.myapp-pid
case $1 in
start)
echo "Starting $EPROG Service ..."
if [ ! -f $PID_NAME ]; then
nohup $EJAVA -Dlog.dir=$ELOG -Dprog.nm=$EPROG -cp $ECONTEXT:$ELIB/* $EMAIN 2>> /dev/null >> /dev/null &
echo $! > $PID_NAME
echo "$EPROG Service started ..."
else
echo "$EPROG Service is already running ..."
fi
;;
stop)
if [ -f $PID_NAME ]; then
PID=$(cat $PID_NAME);
echo "$EPROG Service stoping ..."
kill $PID;
echo "$EPROG Service stopped ..."
rm $PID_NAME
else
echo "$EPROG Service is not running ..."
fi
;;
restart)
if [ -f $PID_NAME ]; then
PID=$(cat $PID_NAME);
echo "$EPROG Service stopping ...";
kill $PID;
echo "$EPROG Service stopped ...";
rm $PID_NAME
echo "$EPROG Service starting ..."
nohup $EJAVA -Dlog.dir=$ELOG -Dprog.nm=$EPROG -cp $ECONTEXT:$ELIB/* $EMAIN 2>> /dev/null >> /dev/null &
echo $! > $PID_NAME
echo "$EPROG Service started ..."
else
echo "$EPROG Service is not running ..."
fi
;;
esac
#!/bin/sh
#
# 2017/12/16
# by emunhi
# description: java application
#
java=/myservice/soft/jdk1.8.0_191
prog=emunhi
javaOptions="-Dspring.profiles.active=prod -Dlog.dir=/myservice/logs"
mainClass=com.emunhi.batch.BootApplication
classPath=/myservice/emunhi/bin:/myservice/emunhi/lib/*
pidfile=/myservice/emunhi/conf/${prog}.pid
lockfile=/myservice/emunhi/conf/${prog}
cmdline="${java}/bin/java ${javaOptions} -cp ${classPath} ${mainClass}"
RETVAL=0
# System configuration
unset TMPDIR
if [ -f /etc/sysconfig/${prog} ]; then
. /etc/sysconfig/${prog}
fi
# Source function library
if [ -f /etc/init.d/functions ] ; then
. /etc/init.d/functions
elif [ -f /etc/rc.d/init.d/functions ] ; then
. /etc/rc.d/init.d/functions
else
exit 1
fi
start() {
echo -n $"Starting ${prog} services: "
daemon --pidfile=${pidfile} "${cmdline} &"
RETVAL=$?
pgrep -f "${mainClass}" > ${pidfile}
echo
[ $RETVAL -eq 0 ] && touch ${lockfile} || RETVAL=1
return $RETVAL
}
stop() {
echo -n $"Stopping ${prog} service: "
killproc -p ${pidfile} ${prog}
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f ${lockfile} ${pidfile}
return $RETVAL
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile} ${prog}
RETVAL=$?
;;
restart)
stop
start
;;
*)
echo $"Usage: ${prog} {start|stop|status|restart}: "
RETVAL=2
esac
exit $RETVAL
기동스크립트 위치에 스크립트 이동
/etc/rc.d/init.d
== mmc script
# cp mmc /etc/rc.d/init.d/mmc
- 실행권한
# chmod 755 mmc
- 서비스 설정 (아래와 같이 하면 전원 ON과 동시 mmc 서비스기동)
# chkconfig --add mmc
# chkconfig mmc on
== 서비스 확인
# chkconfig --list | grep mmc
== 서비스 삭제
# chkconfig --del mmc