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 giving instructions to the server., (*2)

Important: to correctly use this library you must validate your code with vimeo/psalm, (*3)

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\TimeContinuum\Earth\Clock;
use Innmind\TimeWarp\Halt\Usleep;
use Innmind\Stream\Streams;
use Innmind\Url\Path;
use Innmind\Immutable\Str;

$server = ServerFactory::build(
    new Clock,
    Streams::fromAmbientAuthority(),
    new Usleep,
);
$server
    ->processes()
    ->execute(
        Command::foreground('bin/console')
            ->withArgument('debug:router')
    )
    ->output()
    ->foreach(static function(Str $data, Type $type): void {
        $type = match ($type) {
            Type::error => 'ERR : ',
            Type::output => '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:, (*4)

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., (*5)

Remote server control

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

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

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

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

Logging

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

$server = Logger::psr($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