windows安装spring boot、nginx开启自动启动服务

Redis3.2.100

  1. 安装服务:redis-server --service-install redis.windows.conf
  2. 卸载服务:redis-server --service-uninstall

winsw服务安装

  1. 下载地址:Index of releases/com/sun/winsw/winsw/2.9.0 (jenkins-ci.org)
  2. 常用命令
    • install 将服务安装到Windows Service Controller.
    • uninstall 卸载服务和上面相反的操作。
    • start 启动服务,该服务必须已经安装。
    • stop 停止服务。
    • stopwait 停止服务并等待,直到它实际上停止为止。
    • restart 重新启动服务。如果该服务当前未运行,则此命令的作用类似于start
    • status 检查服务的当前状态。

Nginx1.16.1

  1. 获取wsw.exe

  2. 编辑wsw.xml配置

    <?xml version="1.0" encoding="UTF-8" ?>
    <service>
       <!-- 服务唯一ID -->
       <id>Nginx</id>
       <!-- 服务显示名称 -->
       <name>Nginx</name>
       <description>Nginx server</description>
       <!-- 日志路径 -->
       <logpath>D:\nginx1.16.1\logs</logpath>
       <!-- 日志模式-->
       <log mode="roll-by-size">
          <sizeThreshold>10240</sizeThreshold>
          <keepFiles>8</keepFiles>
       </log>
       <!-- 服务依赖项,其他服务的id,多个使用逗号分割
       <depend></depend> -->
       <!-- 可执行文件的命令 -->
       <executable>D:\nginx1.16.1\nginx.exe</executable>
       <!-- 启动参数
       <startargument>-p D:\nginx1.16.1</startargument> -->
    
       <stopexecutable>D:\nginx1.16.1\nginx.exe -s stop</stopexecutable>
       <!-- 停止参数
       <stopargument>-p D:\nginx1.16.1</stopargument> -->
    </service>
    
  3. wsw install(切换到nginx目录进行安装)

SpringBoot

  1. 编辑批处理命令

    // 开始服务脚本
    @echo off
    set port=8086
    title 登陆权限验证-%port%
    
    rem usebackq可以省略,但可以处理带空格的文件名
    rem tokens2表示去1-5个字符,返回给函数体,也可使用,表示第几个字符
    rem a为显示声明,代表第一个字符变量,后续的b,c,d,e为隐式声明,代表了后续四个变量
    
    for /f "tokens=1-5" %%a in ('netstat -ano^|findstr ":%port%"') do (
    	if [%%d] EQU [LISTENING] (
    		set pid=%%e
    	)
    )
    if "%pid%" == "" goto start
    if not "%pid%" == "" goto run
    
    :run
    echo %port% (采集程序运行中)port is opening...
    rem 为调用批处理时传入的参数,结束服务时调用
    if "%1"== "stop" (
    taskkill /f /pid %pid%
    )
    pause
    exit
    
    :start
    echo (开始启动采集程序)starting collect program...
    javaw -jar D:\server\user-auth\ms-user-auth-1.0-SNAPSHOT.jar
    echo.Starting Success!
    exit
    
    
    
    // 停止服务脚本
    echo 关闭服务
    call start-nohup.bat stop
    
    
  2. 编辑winsw配置

    <?xml version="1.0" encoding="UTF-8" ?>
    <service>
       <!-- 服务唯一ID -->
       <id>UserAuth</id>
       <!-- 服务显示名称 -->
       <name>UserAuth</name>
       <description>进货查验,移动办公的服务</description>
       <!-- 日志路径 -->
       <logpath>/logs</logpath>
       <!-- 日志模式-->
       <log mode="roll-by-size">
          <sizeThreshold>10240</sizeThreshold>
          <keepFiles>8</keepFiles>
       </log>
       <!-- 服务依赖项,其他服务的id,多个使用逗号分割 -->
       <depend>Redis</depend>
       <!-- 可执行文件的命令 -->
       <executable>D:\server\user-auth\start-nohup.bat</executable>
       <stopexecutable>D:\server\user-auth\stop.bat</stopexecutable>
    </service>
    
  3. 使用winsw安装(winsw install)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值