Skip to content

Instantly share code, notes, and snippets.

@qlong8807
Created January 30, 2019 09:35
Show Gist options
  • Save qlong8807/6e4b50a030401e704a8340ff4537fe8d to your computer and use it in GitHub Desktop.
Save qlong8807/6e4b50a030401e704a8340ff4537fe8d to your computer and use it in GitHub Desktop.
启动当前目录下的jar结尾的Java程序 start|stop|status
#!/bin/bash
source /etc/profile
basedir=`dirname $0`
cd $basedir
for i in `ls -t *.jar`
do
#echo $i
break
done
ii=${i%.*}
#echo $ii
TaskID=$(ps -ef |grep -w $ii|grep -v 'grep'|awk '{print $2}')
input=$1
start()
{
if [ ${TaskID} ];then
echo "此服务已启动!"
else
#nohup java -Xbootclasspath/a:./config -Djava.ext.dirs=./lib:${JAVA_HOME}/jre/lib/ext -jar $(pwd)/$i spring > nohup.out & 2>&1 &
nohup java -Xbootclasspath/a:./config -Djava.ext.dirs=./lib:${JAVA_HOME}/jre/lib/ext -jar $(pwd)/$i spring > /dev/null &2>&1 &
# tail -f nohup.out
fi
}
stop()
{
if [ ${TaskID} ];then
kill -9 ${TaskID}
echo "服务已经停止启动"
else
echo "服务没有启动"
fi
}
status()
{
if [ ${TaskID} ];then
echo "此服务已启动!"
else
echo "服务没有启动!"
fi
}
if [ -z "$input" ]
then
echo "用法: ./startup.sh {start|stop|status}"
elif [ ${input} == "start" ]
then
start
elif [ ${input} == "stop" ]
then
stop
elif [ ${input} == "status" ]
then
status
else
echo "用法: ./startup.sh {start|stop|status}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment