Windows 转换服务

以Nginx为例

  1. 下载Windows Service Wrapper 工具

  2. 文件重命名为 nginx-service.exe

  3. 同目录下新建同名 nginx-service.xml 文件

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    <service>
    <id>nginx</id>
    <name>nginx</name>
    <description>nginx</description>
    <logpath>C:\nginx-1.17.1</logpath>
    <logmode>roll</logmode>
    <depend></depend>
    <executable>C:\nginx-1.17.1\nginx.exe</executable>
    <stopexecutable>C:\nginx-1.17.1\nginx.exe -s stop</stopexecutable>
    </service>
  4. 使用

    1. 安装

      1
      nginx-service.exe install
    2. 卸载

      1
      nginx-service.exe uninstall
    3. 启动

      1
      nginx-service.exe start
    4. 停止

      1
      nginx-service.exe stop