mjanser / systemctl

该包已被 废弃 并不再维护。作者建议使用 icanhazstring/systemctl-php 包。

用于使用systemctl管理systemd服务的库

dev-master 2018-02-11 17:40 UTC

This package is auto-updated.

Last update: 2021-01-26 14:13:07 UTC


README

Build Status Code Coverage

此库可以用来管理systemd服务。内部使用 Symfony Process Component 来执行 systemctl 命令。

要求

  • PHP 7.0 或更高版本
  • systemd 已安装

安装

在您的项目中运行以下composer命令

composer require mjanser/systemctl

使用方法

示例用法

$service = new SystemCtl\Service('my-service');

if ($service->isRunning()) {
    $service->stop();
} else {
    $service->start();
}

$service->restart();

默认情况下,systemctl 命令将以 sudo 执行。如果需要,您可以更改此设置。

SystemCtl\Service::setCommand('my-systemctl');
SystemCtl\Service::sudo(false);