太阳当空照-Windows服务化方式Winsw应用(上)

简介: 太阳当空照-Windows服务化方式Winsw应用

639f22c1d4f69777840f9c2a33d4322f.png

工具介绍

以下是官方解释,大概意思是,在有权限许可情况下,作为Windows服务的可执行容器,能够运行任何可执行程序,[传送门]https://github.com/winsw/winsw

A wrapper executable that can run any executable as a Windows service, in a permissive license

用户能够通过配置文件,将目标程序根据实际情况,通过Winsw实现系统中服务注册和运行使用,相比Instsrv.exeSrvany.exe从操作上会更偏向与配置,而不是直接操作系统注册表,减低繁琐度,但是同时也引入了,对于配置文件的操作复杂度,使用者需要为每一个目标服务程序,进行个性化配置

环境要求

WinSW 3 can run on Windows platforms with .NET Framework 4.6.1 or later versions installed. For systems without .NET Framework, the project provides native 64-bit and 32-bit executables based on .NET Core

Winsw.exe能够运行在安装有.Net Fx 4.6.1及其以上版本的系统中,对于没有.NET Fx的系统,该项目提供基于 .Net Core的本地 64 位32 位可执行程序

工具下载

下载链接:https://github.com/winsw/winsw/releases

目前最新版本v2.11.0

WinSW-x64.exe

https://github.com/winsw/winsw/releases/download/v2.11.0/WinSW-x64.exe

下载配置文件:

sample-allOptions.xml

https://github.com/winsw/winsw/releases/download/v2.11.0/sample-allOptions.xml

sample-minimal.xmlhttps://github.com/winsw/winsw/releases/download/v2.11.0/sample-minimal.xml

如果访问不到Github可以评论私信留言笔者获取资源

应用说明

由于Winsw.exe是由配置文件进行管理,运行对应的目标程序,都需要配置对应的配置文件xxxx.xml,一个配置文件对应着一个需要实现服务化的应用程序,以下是来自官方的安装参考内容:

Use WinSW as a global tool

  1. Take WinSW.exe or WinSW.zip from the distribution.
  2. Write myapp.xml (see the XML config file specification and samples for more details).
  3. Run winsw install myapp.xml [options\] to install the service.
  4. Run winsw start myapp.xml to start the service.
  5. Run winsw status myapp.xml to see if your service is up and running.

Use WinSW as a bundled tool

  1. Take WinSW.exe or WinSW.zip from the distribution, and rename the .exe to your taste (such as myapp.exe).
  2. Write myapp.xml (see the XML config file specification and samples for more details).
  3. Place those two files side by side, because that’s how WinSW discovers its co-related configuration.
  4. Run myapp.exe install [options\] to install the service.
  5. Run myapp.exe start to start the service.

由上述的内容可以知道Winsw.exe的使用分为两种类型,一种是将Winsw.exe作为全局指令使用,每次注册服务和启动服务通过配置文件进行逻辑处理

捆绑模式[通用]

下载程序后,依据实际需求,将winsw.exe放到特定目录下,并重命名,名称尽量与目标程序名称较为关联,例如,目标程序为nginx.exe,则可以重命名winsw.exenginxservice.exe,同时与nginxservice.exe同目录,设置对应配置文件,与nginxservice.exe名称保持一致,只是文件类型不同,之后对nginxservice.xml进行配置,最后进行相关的服务注册和操作,进行捆绑模式,一个启动程序对应一个服务启动配置实例

> [servicename.exe] install [options\]
> [servicename.exe] start
> [servicename.exe] status
> [servicename.exe] uninstall

全局模式[3.x版本]-目前不可用

Winsw.exe下载之后,放到一个系统环境变量相关的检索目录下,便于在当前系统的任意地方执行Winsw相关指令都能够实现相关程序的注册和启动,安装时指定对应的服务程序配置程序配置文件

> winsw isntall appname.xml [options\]
> winsw start appname.xml
> winsw status appname.xml
> winsw uninstall appname.xml

相关配置

