forked from 91yun/finalspeed
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
94 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#!/bin/bash | ||
# chkconfig: 2345 90 10 | ||
# description: start or stop the ShadowsocksR server | ||
# | ||
### BEGIN INIT INFO | ||
# Provides: ShadowsocksR | ||
# Required-Start: $network $syslog | ||
# Required-Stop: $network | ||
# Default-Start: 2 3 4 5 | ||
# Default-Stop: 0 1 6 | ||
# Description: Start or stop the ShadowsocksR server | ||
### END INIT INFO | ||
|
||
# Author: Teddysun <i@teddysun.com> | ||
|
||
name=fs | ||
BIN=/fs/fs.sh | ||
conf=/fs/fs.conf | ||
logname=/fs/server.log | ||
|
||
start(){ | ||
ulimit -s 65535 | ||
ulimit -n 65535 | ||
tram=$( free -m | awk '/Mem/ {print $2}' ) | ||
serverv=$( cat $conf) | ||
if [ "$tram" -le 128 ]; then | ||
nohup java -Xmx64M -XX:MaxGCPauseMillis=30 -jar /fs/fs.jar > $logname 2>&1 & | ||
elif [ "$tram" -le 256 ]; then | ||
nohup java -Xmx128M -XX:MaxGCPauseMillis=30 -jar /fs/fs.jar > $logname 2>&1 & | ||
elif [ "$tram" -le 512 ]; then | ||
nohup java -Xmx256M -XX:MaxGCPauseMillis=30 -jar /fs/fs.jar > $logname 2>&1 & | ||
elif [ "$tram" -gt 512 ]; then | ||
nohup java -Xmx512M -XX:MaxGCPauseMillis=30 -jar /fs/fs.jar > $logname 2>&1 & | ||
fi | ||
RETVAL=$? | ||
if [ "$RETVAL" = "0" ]; then | ||
tail $logname | ||
echo "$name start success" | ||
else | ||
tail $logname | ||
echo "$name start failed" | ||
fi | ||
} | ||
|
||
stop(){ | ||
pid=`ps -ef | grep fs.jar | grep -v grep | awk '{print $2}'` | ||
if [[ ! -z $pid ]]; then | ||
ps -ef | grep fs.jar | grep -v grep | awk '{print $2}' | xargs kill -s 9 | ||
RETVAL=$? | ||
if [ "$RETVAL" = "0" ]; then | ||
echo "$name stop success" | ||
else | ||
echo "$name stop failed" | ||
fi | ||
else | ||
echo "$name is not running" | ||
RETVAL=1 | ||
fi | ||
} | ||
|
||
status(){ | ||
pid=`ps -ef | grep fs.jar | grep -v grep | awk '{print $2}'` | ||
if [[ -z $pid ]]; then | ||
echo "$name is not running" | ||
RETVAL=1 | ||
else | ||
echo "$name is running with PID $pid" | ||
tail $logname | ||
RETVAL=0 | ||
fi | ||
} | ||
|
||
case "$1" in | ||
'start') | ||
stop | ||
start | ||
;; | ||
'stop') | ||
stop | ||
;; | ||
'status') | ||
status | ||
;; | ||
'restart') | ||
stop | ||
start | ||
RETVAL=$? | ||
;; | ||
*) | ||
echo "Usage: $0 { start | stop | restart | status }" | ||
RETVAL=1 | ||
;; | ||
esac | ||
exit $RETVAL |