def reset_databases(dumpfile): """ Recreate mysql database based from given dump """ put(dumpfile, "dump.sql") mysql = Service('mysql') mysql.stop() sudo('rm -rf /var/lib/mysql/') sudo('mysql_install_db') mysql.start() # Set new password for tracuser password = prompt('Set password for database user "tracuser": '******'mysqladmin -u root password "%s"' % password) sudo(""" echo "UPDATE mysql.user SET password=password(\'\') WHERE user=\'tracuser\';" >> dump.sql echo "UPDATE mysql.user SET password=password(\'{0}\') WHERE user=\'root\';" >> dump.sql echo "UPDATE trac_admin.user SET sha1_pw=sha1(\'{0}\'), mail=\'root@localhost\';" >> dump.sql echo "flush privileges;" >> dump.sql mysql -u root --password={0} < dump.sql """.format(password)) sudo('rm dump.sql')
def deploy(package, opts=''): """ Uploads the given package to remote host and deploys it there. :param str package: Path to tar.gz package in local file system. In case of wildcard, all the matched package are deployed. Package can be in formats: tar.gz (custom package structure, deb, rpm :param str opts: Optional parameters to pass to deploying app (easy_install, rpm, dpkg, deploy.sh) Examples:: fab dist.deploy:package=../../package.tar.gz fab dist.deploy:package=../../package.tar.gz,opts="--theme --activate" fab dist.deploy:package=../../*.deb fab dist.deploy:package=../../*.deb,opts='--force' """ # Use glob to find package from local filesystem (glob supports wildcards) pmatches = glob(os.path.expandvars(os.path.expanduser(package))) if not pmatches: return abort('No package can be found with name: %s' % package) # Iterate matched packages # Upload package(s) to remote host and determine the name of release folder for pmatch in pmatches: package = os.path.normpath(pmatch) # Get the release name from package: drop the extension and version packagename = os.path.basename(package) releasename, releaseversion, releaseextension = split_package_name( packagename) # Upload package to home directory, with same as the orig logger.info('Uploading the package: %s -> %s' % (package, packagename)) put(package, packagename) logger.info('Release name: %s' % releasename) # Run the package specific deployment actions if releaseextension == 'tar.gz': deploy_targz(packagename, opts) elif releaseextension == 'egg': opts = opts or '-Z' sudo('easy_install %s %s' % (opts, packagename)) elif releaseextension == 'deb': opts = opts or '--install' sudo('dpkg %s %s' % (opts, packagename)) elif releaseextension == 'rpm': opts = opts or '-Uvh' sudo('rpm %s %s' % (opts, packagename)) # Remove the package with cd('~'): sudo('rm -f ./%s' % packagename) # Restart apache logger.info('Restarting apache') apache = Apache() apache.restart()
def deploy(package, opts=''): """ Uploads the given package to remote host and deploys it there. :param str package: Path to tar.gz package in local file system. In case of wildcard, all the matched package are deployed. Package can be in formats: tar.gz (custom package structure, deb, rpm :param str opts: Optional parameters to pass to deploying app (easy_install, rpm, dpkg, deploy.sh) Examples:: fab dist.deploy:package=../../package.tar.gz fab dist.deploy:package=../../package.tar.gz,opts="--theme --activate" fab dist.deploy:package=../../*.deb fab dist.deploy:package=../../*.deb,opts='--force' """ # Use glob to find package from local filesystem (glob supports wildcards) pmatches = glob(os.path.expandvars(os.path.expanduser(package))) if not pmatches: return abort('No package can be found with name: %s' % package) # Iterate matched packages # Upload package(s) to remote host and determine the name of release folder for pmatch in pmatches: package = os.path.normpath(pmatch) # Get the release name from package: drop the extension and version packagename = os.path.basename(package) releasename, releaseversion, releaseextension = split_package_name(packagename) # Upload package to home directory, with same as the orig logger.info('Uploading the package: %s -> %s' % (package, packagename)) put(package, packagename) logger.info('Release name: %s' % releasename) # Run the package specific deployment actions if releaseextension == 'tar.gz': deploy_targz(packagename, opts) elif releaseextension == 'egg': opts = opts or '-Z' sudo('easy_install %s %s' % (opts, packagename)) elif releaseextension == 'deb': opts = opts or '--install' sudo('dpkg %s %s' % (opts, packagename)) elif releaseextension == 'rpm': opts = opts or '-Uvh' sudo('rpm %s %s' % (opts, packagename)) # Remove the package with cd('~'): sudo('rm -f ./%s' % packagename) # Restart apache logger.info('Restarting apache') apache = Apache() apache.restart()
def upload(package, rdir=''): """ Uploads the given package to remote host :param str package: Path to package, absolute or relative :param str rdir: Remote directory where to upload the package. Defaults to users home directory Examples:: fab dist.upload:package.tar.gz,/tmp fab dist.upload:package=../../package.tar.gz fab dist.upload:package=../../packa*.tar.gz fab dist.upload:package=../../package.tar.gz,rdir=/tmp .. NOTE:: Special paths, containing environment variables or tilde characters are not supported. """ # Use glob to find package from local filesystem (glob supports wildcards) pmatches = glob(os.path.expandvars(os.path.expanduser(package))) if not pmatches: return abort('No package can be found with name: %s' % package) # Upload package(s) to remote host and determine the name of release folder for pmatch in pmatches: package = os.path.normpath(pmatch) # Get the release name from package: drop the extension and version packagename = os.path.basename(package) target_path = join(rdir, packagename) if rdir else packagename target_dir = os.path.dirname(target_path) # Upload package to specified directory, with the same name as the orig logger.info('Uploading the package: %s -> %s' % (package, target_path)) if not exists(target_dir): run(target_dir) put(package, target_path)