参考笔者的另一篇文章太阳当空照-Windows服务化方式Winsw基本配置,服务化常用配置如下:

<service>
  <id>服务唯一标识</id>
    <name>服务简称</name>
    <description>服务描述</description>
    <startmode>服务启动模式</startmode>
    <executable>执行指令</executable>
    <startarguments>执行参数</startarguments>
    <workingdirectory>工作路径</workingdirectory>
    <logpath>日志输出路径,默认与配置文件同目录</logpath>
    <log mode="输出模式">
      <sizeThreshold>10240</sizeThreshold>
    <pattern>yyyyMMdd</pattern>
      <autoRollAtTime>00:00:00</autoRollAtTime>
    </log>
    <serviceaccount>
      <username>服务启动账户,默认为本地系统账户</username>
    </serviceaccount>
</service>


相关文章
|
7天前
|
Windows
Windows——如何提取Microsoft Store的应用
Windows——如何提取Microsoft Store的应用
12 0
|
7天前
|
JavaScript Windows
NodeJs——如何获取Windows电脑指定应用进程信息
NodeJs——如何获取Windows电脑指定应用进程信息
12 0
|
1月前
|
Windows
【Windows】 Win10下报错:该文件没有与之关联的应用来执行该操作。请安装应用,若已经安装应用,请在“默认应用设置”页面中创建关联
【Windows】 Win10下报错:该文件没有与之关联的应用来执行该操作。请安装应用,若已经安装应用,请在“默认应用设置”页面中创建关联
294 1
|
2月前
|
Ubuntu Linux C语言
【opencv】opencv在windows和linux的应用
【opencv】opencv在windows和linux的应用
|
3月前
|
开发框架 .NET API
在Windows Server 2008 R2上运行.Net 8应用
在Windows Server 2008 R2上成功运行.Net 8程序,需安装三个补丁:Windows Server 2008 R2 SP1 (KB976932)是基础更新;VC_redist.x64提供MSVC库支持;KB3063858解决.NET运行时加载`kernel.dll`的路径问题。KB3063858可能需要KB2533623。详细信息和下载链接在文中给出。
235 4
|
3月前
|
C# Windows
一款.NET开源、简洁易用的Windows桌面小说阅读应用
一款.NET开源、简洁易用的Windows桌面小说阅读应用
|
3月前
|
Serverless API 数据安全/隐私保护
Serverless 应用引擎产品使用之阿里函数计算中在本地搭建Windows开发环境与阿里云函数计算进行交互如何解决
阿里云Serverless 应用引擎(SAE)提供了完整的微服务应用生命周期管理能力,包括应用部署、服务治理、开发运维、资源管理等功能,并通过扩展功能支持多环境管理、API Gateway、事件驱动等高级应用场景,帮助企业快速构建、部署、运维和扩展微服务架构,实现Serverless化的应用部署与运维模式。以下是对SAE产品使用合集的概述,包括应用管理、服务治理、开发运维、资源管理等方面。
|
Windows 开发者
Windows 8.1 应用再出发 - 几种新增控件(1)
原文:Windows 8.1 应用再出发 - 几种新增控件(1) Windows 8.1 新增的一些控件,分别是:AppBar、CommandBar、DatePicker、TimePicker、Flyout、MenuFlyout、SettingsFlyout、Hub 和 Hyperlink。
1127 0
|
Windows Go 网络架构
Windows 8.1 应用再出发 - 几种新增控件(2)
原文:Windows 8.1 应用再出发 - 几种新增控件(2) 本篇我们接着来介绍Windows 8.1 的新增控件,分别是:Flyout、MenuFlyout、SettingsFlyout、Hub 和 Hyperlink。
1041 0
|
Go Android开发 Windows
Windows 8.1 应用再出发 (WinJS) - 几种新增控件(2)
原文:Windows 8.1 应用再出发 (WinJS) - 几种新增控件(2) 上篇我们介绍了Windows 8.1 和 WinJS 中新增控件中的 AppBarCommand、BackButton、Hub、ItemContainer,本篇我们接着来介绍 NavBar、Repeater 和 WebView。
1009 0