Created
November 11, 2014 12:19
-
-
Save sim51/bb4bba220b28ad2276bf to your computer and use it in GitHub Desktop.
Esigate init.d script
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 | |
### BEGIN INIT INFO | |
# Provides: esigate | |
# Required-Start: $remote_fs $syslog | |
# Required-Stop: | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
# Short-Description: Start esigate server. | |
# Description: Enable esigate by daemon. | |
### END INIT INFO | |
SERVICE_USER=esigate | |
SERVICE_GROUP=esigate | |
SERVICE_HOME=/srv/esigate | |
SERVICE_LOCK_PATH=/srv/esigate/lock | |
RETVAL=0 | |
PATH=/usr/sbin:/sbin:/usr/bin:/bin | |
# start, debug, stop, and status functions | |
start() { | |
LISTEN_PORT=`netstat -vatn|grep LISTEN|grep 8181|wc -l` | |
if [ $LISTEN_PORT -ne 0 ]; then | |
echo "ESIGate already started" | |
else | |
echo "Starting ESIGate" | |
# Change owner | |
#chown -R $SERVICE_USER:$SERVICE_GROUP $SERVICE_HOME/* | |
su -l $SERVICE_USER -c "cd $SERVICE_HOME;(java -Dserver.port=8181 -Desigate.config=esigate.properties -jar esigate-server-5.0.jar start 2>&1 /var/log/esigate/%Y%m%d.log)&" | |
LISTEN_PORT=`netstat -vatn|grep LISTEN|grep 8181|wc -l` | |
while [ $LISTEN_PORT -eq 0 ]; do | |
echo -n '.' | |
sleep 1 | |
LISTEN_PORT=`netstat -vatn|grep LISTEN|grep 8181|wc -l` | |
done | |
echo | |
RETVAL=$? | |
echo "ESIGate started in normal mode" | |
[ $RETVAL=0 ] && touch $SERVICE_LOCK_PATH | |
fi | |
} | |
stop() { | |
LISTEN_PORT=`netstat -vatn|grep LISTEN|grep 8181|wc -l` | |
if [ $LISTEN_PORT -eq 0 ]; then | |
PID=`ps -ef | awk '($0 ~ /-Dserver.port=8181 -Desigate.config=esigate.properties/ && $0 !~ /cronolog/) {print $2}'` | |
if [ $PID -ne 0 ]; then | |
kill -9 $PID | |
fi | |
echo "ESIGate already stopped" | |
else | |
echo "Stopping ESIGate" | |
PID=`ps -ef | awk '($0 ~ /-Dserver.port=8181 -Desigate.config=esigate.properties/ && $0 !~ /cronolog/) {print $2}'` | |
if [ $PID -ne 0 ]; then | |
kill -15 $PID | |
fi | |
echo "ESIGate stopped" | |
[ $RETVAL=0 ] && rm -f $SERVICE_LOCK_PATH | |
fi | |
} | |
status() { | |
LISTEN_PORT=`netstat -vatn|grep LISTEN|grep 8181|wc -l` | |
if [ $LISTEN_PORT -eq 0 ]; then | |
echo "ESIGate stopped" | |
else | |
MODE="normal" | |
echo "ESIGate running in $MODE mode" | |
fi | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
restart) | |
stop | |
start | |
;; | |
status) | |
status | |
;; | |
*) | |
echo "Usage: $0 {start||stop|restart|status}" | |
exit 1 | |
esac | |
exit $RETVAL |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tu devrais stocker le pid dans un fichier, ca serait plus simple.