Skip to content

Commit

Permalink
🦄 add bash script
Browse files Browse the repository at this point in the history
  • Loading branch information
hellokaton committed Mar 4, 2017
1 parent 1ace33c commit 2076469
Showing 1 changed file with 98 additions and 0 deletions.
98 changes: 98 additions & 0 deletions bin/tale.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
#!/bin/bash
# author:biezhi
# url:https://github.com/otale/scripts


# Usage: sh tale.sh start "-Xms128m -Xmx128m"
# Usage: sh tale.sh stop
# Usage: sh tale.sh status
# Usage: sh tale.sh reload 10
# Usage: sh tale.sh log

env_args="-Xms128m -Xmx128m"
sleeptime=0
arglen=$#

# get tale pid
get_pid(){
pname="`find .. -name 'tale*.jar'`"
pname=${pname:3}
pid=`ps -ef | grep $pname | grep -v grep | awk '{print $2}'`
echo "$pid"
}

startup(){
pid=$(get_pid)
if [ "$pid" != "" ]
then
echo "Tale already startup!"
else
jar_path=`find .. -name 'tale*.jar'`
echo "jarfile=$jar_path"
cmd="java $1 -jar $jar_path > ./tale.out < /dev/null &"
echo "cmd: $cmd"
java $1 -jar $jar_path > ./tale.out < /dev/null &
show_log
fi
}

shut_down(){
pid=$(get_pid)
if [ "$pid" != "" ]
then
kill -9 $pid
echo "Tale is stop!"
else
echo "Tale already stop!"
fi
}

show_log(){
tail -f tale.out
}

show_help(){
echo "\r\n\t欢迎使用Tale Blog"
echo "\r\nUsage: sh tale.sh start|stop|reload|status|log"
echo "\r\n可选参数: [-env] [-h]"
echo "\t-env\t\tjvm相关参数"
echo "\t-h\t\t帮助信息"
exit
}

show_status(){
pid=$(get_pid)
if [ "$pid" != "" ]
then
echo "Tale is running with pid: $pid"
else
echo "Tale is stop!"
fi
}

if [ $arglen -eq 0 ]
then
show_help
else
if [ "$2" != "" ]
then
env_args="$2"
fi
case "$1" in
"start")
startup "$env_args"
;;
"stop")
shut_down
;;
"reload")
echo "reload"
;;
"status")
show_status
;;
"log")
show_log
;;
esac
fi

0 comments on commit 2076469

Please sign in to comment.