【实战篇】程序封装成windows服务

最近帮客户开发了一款B/S架构的软件,但是客户没有linux服务器,只有windows电脑,客户不是很懂IT方面,只希望最简单使用,这样很多linux下的shell命令之类的就无法使用了。目前考虑主要包含以下功能

  • 开机自动启动
  • 如果某个东西没有正常启动,可以点击一下就启动

网上找了一下原来真有这样的神器,地址如下,截止发稿日star数量11.5K

https://github.com/winsw/winsw

主要过程如下,可以使用全局模式或者捆绑的模式

  1. 下载exe
  2. 编写配置文件
  3. 安装卸载或者查看服务状态

CommandDescription
installInstalls the service.
uninstallUninstalls the service.
startStarts the service.
stopStops the service.
restartStops and then starts the service.
statusChecks the status of the service.
refreshRefreshes the service properties without reinstallation.
customizeCustomizes the wrapper executable.
devExperimental commands.

安装nginx作为windows服务

<service>
    <id>nginx</id>
    <name>nginx</name>
    <description>nginx</description>
    <logpath>d:\nginx\logs\</logpath>
    <logmode>roll</logmode>
    <depend></depend>
    <executable>d:\nginx\nginx.exe</executable>
    <stopexecutable>d:\nginx\nginx.exe -s stop</stopexecutable>
</service>
# 注册服务
.\service.exe install

# 删除服务
.\service.exe uninstall

# 启动服务 nginx-服务id
net start nginx

# 关闭服务
net stop nginx

安装java程序作为系统服务

<service>
  <id>foo</id>
  <!-- 服务名称-->
  <name>foo service </name>
  <!-- 服务说明 -->
  <description>This is foo service </description>
  <!-- 指定程序依赖的 jre  -->
  <executable>%BASE%\jre\bin\java.exe</executable>
  <!-- jar 运行命令  -->
  <arguments> -jar %BASE%\jar\app.jar </arguments>
  <!-- 输出日志目录  -->
  <logpath>%BASE%\logs</logpath>
  <!-- %BASE% 为部署主目录  -->
</service>

使用

# 安装服务
foo.exe install 
# 启动服务
foo.exe start
# 停止服务
foo.exe stop
# 卸载服务
foo.exe uninstall 

项目开发、代码讲解、疑难问题、环境搭建 请联系:gaoyue_13

微信搜一搜:逮猫大兄弟。感谢支持~

  • 11
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值