Skip to main content

Posts

Showing posts with the label service stop

Java Application as Linux Service

Introduction Configuring a java application as a Linux service, makes management of application easier.   Steps 1.         Create  following   init.d  script under / etc / init.d  directory. Suppose its name is service_name.sh. #!/bin/bash # # source function library . /etc/init.d/functions RETVAL=0 EXECUTABLE="path_to_java_executable" WORKDIR="service_working_directory" LAUNCH_OPTIONS="application_launch_parameters" GREP_EXPR="%application_name%" PIDFILE="%application_name%.pid" start() { echo -n $"Starting %application_name% service: " cd $WORKDIR if [[ -f $PIDFILE ]];then echo "pidfile is already existing. Cancelling service start." return fi nohup ${EXECUTABLE} ${LAUNCH_OPTIONS} & RETVAL=$? pid=$(ps -ef | grep ${GREP_EXPR} | grep -v grep| grep -v service | grep -v init.d | awk '{print $2}') echo $pid > $PIDFILE ...