Created
July 18, 2017 14:58
-
-
Save franzramadhan/2a2cd91c3b3722e9709bf608bfad5b5b to your computer and use it in GitHub Desktop.
Custom Java Application Init Scripts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/expect | |
# | |
# Shutdown Queue jpr@2013 | |
# | |
################################################################3 | |
set timeout 20 | |
set host [lindex $argv 0] | |
set port [lindex $argv 1] | |
spawn telnet $host $port | |
expect ">" | |
send "shutdown\n" | |
expect ">" | |
#send "close\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# Router standalone control script | |
# | |
# chkconfig: 234 80 20 | |
# description: Altamides V3 Router | |
# processname: Router | |
prog="router" | |
# Source function library. | |
. /etc/init.d/functions | |
# Load Java configuration. | |
[ -r /etc/java/java.conf ] && . /etc/java/java.conf | |
export JAVA_HOME | |
USER=app | |
export USER | |
AGENT_HOME=/app/servers/router | |
PIDFILE=$AGENT_HOME/$prog.pid | |
LOCKFILE=$AGENT_HOME/$prog.lock | |
SCRIPT=$AGENT_HOME/$prog.sh | |
SHUTDOWN_SCRIPT=/etc/init.d/console-shutdown.exp | |
APP_HOST=app.trd.ams | |
APP_PORT=9290 | |
start() { | |
echo -n "Starting $prog: " | |
status > /dev/null 2>&1 | |
ret_status=$? | |
if [[ $ret_status -eq 0 ]]; then | |
echo -n "$prog is already running" | |
failure | |
echo | |
return 1 | |
else | |
rm -f $PIDFILE | |
rm -f $LOCKFILE | |
fi | |
su - $USER -c $SCRIPT > /dev/null 2>&1 | |
sleep 5 | |
status > /dev/null 2>&1 | |
if [[ $? -eq 0 ]]; then | |
success | |
echo | |
return 0 | |
else | |
failure | |
echo | |
return 3 | |
fi | |
} | |
stop() { | |
echo -n "Stopping $prog: " | |
if [ -f $PIDFILE ]; then | |
read ppid < $PIDFILE | |
if [ `ps --pid $ppid 2> /dev/null | grep -c $ppid 2> /dev/null` -eq '1' ]; then | |
$SHUTDOWN_SCRIPT $APP_HOST $APP_PORT > /dev/null 2>&1 | |
sleep 5 | |
if [ `ps --pid $ppid 2> /dev/null | grep -c $ppid 2> /dev/null` -eq '1' ]; then | |
kill -9 $ppid | |
fi | |
rm -f $PIDFILE | |
rm -f $LOCKFILE | |
success | |
echo | |
return 0 | |
fi | |
rm -f $PIDFILE | |
rm -f $LOCKFILE | |
failure | |
echo | |
return 3 | |
fi | |
failure | |
echo | |
return 1 | |
} | |
status() { | |
if [ -f $PIDFILE ]; then | |
read ppid < $PIDFILE | |
if [ `ps --pid $ppid 2> /dev/null | grep -c $ppid 2> /dev/null` -eq '1' ]; then | |
echo "$prog is running (pid $ppid)" | |
return 0 | |
else | |
echo "$prog dead but pid file exists" | |
return 1 | |
fi | |
fi | |
echo "$prog is not running" | |
return 3 | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
restart) | |
$0 stop | |
$0 start | |
;; | |
status) | |
status | |
;; | |
*) | |
## If no parameters are given, print which are avaiable. | |
echo "Usage: $0 {start|stop|status|restart|reload}" | |
exit 1 | |
;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment