使用winsw发布接口服务
该方法同时适用于Springboot项目和.netCore项目
参考:https://zhuanlan.zhihu.com/p/453733074
1.下载 winsw
下载地址: https://github.com/winsw/winsw
同时包括.exe和.xml文件,其中.xml为配置文件,.exe为执行文件,两个文件名称必须一致
2.配置服务信息
1).netcore 项目
<service>
<!--服务ID-->
<id>DataService</id>
<!--系统服务名称-->
<name>DataService</name>
<!--系统服务名称-->
<description>DataService</description>
<executable>dotnet</executable>
<arguments>E:\prj\code\CSharp\SW\IntelligentTrack\DataService\bin\Debug\net6.0\DataService.dll</arguments>
<!--开机自启-->
<startmode>Automatic</startmode>
<!--保存日志-->
<log mode="append">
<logpath>filelog.log</logpath>
</log>
</service>
2).SpringBoot项目
<service>
<!--服务ID-->
<id>yy</id>
<!--系统服务名称-->
<name>yy</name>
<!--系统服务名称-->
<description>计算服务</description>
<executable>java</executable>
<arguments>-jar yy-0.0.1-SNAPSHOT.jar</arguments>
<!--开机自启-->
<startmode>Automatic</startmode>
<!--保存日志-->
<log mode="append">
<logpath>filelog.log</logpath>
</log>
</service>
3.安装服务
apiServer.exe install
除install之外,还有如下命令:
- uninstall:删除服务
- start:启动服务
- stop:停止服务
- restart:重启服务
- status:查看状态
安装成功后可以在系统服务中查看到服务信息,可以自定义服务