thelfensdrfer/yii-ssh-console

SSH library for yii console commands

Installs: 10

Dependents: 0

Stars: 1

Watchers: 1

Forks: 2

Language: PHP

1.1.0 2014-05-14 12:05 UTC

README

Controller with ssh commands for the yii console.

Example

<?php 

class DeployCommand extends CConsoleCommand
{
    public $defaultAction = 'exec';

    public function actionExec()
    {
        $this->auth('example.com', [
            'username' => 'myusername',
            'password' => 'mypassword', // optional
        ]);

        // Or via private key
        /*
        $this->auth('example.com', [
            'username' => 'myusername',
            'key' => '/path/to/private.key',
            'password' => 'mykeypassword', // optional
        ]);
        */

        $output = $this->run('echo "test"');
        echo 'Output: ' . $output; // Output: test

        $output = $this->run([
            'cd /path/to/install',
            './put_offline.sh',
            'git pull -f',
            'composer install',
            './yii migrate --interactive=0',
            './build.sh',
            './yii cache/flush',
            './put_online.sh',
        ]);

        // Or via callback
        $this->run([
            'cd /path/to/install',
            './put_offline.sh',
            'git pull -f',
            'composer install',
            './yii migrate --interactive=0',
            './build.sh',
            './yii cache/flush',
            './put_online.sh',
        ], function($line) {
            echo $line;
        });
    }
}

And then in the local console:

./yiic deploy