winsw 它可以将 Windows 上的任何一个程序注册为服务,如果不需要,也可以方便的卸载服务。
【以 Nacos 为例】
<?xml version="1.0" encoding="UTF-8"?>
<service>
<id>NacosWinService</id>
<name>NacosWinService</name>
<description>NacosWinService</description>
<executable>D:\nacos-server-1.4.2\nacos\bin\startup.cmd</executable>
<arguments>-m standalone</arguments>
<logpath>D:\nacos-server-1.4.2\nacos\bin\serviceLogs</logpath>
</service>
注册服务
编写好配置文件之后,记得把配置文件和可执行文件放在一起,并且需要把 WinSW-x64 重命名为 NacosWinService(执行文件与 xml 文件在同一目录下并且名字保持一致)这样 winsw 才能正确识别配置文件。然后我们打开一个管理员权限的命令提示符或 Powershell 窗口,然后输入下面的命令,如果返回值为 0,说明已将程序注册为服务。
winsw install
启动服务
net start NacosWinService
或者
NacosWinService.exe start
卸载服务
winsw uninstall