1、启动start.sh
#!/bin/sh
source /etc/profile
base_dir=$(cd "$(dirname "$0")"; pwd)
jar_file=`ls $base_dir -t| grep "^hello.*\.jar$"`
server_name="hello"
launcher_daemon_out="server.out"
if [ ! -f "$jar_file" ]
then
echo "can not found jar file , failed to start server! "
exit 1
fi
pid=`ps -ef | grep "serverName=$server_name" | grep -v "grep" | awk '{print $2}'`
if [ "$pid" = "" ];then
nohup java -DserverName=$server_name -Dbasedir=$base_dir -Djava.security.egd=file:/dev/./urandom -Dloader.path=. $jvm_args -jar $jar_file >"$launcher_daemon_out" 2>&1 < /dev/null &
else
echo "$server_name is running"
fi
2、停止stop.sh
#!/bin/shserver_name="hello"pid=`ps -ef | grep "serverName=$server_name" | grep -v "grep" | awk '{print $2}'`if [ "$pid" = "" ]then echo "$server_name is not running"else kill -9 $pid echo "kill pid:$pid" echo "$server_name stop success"fi
修改.sh为linux的命令
1 vim打开文件在命令模式下输入:set ff 发现出来的是 fileformart=dos2 通过命令:set ff=unix设置我们的代码模式 :wq然后保存代码3 sh start.sh执行命令