Commit 33efeb79 authored by Joachim Mathes's avatar Joachim Mathes

TASK: Update fabfile

parent a5eef618
......@@ -4,29 +4,45 @@ fabric file proserver-box
from fabric.api import *
from fabric.colors import *
from fabric import state
from fabric.utils import abort
from fabric.contrib.project import rsync_project
import os
import sys
import subprocess
import yaml
env.hosts = ['172.17.28.100']
env.shell = '/usr/local/bin/bash -l -c'
def load_settings():
env.project_settings = yaml.load(open("settings.yaml", 'r'))
env.shell = '/usr/local/bin/bash -c'
state.output['everything'] = False
def boot_vagrant_box():
print(cyan('Downloading and starting proServer box. This may take some time ...'))
'''
Download and start proServer box. This may take some time ...
'''
print(cyan(boot_vagrant_box.__doc__))
local("vagrant up")
@runs_once
@with_settings(user='proserver')
def acquire_database_password():
'''
Acquire database password
'''
print(cyan(acquire_database_password.__doc__))
acquire_private_key_of_box()
env.database_password = run('php -r \'$configuration=include("/var/www/typo3/typo3conf/LocalConfiguration.php"); echo $configuration["DB"]["Connections"]["Default"]["password"];\'').stdout.strip()
@runs_once
def acquire_private_key_of_box():
print(cyan('Acquire private key of vagrant box'))
'''
Acquire private key of vagrant box
'''
print(cyan(acquire_private_key_of_box.__doc__))
private_key_path = subprocess.Popen("vagrant ssh-config | grep IdentityFile | awk '{print $2}'", shell=True, stdout=subprocess.PIPE).stdout.read().strip()
if env.key_filename is None and os.path.exists(private_key_path):
......@@ -35,15 +51,23 @@ def acquire_private_key_of_box():
@with_settings(user='vagrant')
def prepare_user_proserver():
print(cyan('Copy authorized keys of user vagrant to user proserver and set user proserver as fabric login user'))
'''
Copy authorized keys of user vagrant to user proserver and set user proserver as fabric login user
'''
print(cyan(prepare_user_proserver.__doc__))
sudo('cat /home/vagrant/.ssh/authorized_keys >> /home/proserver/.ssh/authorized_keys')
@with_settings(user='proserver')
def inject_and_initialize_project():
'''
Inject project into box and install it
'''
print(cyan(inject_and_initialize_project.__doc__))
rsync_project(
remote_dir='/var/www/',
remote_dir='/var/www/t3o',
exclude='.git')
with cd("/var/www/t3o"):
......@@ -53,49 +77,44 @@ def inject_and_initialize_project():
run('rm -rf typo3 && ln -s t3o/html typo3')
@task
@with_settings(user='proserver')
def download_initialized_project():
'''
Download initialized project
'''
print(cyan('Download initialized project'))
print(cyan(download_initialized_project.__doc__))
acquire_private_key_of_box()
rsync_project(
remote_dir='/var/www/t3o/*',
exclude=['.git', 'fabfile.py'],
exclude=['fabfile.py'],
extra_opts='-l',
upload=False)
@task
@with_settings(user='proserver')
def download_and_import_database():
'''
Download database from vpro0100.proserver.punkt.de and import in box.
'''
print(cyan('Download and import database'))
load_settings()
print(cyan(download_and_import_database.__doc__))
with settings(hide('stdout'), user='vagrant'):
mysql_root_password = sudo('cat /usr/local/etc/mysql-password').stdout.strip()
with cd("/tmp"):
run('curl -LsO https://vpro0100.proserver.punkt.de/sql/t3o.sql.gz')
run('mysql -u root -p%s -e "%s"' % (mysql_root_password, "CREATE DATABASE IF NOT EXISTS t3o"))
run('mysql -u root -p%s -e "%s"' % (mysql_root_password, "GRANT ALL ON t3o.* TO t3o@localhost identified by 'DOLU0qBHtdgyXjCvB4Q1A79McSrcfpjQ'"))
run('mysql -u root -p%s -e "CREATE DATABASE IF NOT EXISTS t3o"' % (mysql_root_password))
run('mysql -u root -p%s -e "GRANT ALL ON t3o.* TO t3o@localhost identified by \'%s\'"' % (mysql_root_password, env.database_password))
run("gunzip < t3o.sql.gz | mysql -u root -p%s" % (mysql_root_password))
@task
@with_settings(user='vagrant')
def restart_phpfpm():
'''
Restart php-fpm in box.
'''
print(cyan('Restarting php-fpm service'))
print(cyan(restart_phpfpm.__doc__))
sudo('/usr/local/etc/rc.d/php-fpm restart')
......@@ -106,7 +125,7 @@ def initialize_proserver_box():
'''
Initialize proServer box.
'''
print(cyan('Initialize proServer box'))
print(cyan(initialize_proserver_box.__doc__))
boot_vagrant_box()
acquire_private_key_of_box()
......@@ -123,15 +142,14 @@ def initialize_proserver_box():
@task
@hosts('vpro0100.proserver.punkt.de')
@with_settings(hide('stdout'), user='proserver')
@with_settings(user='proserver')
def dump_proserver_database():
'''
Dump TYPO3 database of proServer vpro0100.proserver.punkt.de.
=> ssh access to vpro0100.proserver.punkt.de required. <=
'''
print(cyan('Dumping database on proserver'))
print cyan(dump_proserver_database.__doc__)
load_settings()
acquire_database_password()
with cd('/var/www/surf/releases/current/html/sql/'):
run("mysqldump -u %(user)s -p%(password)s --add-drop-database --databases %(database)s | gzip > t3o.sql.gz" %
env.project_settings['hosts']['proserver']['databases']['typo3'])
run("mysqldump -u t3o -p%s t3o | gzip > t3o.sql.gz" % (env.database_password))
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment