2017 © Pedro Peláez
 

library server-control

Allows to control the server from php

image

innmind/server-control

Allows to control the server from php

  • Saturday, April 14, 2018
  • by Baptouuuu
  • Repository
  • 1 Watchers
  • 0 Stars
  • 871 Installations
  • PHP
  • 13 Dependents
  • 1 Suggesters
  • 0 Forks
  • 0 Open issues
  • 12 Versions
  • 13 % Grown

The README.md

ServerControl

Build Status codecov Type Coverage, (*1)

Give access to giev instructions to the server., (*2)

Installation

composer require innmind/server-control

Usage

use Innmind\Server\Control\{
    ServerFactory,
    Server\Command,
    Server\Process\Output\Type,
    Server\Process\Pid,
    Server\Signal,
    Server\Volumes\Name,
};
use Innmind\Url\Path;
use Innmind\Immutable\Str;

$server = ServerFactory::build();
$server
    ->processes()
    ->execute(
        Command::foreground('bin/console')
            ->withArgument('debug:router')
    )
    ->output()
    ->foreach(static function(Str $data, Type $type): void {
        $type = $type === Type::error() ? 'ERR : ' : 'OUT : ';

        echo $type.$data->toString();
    });
$server
    ->processes()
    ->kill(
        new Pid(42),
        Signal::kill()
    );
$server->volumes()->mount(new Name('/dev/disk2s1'), Path::of('/somewhere')); // the path is only interpreted for linux
$server->volumes()->unmount(new Name('/dev/disk2s1'));
$server->reboot();
$server->shutdown();

Scripts

Sometimes you may want to run a set of commands on your server. You can easily do so like this:, (*3)

use Innmind\Server\Control\Server\Script;

$script = Script::of(
    'apt-get install php-fpm -y',
    'service nginx start',
);
$script($server);

If any command fails, it will stop the script and raise an exception., (*4)

Remote server control

use Innmind\Server\Control\Servers\Remote;
use Innmind\Url\Authority\{
    Host,
    Port,
    UserInformation\User,
};

$server = new Remote(
    $server,
    new User('john'),
    new Host('example.com'),
    new Port(42),
);
$server->processes()->execute(new Command('ls'));

This will run ssh -p 42 john@example.com ls., (*5)

Important: specifying environment variables or an input stream will not be taken into account on the remote server., (*6)

Logging

use Innmind\Server\Control\Servers\Logger;
use Psr\Log\LoggerInterface;

$server = new Logger($server, /** an instance of LoggerInterface */);

The Versions

14/11 2017
07/10 2017
29/05 2017

1.0.0

1.0.0.0 http://github.com/Innmind/ServerControl

Allows to control the server from php

  Sources   Download

MIT

The Requires

 

The Development Requires