winsw/winsw

GitHub: winsw/winsw

WinSW 是一个可将任意可执行文件打包并注册为 Windows 服务进行管理的轻量级包装器。

Stars: 14136 | Forks: 1685

# 宽松许可证下的 Windows Service Wrapper [![Github All Releases](https://img.shields.io/github/downloads/winsw/winsw/total?style=flat-square)](https://github.com/winsw/winsw/releases) [![GitHub Release](https://img.shields.io/github/v/release/winsw/winsw?include_prereleases&sort=semver&style=flat-square)](https://github.com/winsw/winsw/releases) [![NuGet](https://img.shields.io/nuget/v/WinSW?style=flat-square)](https://www.nuget.org/packages/WinSW/) [![Build Status](https://img.shields.io/azure-devops/build/winsw/aabe43dd-6f6d-4660-b5dd-5b79e1e2ef4e/1?style=flat-square)](https://dev.azure.com/winsw/winsw/_build?definitionId=1&_a=summary) [![Deployment Status](https://img.shields.io/azure-devops/release/winsw/aabe43dd-6f6d-4660-b5dd-5b79e1e2ef4e/1/1?style=flat-square)](https://dev.azure.com/winsw/winsw/_release?_a=releases&view=mine&definitionId=1) [![Gitter](https://img.shields.io/gitter/room/winsw/winsw?style=flat-square)](https://gitter.im/winsw/winsw?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) [![License](https://img.shields.io/github/license/winsw/winsw?style=flat-square)](LICENSE.txt) WinSW 将任何应用程序打包并作为 Windows 服务进行管理。 ## 项目状态 - WinSW 3.x 的开发在默认分支 [`v3`](https://github.com/winsw/winsw/tree/v3) 上进行。 - GitHub Releases 包含稳定的 2.x 版本和 3.x 预发布版本。NuGet 和 Maven 包目前对应 2.x 版本。 - 有关 WinSW 2.x 的文档,请参阅 [`v2`](https://github.com/winsw/winsw/tree/v2) 分支。 ## 为什么使用? 请参阅[项目清单](MANIFEST.md)。 ## 支持的平台 WinSW 3 可以在安装了 .NET Framework 4.6.1 或更高版本的 Windows 平台上运行。 对于没有 .NET Framework 的系统,该项目提供了基于 .NET 7 的原生 64 位和 32 位可执行文件。 可以根据需要添加更多可执行文件。 [.NET Framework 系统要求](https://docs.microsoft.com/dotnet/framework/get-started/system-requirements)\ 自 Windows 10 版本 1511 和 Windows Server 2016 起预装。\ 自 Windows 7 SP1 和 Windows Server 2008 R2 SP1 起可安装。 [.NET 7 系统要求](https://github.com/dotnet/core/blob/main/release-notes/7.0/supported-os.md)\ 自 Windows 10 版本 1607、Windows Server (Core) 2012 R2 和 Nano Server 版本 1809 起支持。 ## 下载 最新的发布和预发布 WinSW 二进制文件可在 [GitHub Releases](https://github.com/winsw/winsw/releases) 上获取。 其他来源: * CI 构建可在 [Azure Pipelines](https://dev.azure.com/winsw/winsw/_build?definitionId=1) 上获取。 * [NuGet](https://www.nuget.org/packages/WinSW/)。(2.x) * 用于可执行文件的 [Maven 打包](https://github.com/jenkinsci/winsw-maven-packaging),由 [Jenkins 项目](https://jenkins.io/)托管。 二进制文件可在[此处](https://repo.jenkins-ci.org/releases/com/sun/winsw/winsw/)获取。(2.x) ## 快速开始 ### 将 WinSW 作为全局工具使用 1. 从发行版中提取 *WinSW.exe* 或 *WinSW.zip*。 2. 编写 *myapp.xml*(有关更多详细信息,请参阅 [XML 配置文件规范](docs/xml-config-file.md)和[示例](samples))。 3. 运行 [`winsw install myapp.xml [options]`](docs/cli-commands.md#install-command) 来安装服务。 4. 运行 [`winsw start myapp.xml`](docs/cli-commands.md#start-command) 来启动服务。 5. 运行 [`winsw status myapp.xml`](docs/cli-commands.md#status-command) 来查看您的服务是否已启动并正在运行。 ### 将 WinSW 作为捆绑工具使用 1. 从发行版中提取 *WinSW.exe* 或 *WinSW.zip*,并根据您的喜好重命名 *.exe*(例如 *myapp.exe*)。 2. 编写 *myapp.xml*(有关更多详细信息,请参阅 [XML 配置文件规范](docs/xml-config-file.md)和[示例](samples))。 3. 将这两个文件并排放置,因为 WinSW 就是通过这种方式发现其关联配置的。 4. 运行 [`myapp.exe install [options]`](docs/cli-commands.md#install-command) 来安装服务。 5. 运行 [`myapp.exe start`](docs/cli-commands.md#start-command) 来启动服务。 ### 示例配置文件 您需要编写定义服务的配置文件。 下面的示例是 Jenkins 项目中使用的基础示例: ``` jenkins Jenkins This service runs Jenkins continuous integration system. java -Xrs -Xmx256m -jar "%BASE%\jenkins.war" --httpPort=8080 ``` 完整的配置文件规范可在[此处](docs/xml-config-file.md)获取。 您可以在[此处](samples)找到更多示例。 ## 用法 WinSW 通过 [XML 配置文件](docs/xml-config-file.md)进行管理。 您重命名的 *WinSW.exe* 二进制文件还接受以下命令: | 命令 | 描述 | | ------- | ----------- | | [install](docs/cli-commands.md#install-command) | 安装服务。 | | [uninstall](docs/cli-commands.md#uninstall-command) | 卸载服务。 | | [start](docs/cli-commands.md#start-command) | 启动服务。 | | [stop](docs/cli-commands.md#stop-command) | 停止服务。 | | [restart](docs/cli-commands.md#restart-command) | 停止并重新启动服务。 | | [status](docs/cli-commands.md#status-command) | 检查服务状态。 | | [refresh](docs/cli-commands.md#refresh-command) | 在不重新安装的情况下刷新服务属性。 | | [customize](docs/cli-commands.md#customize-command) | 自定义 wrapper 可执行文件。 | | dev | 实验性命令。 | 实验性命令: | 命令 | 描述 | | ------- | ----------- | | [dev ps](docs/cli-commands.md#dev-ps-command) | 绘制与服务关联的进程树。 | | [dev kill](docs/cli-commands.md#dev-kill-command) | 在服务停止响应时终止服务。 | | [dev list](docs/cli-commands.md#dev-list-command) | 列出由当前可执行文件管理的服务。 | 大多数命令需要管理员权限才能执行。WinSW 会在非提权会话中提示 UAC。 ## 文档 * [迁移到 WinSW 3.x](docs/migrate-to-3-x.md) * 配置: * [XML 配置文件](docs/xml-config-file.md) * [日志和错误报告](docs/logging-and-error-reporting.md) * [扩展](docs/extensions/extensions.md) * 用例: * [自重启服务](docs/self-restarting-service.md) * [延迟文件操作](docs/deferred-file-operations.md) * [故障排除](docs/troubleshooting.md) ## 许可证 WinSW 采用 [MIT](LICENSE.txt) 许可证授权。 ## 类似项目 * [srvany.exe](https://learn.microsoft.com/en-us/troubleshoot/windows-client/setup-upgrade-and-drivers/create-user-defined-service) * [nssm](https://git.nssm.cc/nssm/nssm.git) * [srvany-ng](https://github.com/birkett/srvany-ng) * [shawl](https://github.com/mtkennerly/shawl)
标签:服务封装, 系统服务, 运维工具