2017 © Pedro Peláez
 

library gerar

PHP Configuration Management

image

gerar/gerar

PHP Configuration Management

  • Monday, February 3, 2014
  • by slava-vishnyakov
  • Repository
  • 12 Watchers
  • 61 Stars
  • 63 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 2 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

PHP configuration management

... because I'm too lazy to remember Puppet or Chef syntax., (*1)

This is an experiment in configuration management. Open example.php if you will., (*2)

Currently only Ubuntu is implemented. Probably going to implement CentOS later., (*3)

Installation (global)

All commands must be run as root, (*4)

apt-get update && apt-get install -y php5-cli && (wget -qO - http://git.io/FhkM4A | php)

run same command to update Gerar, (*5)

Example run

gerar --set-hostname your-host-name.com
gerar some-file.php

Examples

  • Install RVM, Ruby 2.0, Passenger and create passenger-add-host command

Read the source at http://git.io/oVoLFg, (*6)

wget -qO - http://git.io/oVoLFg | gerar
passenger-add-ruby-host test.com

You should now have directory to run your Passenger/Nginx Rails application., (*7)

Other examples

<?php namespace Gerar;

Hostname::change('vagrant.local');

Run stuff on specific hosts

Hostname::run('vagrant.local', function() {
    Console::log('Hello!');
});

Hostname::run('vagrant.local', function() {
    Ubuntu::fixLocales();
    Ubuntu::update();
});

Package and service management

Package::named('php5-cli mysql-server git imagemagick')
    ->shouldBeInstalled();

Service::named('apache2')
    ->shouldBeInstalled()
    ->shouldBeRunning()
    ->shouldBeRunningAtReboots();

One-time tasks

DoOnce::run('initializeServer', function() {
    Console::log('We have an ignition!');
});

HTTP requests

File::named('/var/www/index.html')->write('Bender is great!');

Http::request('http://localhost/')
    ->onSuccess(function($request, $response) {
        Console::log('My new code is "' . $response->getBody() . '"');
    })
    ->run();

Port monitoring

Port::number(810)
    ->ifNotResponding(function() {
        Console::log('Oops, port 810 is not responding, maybe we should start apache? Hint: won\'t help');
        Service::named('apache2')->start();

    });

File management

File::named('test.txt')->write(microtime(true));

File::named('test.txt')
    ->whenChanges(function() {
        Console::log('Hello, World appears!');
    })
    ->write('Hello, world!')
    ->replaceIfPresent('world', 'Gerar')
    ->replaceIfPresent(new Regexp('/He..o/'), 'Howdy');

User management

User::named('root')
    ->shouldHaveSshKey()
    ->mailPublicKeyOnce('user@super-server.com');

User::named('alex')
    ->shouldBePresent()
    ->haveSshKeyFrom('files/alex.ssh')
    ->shouldBeInGroup('sudo')
    ->shouldHaveNoPasswordSudoFor('/usr/sbin/service')
    ->shouldHaveSudoFor('/bin/vi');

IPs

Console::log('My external IP is ' . ThisServer::mainExternalIp());

/etc/hosts

EtcHosts::file()
    ->shouldResolve('rarestblog.com', '127.0.0.1')
    ->shouldNotResolve('rarestblog.com');

SSH server

Ssh::server()->securify();

What it does:, (*8)

User::shouldHaveOneSudoUserWithSshKey();
Ssh::server()
    ->shouldNotAllowRoot();
    ->shouldNotAllowPlainTextPasswords();

Does not work yet

Git projects

Git::src('git@github:')
    ->shouldBeAt('/home/git')
    ->shouldBeOnBranch('origin/production');

Cron

Cron::named('artisan-cleanup')
    ->ofUser('root')->shouldRun()->daily()->run('php artisan cleanup');

Nginx, Apache, serving rails and PHP

Nginx::server()
    ->shouldBeInstalled()
    ->shouldProxy('http://rarestblog.com/update-328719', 'http://localhost:8000/')
    ->shouldProxy('http://rarestblog.com/', 'http://localhost:9000/')
    ->shouldServePhpFpm('rarestblog.com', '/home/user/php/myApp/public')
    ->shouldServePhpFpm('rarestblog.com', '/home/user/php/myApp/public/index.php');

NginxPassenger::server()
    ->shouldBeInstalled()
    ->shouldServeRailsApp('/home/user/rails/my_app/public');

Apache::server()
    ->shouldServePhp('rarestblog.com', '/home/user/php/myApp/public');

Git webhooks and simple apps

WebApp('127.0.0.1', 8000)
    ->url('/update-182739')->shouldRun('cd /home/user && php update.php');

Testing

SshHost('backup')
    ->shouldBeAccessibleForUser('user');

Mysql

$password = RandomPassword::named('rarestblog-db-password');

MySQL::server()
    ->shouldHaveDatabase('rarestblog')
    ->shouldHaveUser('rarestblog', '127.0.0.1', $password)
    ->userShouldHaveFullAccessTo('rarestblog', '127.0.0.1', 'rarestblog.*');

File::named('/var/www/database.php')
    ->fromTemplate('files/database.php', array('password', $password));

Firewall

Firewall::rules()
    ->shouldAllowToPort(22, '234.234.234.234')
    ->shouldNotAllowAnyoneElseToPort(22);

Gerar()->shouldUpdateItselfEvery(15, 'minutes');

The Versions

03/02 2014

dev-master

9999999-dev https://github.com/slava-vishnyakov/gerar-php

PHP Configuration Management

  Sources   Download

MIT

configuration