icanhazstring / systemctl-php
PHP wrapper for systemctl
Installs: 13 598
Dependents: 2
Suggesters: 0
Security: 0
Stars: 72
Watchers: 6
Forks: 15
Open Issues: 2
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
PHP wrapper for systemctl
How to install
$ composer require icanhazstring/systemctl-php
Current supported units
See Units
If you like to add support for more units, feel free to grab an issue and contribute.
Current supported commands
- start
- stop
- enable
- disable
- reload
- restart
- isEnabled
- isActive
If you like to add support for more commands, feel free to contribute.
How to change the binary
SystemCtl::setBinary('/bin/systemctl');
How to change command timeout
To change command tmeout simply call the static method setTimeout
.
SystemCtl::setTimeout(10);
The default timeout is set to
3
seconds
"I need sudo to run commands"
If you need sudo, you should execute the bin executable with sudo. The incode support was dropped due to security reason.
How do I start/stop/restart a unit?
Simply is that. First we instantiate a SystemCtl
instance an load a unit from a specific type. Here we use a Service
. You will always get back true
if the command succeeded. Otherwise the method will throw a CommandFailedException
.
$systemCtl = new SystemCtl(); // start/stop/enable/disable/reload/restart $systemCtl->getService('nginx')->start(); $systemCtl->getService('nginx')->stop();
How to Contribute
Clone the repo and install using composer
$ composer install
Make your changes and make sure you run test, codesniffer and 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 $
Credits
This library is heavily influenced by @mjanser php-systemctl.