winsw
本文基于开源工具 winsw 以windows服务启动jar包 或者 dotnetcore dll 或者exe
https://github.com/kohsuke/winsw/releases
官方原始Start文档
Use WinSW as a bundled tool 使用WinSW作为捆绑工具
In order to setup WinSW, you commonly need to perform the following steps:
- Take WinSW.exe from the distribution, and rename it to your taste (such as myapp.exe)
- Write myapp.xml (see the XML config file specification for more details)
- Place those two files side by side, because that's how WinSW discovers its configuration.
- Run
myapp.exe install [options]
to install the service. - Run
myapp.exe start
to start the service.
There are some details for each step available below.
可以去网站下载 WinSW.NET461.exe,如果电脑没有安装.NetFramework,可以直接下载dotnetcore版本
示例1:
需要运行Nop.Web.dll
将下载下来的WinSW.NET461.exe修改为名称 nopcommerce.exe
然后添加一样名称的配置文件nopcommerce.xml
<service>
<id>nopcommerce</id>
<name>nopcommerce</name>
<description>This is nopcommerce service.</description>
<executable>dotnet</executable>
<arguments>Nop.Web.dll --urls=http://localhost:15536</arguments>
<startmode>Automatic</startmode>
<logmode>roll</logmode>
<logpath>log</logpath>
</service>
示例2:
需要运行pigx-auth.jar
包
将下载下来的WinSW.NET461.exe修改为名称 pigx-auth.exe
样名称的配置文件pigx-auth.xml
`
<service>
<id>pigx-auth</id> #id
<name>pigx-auth</name> #名称或者简称
<description>This is pigx-auth service.</description> #windows服务名称
<executable>java</executable> #可执行文件
<arguments>-Dfile.encoding=utf-8 -jar %BASE%/pigx-auth.jar</arguments> #参数 %BASE% 表示pigx-auth所在目录
<startmode>Automatic</startmode> #自动启动
<logmode>roll</logmode> #移动到*.old
<logpath>log</logpath> #日志目录 nopcommerce.err.log nopcommerce.out.log nopcommerce.wrapper.log
</service>
常用命令
myapp.exe stop
myapp.exe uninstall
myapp.exe restart