github:
倉庫地址: https://github.com/kohsuke/winsw
下載地址: https://github.com/kohsuke/wi...
步驟:
1先到 https://github.com/kohsuke/winsw/releases 下載對應文件,如果沒有特殊要求只為實現守護進程只需要下載 sample-minimal.xml 與 WinSW.NET2.exe 或 WinSW.NET4.exe。
2.在桌面新建一個文件夾(在哪里新建都可以)叫做 phpserver(名字英文,與要命名的服務名稱相同,不能與已有的服務名稱沖突)
服務名稱=
文件夾示例:(文件夾初始只有自己下載的exe與配置文件,需要更名為與要創建的服務名稱相同的名字。其他文件是我運行之后生成的)
3.修改配置文件
<!-- Copyright (c) 2016 Oleg Nenashev and other contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. --> <!-- This is an example of a minimal Windows Service Wrapper configuration, which includes only mandatory options. This configuration file should be placed near the WinSW executable, the name should be the same. E.g. for myapp.exe the configuration file name should be myapp.xml You can find more information about the configuration options here: https://github.com/kohsuke/winsw/blob/master/doc/xmlConfigFile.md Full example: https://github.com/kohsuke/winsw/blob/master/examples/sample-allOptions.xml --> <service> <!--服務ID 要唯一--> <id>phpservice</id> <!-- 服務名字 --> <name>phpservice</name> <!--服務描述 --> <description>test php service </description> <!-- 要運行的文件 --> <executable>D:\PhpStudy\php\php-7.4.1-nts\php.exe</executable> <!-- 要執行的命令 --> <arguments>D:\PhpStudy\WWW\index.php</arguments> </service>
4.執行命令
// 安裝服務 phpservice.exe install // 啟動服務 phpservice.exe stop // 停止服務 phpservice.exe start // 重啟服務(修改配置文件后要重啟生效) phpservice.exe restart // 刪除服務 phpservice.exe uninstall
5.服務設置 (當服務崩潰的時候進行重啟)
查看服務已正常運行:
設置服務中斷后的操作:
主要參考
https://segmentfault.com/a/1190000019520072