nginx加入Windows服务开机自启动

目标:将nginx加入Windows服务,实现开机自启动

 

需要用到工具winsw,到该目录下,下载最新版winsw

http://repo.jenkins-ci.org/releases/com/sun/winsw/winsw/

源码: https://github.com/winsw/winsw

 

新建个nginx目录,将winsw-2.9.0-bin.exe拷贝到该目录下并重命名为nginx-service.exe

该目录下新建nginx-service.xml(exe与xml文件名要一致)

<!-- nginx-service.xml -->
<service>
  <id>nginx</id>
  <name>nginx</name>
  <description>This service runs nginx system.</description>
  <executable>D:\nginx\nginx.exe</executable>
  <startarguments>
    -c
    D:\nginxWebUI\nginx.conf
    -p
    D:\nginx
  </startarguments>
  
  <stopexecutable>D:\nginx\nginx.exe</stopexecutable>
  <stoparguments>
    -p
    D:\nginx
    -s
    stop
  </stoparguments>
  
  <log mode="roll"></log>
</service>

 

在该目录下shift+右键,打开cmd,执行

nginx-service.exe install  # 安装服务(默认开机自启)
nginx-service.exe start    # 启动服务

nginx-service.exe uninstall  # 卸载服务

 

 

同样的,可以添加nginxWebUI对应的xml来安装服务

<!-- nginx-webui-service.xml -->
<service>
  <id>nginx-webui</id>
  <name>nginx-webui</name>
  <description>This service runs nginxWebUI system.</description>
  <!-- <env name="JENKINS_HOME" value="%BASE%"/>  -->
  <executable>java</executable>
  <arguments>-Xmx64m -jar D:\nginxWebUI\nginxWebUI.jar --server.port=8086 --project.home=D:\nginxWebUI\</arguments>
  <log mode="roll"></log>
</service>

 

常用排查命令

netstat -aon | findstr 0:8086

tasklist | findstr 进程号或进程名

taskkill /f /im 进程号或进程名

 

posted @ 2021-01-22 11:48  Virya  阅读(1291)  评论(0编辑  收藏  举报