最近在部署一套Java的spring boot服务,由于对方给定的是Windows server2008服务器,都知道启动jar程序一个命令后停留在一个cmd窗口,且该窗口无法关闭,如果打开的服务个数多了任务栏一堆的cmd窗口不好维护。最终找到通过winSW.exe(开源软件)实现了Windows服务注册。
首先官网下载winSW.exe程序,官网为winsw/winsw: A wrapper executable that can run any executable as a Windows service, in a permissive license. (github.com)
目前最新稳定版为2.11.0
winSW注册分为两个部分,首先确定你要注册的软件名,将winSW.exe修改成为软件名称,例如:
common-service.exe
在common-service.exe同级目录创建它的配置文件,注意配置文件名必须与exe程序文件名一致。目前配置文件支持两种格式,xml和yml,注意必须是.yml结尾,.yaml无法识别。
下面创建common-service.yml或者common-service.xml
xml示例:common-service.xml
<service>
<id>common-service</id>
<name>common-service</name>
<description>软件说明.</description>
<executable>java</executable>
<arguments> -Xmx256m -jar "%BASE%\jenkins.war" --httpPort=8080</arguments>
<logmode>rotate</logmode>
</service>
yml示例:common-service.yml
id: common-service #全局唯一
name: common-service #名称
description: 软件介绍
executable: java #这里也可以指定全路径
arguments: >
-Xmx256m -Xms256m
d:/jenkins.war
--httpPort=8080
更多yml配置参考官方说明:winsw/xml-config-file.md at v3 · winsw/winsw (github.com)
executable也可以配置Windows bat脚本(支持普通打开脚本驻留前台的脚本)
接下来就是安装服务
命令:
.\common-service.exe install
启动服务
net start common-service
start后面的是配置文件里面的id值
停用服务
net stop common-service
卸载删除服务:
.\common-service.exe uninstall
https://www.leftso.com/article/921.html