icanhazstring / systemctl-php
systemctl的PHP封装
1.0-rc2
2019-04-07 11:28 UTC
Requires
- php: >=7.1.0
- league/plates: ^3.3
- symfony/process: ^3.2
Requires (Dev)
- adlawson/vfs: ^0.12.1
- codeclimate/php-test-reporter: dev-master
- jangregor/phpstan-prophecy: ^0.1.1
- phpstan/phpstan: ^0.9.2
- phpunit/phpunit: ^6.1
- squizlabs/php_codesniffer: ^3.0
README
systemctl的PHP封装
如何安装
$ composer require icanhazstring/systemctl-php
当前支持的单元
查看 单元
如果您想添加更多单元的支持,请自由地获取一个问题并做出贡献。
当前支持的命令
- 启动
- 停止
- 启用
- 禁用
- 重新加载
- 重启
- isEnabled
- isActive
如果您想添加更多命令的支持,请自由地做出贡献。
如何更改二进制文件
SystemCtl::setBinary('/bin/systemctl');
如何更改命令超时
要更改命令超时,只需调用静态方法setTimeout
。
SystemCtl::setTimeout(10);
默认超时设置为
3
秒
“我需要sudo来运行命令”
如果您需要sudo,应该使用sudo执行bin可执行文件。由于安全原因,已删除incode支持。
如何启动/停止/重启一个单元?
简单来说。首先我们实例化一个SystemCtl
实例并从特定类型加载一个单元。这里我们使用Service
。如果命令成功,您总是会得到true
。否则,该方法将抛出CommandFailedException
。
$systemCtl = new SystemCtl(); // start/stop/enable/disable/reload/restart $systemCtl->getService('nginx')->start(); $systemCtl->getService('nginx')->stop();
如何贡献
克隆仓库并使用composer
安装
$ composer install
修改您的更改,并确保您运行了test、codesniffer和phpstan。
$ composer test > vendor/bin/phpunit PHPUnit 9.5.3 by Sebastian Bergmann and contributors. ............................................................... 63 / 128 ( 49%) ............................................................... 126 / 128 ( 98%) .. 128 / 128 (100%) Time: 00:00.033, Memory: 10.00 MB OK (128 tests, 192 assertions) $ composer cs > vendor/bin/phpcs --standard=PSR2 src/ && vendor/bin/phpcs --standard=PSR2 tests/ $ $ composer analyse > vendor/bin/phpstan analyse --no-progress Note: Using configuration file /data/systemctl-php/phpstan.neon. [OK] No errors $
致谢
这个库在很大程度上受到了@mjanser php-systemctl的影响。