`
NanguoCoffee
  • 浏览: 49738 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

支持start,stop,restart的运行脚本

阅读更多

linux下的运行脚本,支持start,stop,restart

使用说明;

1:

run.sh start

run.sh stop

run.sh restart

2:

   修改最大内存memlimit=512

项目名称:projectname=processServer
启动的类名:com.ifeng.ipicture.ProcessServer

 

 

run.sh

#!/bin/sh
#memory limit
memlimit=512M
projectname=processServer
ulimit -SHn 51200
dir=`dirname $0`
pidfile=pid
cd  $dir
CP=.:config/
for file in lib/*;
do CP=${CP}:$file;
done
retval=0
# start the server
start(){
        printf "Starting the server of $projectname\n"
        if [ -f "$pidfile" ] ; then
                pid=`cat "$pidfile"`
        printf 'Existing process: %d\n' "$pid"
                retval=1
        else
                java  -Xms512M \
                      -Xmx"$memlimit" \
                      -XX:+UseParallelGC \
                      -XX:+AggressiveOpts \
                      -XX:+UseFastAccessorMethods \
                      -Xloggc:logs/gc`date +%Y%m%d%H%M%S`.log \
                      -cp $CP com.ifeng.ipicture.ProcessServer  >>logs/log.log &
                echo $! >"$pidfile"
                if [ "$?" -eq 0 ] ; then
                        printf 'Done\n'
                else
                        printf 'The server could not started\n'
                        retval=1
                fi
        fi
}
# stop the server
stop(){
  printf "Stopping the server of $projectname\n"
  if [ -f "$pidfile" ] ; then
    pid=`cat "$pidfile"`
    printf "Sending the terminal signal to the process: %s\n" "$pid"
    PROCESSPID=`ps -ef|awk  '{print $2}'|grep "$pid"`
    if [[ $PROCESSPID -ne "$pidfile" ]] ; then
        rm -f "$pidfile";
        printf 'Done\n'
    fi
    kill -TERM "$pid"
    c=0
    while true ; do
      sleep 0.1
      PROCESSPID=`ps -ef|awk  '{print $2}'|grep "$pid"`
      if [[ $PROCESSPID -eq "$pidfile" ]] ; then
        c=`expr $c + 1`
        if [ "$c" -ge 100 ] ; then
          printf 'Hanging process: %d\n' "$pid"
          retval=1
          break
        fi
      else
        printf 'Done\n'
        rm -f "$pidfile";
        break
      fi
    done
  else
    printf 'No process found\n'
    retval=1
  fi
}
# dispatch the command
case "$1" in
start)
  start
  ;;
stop)
  stop
  ;;
restart)
  stop
  start
  ;;
hup)
  hup
  ;;
*)
  printf 'Usage: %s {start|stop|restart}\n'
  exit 1
  ;;
esac


# exit
exit "$retval"



# END OF FILEcho $CP

分享到:
评论

相关推荐

    启动脚本的模板,start stop status restart

    启动脚本的模板,start stop status restart

    spring boot/spring cloud项目启动脚本,默认名称:start.sh

    linux服务器,springboot,spring cloud、spring cloud alibaba等项目...sh start.sh stop sh start.sh restart sh start.sh status 或者: ./start.sh start ./start.sh stop ./start.sh restart ./start.sh status

    auto_start_stop_restart.sh

    支持一键启停jar包(也可以改成py文件等需后台运行启停的文件),将该脚本文件与待执行程序文件放在同一目录后替换脚本文件中所有程序名即可

    start-stop-daemon:轻松将 JS 脚本转换为 start-stop-daemon 脚本

    使用node script.js start命令将脚本作为守护进程node script.js start 使用命令node script.js stop停止守护进程使用命令node script.js restart守护进程使用命令node script.js status获取守护进程的node script....

    springboot 架包运行脚本

    springboot jar包启动脚本,启动:./lpwa./sh start 停止:./lpwa./sh stop 重启:./lpwa./sh restart

    springboot项目linux系统下 通用 启动脚本

    springboot项目linux系统下 通用 启动脚本 支持日志输出、远程调试开启 支持start、stop、restart命令 通用启动脚本,只需将服务名改成自己的服务名即可! 保证可用!

    jar spring boot 运行脚本

    将spring boot项目与脚本放在同一目录下,直接启动./springboot start 停止./springboot stop 重启./springboot restart

    linux系统Shell脚本运行java项目。

    linux shell脚本启动java。 ---------------------------------------- Windows编辑的sh,在linux会报错: shell unexpected end of file 解决办法: ...运行命令:sh test.sh start/stop/restart/status

    Linux运行、停止、重启Jar包Bash脚本

    通过 run.sh [ start | stop | restart | pid ] 脚本,执行启动 | 停止 | 重启 | 输出进程号。 注:1.该脚本为Linux Bash脚本。2.替换文件第3行 app_name='xyz.jar' 中 'xyz.jar' 为运行jar包名。3.给该脚本执行...

    项目启停通用shell脚本

    项目start|stop|restart|status操作通用脚本 eg: sh service.sh start new_project

    centos6下redis开机自启动脚本配置

    本文档适用于配置 centos6 环境下 redis开机自启动脚本配置,可以使用service redis stop|start|restart|status 进行管理 ,内部文件需要更改的有PASSWD(这个是连接redis的密码,与redis.conf 对应 )REDIS_HOME ...

    linux_启动脚本次序.doc

    而这些rc启动脚本有着类似的用法,它们一般能接受start、stop、restart、status等参数。  /etc/rc.d/rc5.d/中的rc启动脚本通常是K或S开头的链接文件,对于以以S开头的启动脚本,将以start参数来运行。而如果发现...

    oracle启动与管理服务脚本

    其中stop 与restart命令相似,status查看简易数据库状态。 此脚本根据默认安装完成设置: 数据库系统用户oracle 需配置好要求的环境变量 PATH变量指定到$ORACLE_HOME/bin目录下。 注意:如果数据库用户或者组有不同...

    java启动jar包一键脚本

    java启动jar包一键脚本 一键启动/停止/重启/查看状态 sh startJar.sh [start/stop/restart/status] ./startJar.sh [start/stop/restart/status]

    redis启动停止脚本.rar

    Redis的启动停止重启脚本,使用shell脚本编写,包含start.sh、stop.sh、restart.sh三个脚本文件

    tomcat自启脚本

    tomcat自启动脚本,使用方法: 将tomcat脚本放到/etc.init.d目录下 使用servcie调用tomcat脚本进行启动停止重启 例如:service tomcat start service tomcat stop service tomcat restart

    smokeping启动脚本

    smokeping启动脚本 service smokeping start/stop/restart/reload

    linux一键启动、关闭、重启springboot项目脚本

    修改jar包名称,修改脚本权限为777。 使用方法: ./server.sh start(stop/restart)

    脚本启动、停止ArcGIS Server 服务的源码

    AGSSOM [usage]: {server} [-s|start, -x|stop, -r|restart -list|list_services -listtypes|list_server_types -describe|describe -publish|publish resources] [servicename (or *all* for stop, or MXD path for...

    将nginx用service管理的shell脚本

    将其复制到/etc/init.d下。 就可以通过service nginx start | restart | stop 管理nginx了

Global site tag (gtag.js) - Google Analytics