windows环境下,workerman不具备进程守护能力,最简单的解决方案是将workerman封装成windows service来实现进程守护。
主要是每次打开很麻烦。。
封装工具:instsrv.exe, srvany.exe,由microsoft的Windows Server 2003 Resource Kit Tools包所提供。
下载地址:https://www.microsoft.com/en-us/download/details.aspx?id=17657
下载到的Windows Server 2003 Resource Kit Tools包是一个自解压文件rktools.exe,运行后从解压出来的文件中,找到instsrv.exe, srvany.exe这2个文件,然后将它们复制到workerman安装目录下,再在该目录下创建4个空白的txt文件,修改txt文件的扩展名为.bat:
install.bat:用于将workerman程序封装成windows service
uninstall.bat:用于删除 install.bat所安装的所有windows service
startAll.bat:用于启动 install.bat所安装的所有windows service
stopAll.bat:用于停止 install.bat所安装的所有windows service
选中install.bat-->右键-->编辑,添加以下内容:
注意:
1:set phpDir=D:\wamp64\bin\php\php7.0.10\(改为你的PHP安装目录)
2:set regDir=HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\
--------以下为install.bat文件内容---------------------------------------------
REM: install.bat for workerman-chat-for-win
@echo off
set cxDir=%~dp0
set wraper=%cxDir%srvany.exe
set appDir=%cxDir%Applications\chat\
set regDir=HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\
set phpDir=D:\wamp64\bin\php\php7.0.10\
set cxPHP=%phpDir%php.exe
REM ########install workman_register ########
set cxSrv=workman_register
set cxApp=%appDir%start_register.php
set cxReg=%regDir%%cxSrv%\Parameters\
instsrv %cxSrv% %wraper%
reg add %cxReg% /v AppDirectory /t REG_SZ /d "%phpDir%" /f
reg add %cxReg% /v Application /t REG_SZ /d "%cxPHP%" /f
reg add %cxReg% /v AppParameters /t REG_SZ /d "%cxApp%" /f
REM ######## install workman_webServer ########
set cxSrv=workman_webServer
set cxApp=%appDir%start_web.php
set cxReg=%regDir%%cxSrv%\Parameters\
instsrv %cxSrv% %wraper%
reg add %cxReg% /v AppDirectory /t REG_SZ /d "%phpDir%" /f
reg add %cxReg% /v Application /t REG_SZ /d "%cxPHP%" /f
reg add %cxReg% /v AppParameters /t REG_SZ /d "%cxApp%" /f
REM ######## install workman_gateway ########
set cxSrv=workman_gateway
set cxApp=%appDir%start_gateway.php
set cxReg=%regDir%%cxSrv%\Parameters\
instsrv %cxSrv% %wraper%
reg add %cxReg% /v AppDirectory /t REG_SZ /d "%phpDir%" /f
reg add %cxReg% /v Application /t REG_SZ /d "%cxPHP%" /f
reg add %cxReg% /v AppParameters /t REG_SZ /d "%cxApp%" /f
REM ######## install workman_business ########
set cxSrv=workman_business
set cxApp=%appDir%start_businessworker.php
set cxReg=%regDir%%cxSrv%\Parameters\
instsrv %cxSrv% %wraper%
reg add %cxReg% /v AppDirectory /t REG_SZ /d "%phpDir%" /f
reg add %cxReg% /v Application /t REG_SZ /d "%cxPHP%" /f
reg add %cxReg% /v AppParameters /t REG_SZ /d "%cxApp%" /f
选中uninstall.bat-->右键-->编辑,添加以下内容:
注意:
写完才发现,貌似reg delete语句不是必须的,需验证,不想折腾了。
--------以下为uninstall.bat文件内容---------------------------------------------
REM: install.bat for workerman-chat-for-win
@echo off
set regDir=HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\
reg delete %regDir%workman_register\Parameters
instsrv.exe workman_register remove
reg delete %regDir%workman_webServer\Parameters
instsrv.exe workman_webServer remove
reg delete %regDir%workman_gateway\Parameters
instsrv.exe workman_gateway remove
reg delete %regDir%workman_business\Parameters
instsrv.exe workman_business remove
选中startAll.bat-->右键-->编辑,添加以下内容:
--------以下为uninstall.bat文件内容---------------------------------------------
@echo off
sc start workman_register
sc start workman_webServer
sc start workman_gateway
sc start workman_business
选中stopAll.bat-->右键-->编辑,添加以下内容:
--------以下为stopAll.bat文件内容---------------------------------------------
@echo off
sc stop workman_business
sc stop workman_gateway
sc stop workman_webServer
sc stop workman_register
选中install.bat-->右键-->以管理员身份运行(A);
选中startAll.bat-->右键-->以管理员身份运行(A);
此电脑-->右键-->管理-->服务和应用程序\服务,在右侧窗口可以看到刚才安装好的四个服务
网友评论