前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >使用winsw实现windows上的进程托管

使用winsw实现windows上的进程托管

原创
作者头像
保持热爱奔赴山海
修改2024-05-04 15:38:42
1040
修改2024-05-04 15:38:42

项目地址 https://github.com/winsw/winsw

下载3.x的winsw

代码语言:txt
复制
https://github.com/winsw/winsw/releases/download/v3.0.0-alpha.11/WinSW-x64.exe

我这里是把放到了 C:\WinSW\ 这个目录下

编写需要服务化的相关配置文件

xml配置文件的相关说明:https://github.com/winsw/winsw/blob/v3/docs/xml-config-file.md

这里以nginx和mysql为例

vim mysql.xml

代码语言:txt
复制
<service>

  <id>mysql8</id>
  <workingdirectory>D:\mysql8\bin</workingdirectory>

  <!-- Path to the executable, which should be started -->
  <!-- CAUTION: Don't put arguments here. Use <arguments> instead. -->
  <executable>D:\mysql8\bin\mysqld</executable>

</service>

vim nginx.xml

代码语言:txt
复制
<service>
    
  <id>nginx</id>
  <workingdirectory>C:\nginx-1.22.0</workingdirectory>

  <!-- Path to the executable, which should be started -->
  <!-- CAUTION: Don't put arguments here. Use <arguments> instead. -->
  <executable>C:\nginx-1.22.0\nginx.exe</executable>

</service>

dir 查看下当前的项目结构

代码语言:txt
复制
PS C:\WinSW

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a----          2024/5/4     14:35            347 mysql.xml
-a----          2024/5/4      8:10            353 nginx.xml
-a----          2024/5/4      8:04       18286774 WinSW-x64.exe

注册服务

代码语言:txt
复制
PS C:\WinSW
λ .\WinSW-x64.exe install mysql.xml
Installing service 'mysql8 (mysql8)'...
Service 'mysql8 (mysql8)' was installed successfully.

PS C:\WinSW
λ .\WinSW-x64.exe install nginx.xml
Installing service 'nginx (nginx)'...
Service 'nginx (nginx)' was installed successfully.

启动服务

代码语言:txt
复制
PS C:\WinSW
λ .\WinSW-x64.exe start nginx.xml
Starting service 'nginx (nginx)'...
Service 'nginx (nginx)' started successfully.

PS C:\WinSW
λ .\WinSW-x64.exe status nginx.xml
Active (running)

PS C:\WinSW
λ .\WinSW-x64.exe start mysql.xml
Starting service 'mysql8 (mysql8)'...
Service 'mysql8 (mysql8)' started successfully.

PS C:\WinSW
λ .\WinSW-x64.exe status mysql.xml
Active (running)

其它命令

Command

Description

install

Installs the service.

uninstall

Uninstalls the service.

start

Starts the service.

stop

Stops the service.

restart

Stops and then starts the service.

status

Checks the status of the service.

refresh

Refreshes the service properties without reinstallation.

customize

Customizes the wrapper executable.

dev

Experimental commands.

Experimental commands:

Command

Description

dev ps

Draws the process tree associated with the service.

dev kill

Terminates the service if it has stopped responding.

dev list

Lists services managed by the current executable.

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 编写需要服务化的相关配置文件
  • 注册服务
  • 启动服务
  • 其它命令
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
http://www.vxiaotou.com