def hosts_conf(): notify('Writing hostname and hosts files.') cuisine.mode_sudo() sudo('echo "{NAME}" > /etc/hostname'.format(NAME=MACHINE['KEY'])) sudo('hostname -F /etc/hostname') hosts = cuisine.text_template(templates.hosts, MACHINE) cuisine.file_append('/etc/hosts', hosts)
def locale_conf(): notify('Configuring locale defaults.') sudo('locale-gen --purge en_US.UTF-8') sudo( 'echo -e "LANG=\'en_US.UTF-8\'\nLANGUAGE=\'en_US:en\'\n" > /etc/default/locale' ) sudo('dpkg-reconfigure -f noninteractive locales')
def ensure_production_settings(): notify('Configuring production settings.') context = SENSITIVE cuisine.mode_sudo() content = cuisine.text_template(templates.production_settings, context) cuisine.file_write(PROJECT['ROOT'] + '/moment/conf/production.py', content) restart()
def ensure_production_settings(): notify("Configuring production settings.") context = SENSITIVE cuisine.mode_sudo() content = cuisine.text_template(templates.production_settings, context) cuisine.file_write(PROJECT["ROOT"] + "/moment/conf/production.py", content) restart()
def link_conf(): notify('Configuring necessary symlinks for our libraries.') cuisine.mode_sudo() cuisine.file_link('/usr/lib/x86_64-linux-gnu/libjpeg.so', '/usr/lib/libjpeg.so', symbolic=True) cuisine.file_link('/usr/lib/x86_64-linux-gnu/libpng.so', '/usr/lib/libpng.so', symbolic=True) cuisine.file_link('/usr/lib/x86_64-linux-gnu/libz.so', '/usr/lib/libz.so', symbolic=True) cuisine.file_link('/usr/lib/x86_64-linux-gnu/libfreetype.so', '/usr/lib/libfreetype.so', symbolic=True) cuisine.file_link('/usr/lib/x86_64-linux-gnu/liblcms.so', '/usr/lib/liblcms.so', symbolic=True)
def bootstrap(): notify("Now starting the project bootstrap sequence") make_environment() clone() ensure_dependencies() ensure_production_settings() ensure_nginx() ensure_gunicorn() ensure_rq()
def upgrade(): notify("Now starting the project upgrade sequence") fetch() merge() ensure_dependencies() ensure_production_settings() ensure_nginx() ensure_gunicorn() ensure_rq()
def upgrade(): notify('Now starting the project upgrade sequence') fetch() merge() ensure_dependencies() ensure_production_settings() ensure_nginx() ensure_gunicorn() ensure_rq()
def bootstrap(): notify('Now starting the project bootstrap sequence') make_environment() clone() ensure_dependencies() ensure_production_settings() ensure_nginx() ensure_gunicorn() ensure_rq()
def dir_conf(): notify('Creating the working directory structure.') cuisine.mode_sudo() cuisine.dir_ensure(MACHINE['DIR_WORKSPACE']) cuisine.dir_ensure(MACHINE['DIR_ENVIRONMENTS'], recursive=True, mode=MACHINE['DIR_MODE'], owner=KEY, group=MACHINE['OWNER_GROUP']) cuisine.dir_ensure(MACHINE['DIR_PROJECTS'], recursive=True, mode=MACHINE['DIR_MODE'], owner=KEY, group=MACHINE['OWNER_GROUP']) cuisine.dir_ensure(MACHINE['DIR_SSL'], recursive=True, mode=MACHINE['DIR_MODE'], owner=KEY, group=MACHINE['OWNER_GROUP']) cuisine.dir_ensure(MACHINE['DIR_LOGS'], recursive=True, mode=MACHINE['DIR_MODE'], owner=KEY, group=MACHINE['OWNER_GROUP'])
def alert(self, item, message): try: for number in self.imessage_numbers: notify(number, item, message) except Exception as e: pprint(item, e, "FAIL") self.notifications += 1 if self.notifications >= self.options["max_notifications"]: self.stop()
def ensure_rq(): notify("Configuring RQ.") context = { "ACTION_DATE": MACHINE["ACTION_DATE"], "NAME": PROJECT["NAME"], "KEY": KEY, "PROJECT_ROOT": PROJECT["ROOT"], "PROJECT_ENV": PROJECT["ENV"], } cuisine.mode_sudo() content = cuisine.text_template(templates.rq_supervisor, context) cuisine.file_write("/etc/supervisor/conf.d/" + KEY + "-rq.conf", content) restart()
def ensure_rq(): notify('Configuring RQ.') context = { 'ACTION_DATE': MACHINE['ACTION_DATE'], 'NAME': PROJECT['NAME'], 'KEY': KEY, 'PROJECT_ROOT': PROJECT['ROOT'], 'PROJECT_ENV': PROJECT['ENV'], } cuisine.mode_sudo() content = cuisine.text_template(templates.rq_supervisor, context) cuisine.file_write('/etc/supervisor/conf.d/' + KEY + '-rq.conf', content) restart()
def bootstrap(): notify('Configuring the server.') tz_conf() locale_conf() apt_update() apt_upgrade() hosts_conf() dir_conf() apt_packages() custom_packages() pip_packages() profile_conf() firewall_conf() link_conf() reboot()
def ensure_nginx(): notify("Configuring nginx.") context = { "ACTION_DATE": MACHINE["ACTION_DATE"], "NAME": PROJECT["NAME"], "KEY": KEY, "APP_LOCATION": PROJECT["APP_LOCATION"], "APP_PORT": PROJECT["APP_PORT"], "LOCATION": MACHINE["LOCATION"], "PORT": MACHINE["PORT"], "PROJECT_ROOT": PROJECT["ROOT"], "ACCESS_LOG": PROJECT["LOGS"]["NGINX_ACCESS"], "ERROR_LOG": PROJECT["LOGS"]["NGINX_ERROR"], "SERVER_NAMES": " ".join(PROJECT["DOMAINS"]), } cuisine.mode_sudo() content = cuisine.text_template(templates.nginx, context) cuisine.file_write("/etc/nginx/sites-enabled/" + KEY, content) sudo("/etc/init.d/nginx restart")
def ensure_nginx(): notify('Configuring nginx.') context = { 'ACTION_DATE': MACHINE['ACTION_DATE'], 'NAME': PROJECT['NAME'], 'KEY': KEY, 'APP_LOCATION': PROJECT['APP_LOCATION'], 'APP_PORT': PROJECT['APP_PORT'], 'LOCATION': MACHINE['LOCATION'], 'PORT': MACHINE['PORT'], 'PROJECT_ROOT': PROJECT['ROOT'], 'ACCESS_LOG': PROJECT['LOGS']['NGINX_ACCESS'], 'ERROR_LOG': PROJECT['LOGS']['NGINX_ERROR'], 'SERVER_NAMES': ' '.join(PROJECT['DOMAINS']) } cuisine.mode_sudo() content = cuisine.text_template(templates.nginx, context) cuisine.file_write('/etc/nginx/sites-enabled/' + KEY, content) sudo('/etc/init.d/nginx restart')
def custom_packages(): notify('Installing custom packages.') notify('Installing PhantomJS') cuisine.mode_sudo() cuisine.dir_ensure(MACHINE['DIR_USER_HOME']) with cd(MACHINE['DIR_USER_HOME']): sudo( 'wget -N https://phantomjs.googlecode.com/files/phantomjs-1.9.1-linux-x86_64.tar.bz2 -O phantomjs.tar.bz2' ) sudo('tar jxvf phantomjs.tar.bz2') sudo('mv phantomjs-1.9.1-linux-x86_64 /etc/phantomjs') cuisine.file_link('/etc/phantomjs/bin/phantomjs', '/usr/bin/phantomjs', symbolic=True) notify('Installing CasperJS') cuisine.mode_sudo() cuisine.dir_ensure(MACHINE['DIR_USER_HOME']) with cd(MACHINE['DIR_USER_HOME']): sudo( 'wget -N https://codeload.github.com/n1k0/casperjs/legacy.tar.gz/1.0.3 -O casperjs.tar.bz2' ) sudo('tar xzvf casperjs.tar.bz2') sudo('mv n1k0-casperjs-76fc831 /etc/casperjs') cuisine.file_link('/etc/casperjs/bin/casperjs', '/usr/bin/casperjs', symbolic=True)
def ensure_gunicorn(): notify("Configuring gunicorn.") context = { "ACTION_DATE": MACHINE["ACTION_DATE"], "NAME": PROJECT["NAME"], "KEY": KEY, "APP_LOCATION": PROJECT["APP_LOCATION"], "APP_PORT": PROJECT["APP_PORT"], "APP_TIMEOUT": PROJECT["APP_TIMEOUT"], "APP_WSGI": PROJECT["APP_WSGI"], "APP_WORKERS": PROJECT["APP_WORKERS"], "LOCATION": MACHINE["LOCATION"], "PORT": MACHINE["PORT"], "PROJECT_ROOT": PROJECT["ROOT"], "PROJECT_ENV": PROJECT["ENV"], "ACCESS_LOG": PROJECT["LOGS"]["GUNICORN_ACCESS"], "ERROR_LOG": PROJECT["LOGS"]["GUNICORN_ERROR"], } cuisine.mode_sudo() content = cuisine.text_template(templates.gunicorn_supervisor, context) cuisine.file_write("/etc/supervisor/conf.d/" + KEY + "-gunicorn.conf", content) restart()
def apt_packages(databases=MACHINE['DATABASES']): notify('Installing all required system packages.') cuisine.package_ensure('ufw') cuisine.package_ensure('supervisor') cuisine.package_ensure('python-dev') cuisine.package_ensure('python-setuptools') cuisine.package_ensure('python-software-properties') cuisine.package_ensure('g++') cuisine.package_ensure('make') cuisine.package_ensure('cmake') cuisine.package_ensure('build-essential') cuisine.package_ensure('checkinstall') cuisine.package_ensure('imagemagick') cuisine.package_ensure('graphicsmagick-imagemagick-compat') cuisine.package_ensure('libxml2-dev') cuisine.package_ensure('libjpeg8-dev') cuisine.package_ensure('libpng-dev') cuisine.package_ensure('zlib1g-dev') cuisine.package_ensure('libfreetype6-dev') cuisine.package_ensure('liblcms1-dev') cuisine.package_ensure('python') cuisine.package_ensure('python-pip') cuisine.package_ensure('nginx') cuisine.package_ensure('git-core') cuisine.package_ensure('mercurial') if databases: if 'postgres' in databases: cuisine.package_ensure('postgresql') cuisine.package_ensure('postgresql-contrib') cuisine.package_ensure('postgresql-server-dev-all') # Not working, do manually #postgres_conf() if 'redis' in databases: cuisine.package_ensure('redis-server')
def ensure_gunicorn(): notify('Configuring gunicorn.') context = { 'ACTION_DATE': MACHINE['ACTION_DATE'], 'NAME': PROJECT['NAME'], 'KEY': KEY, 'APP_LOCATION': PROJECT['APP_LOCATION'], 'APP_PORT': PROJECT['APP_PORT'], 'APP_TIMEOUT': PROJECT['APP_TIMEOUT'], 'APP_WSGI': PROJECT['APP_WSGI'], 'APP_WORKERS': PROJECT['APP_WORKERS'], 'LOCATION': MACHINE['LOCATION'], 'PORT': MACHINE['PORT'], 'PROJECT_ROOT': PROJECT['ROOT'], 'PROJECT_ENV': PROJECT['ENV'], 'ACCESS_LOG': PROJECT['LOGS']['GUNICORN_ACCESS'], 'ERROR_LOG': PROJECT['LOGS']['GUNICORN_ERROR'], } cuisine.mode_sudo() content = cuisine.text_template(templates.gunicorn_supervisor, context) cuisine.file_write('/etc/supervisor/conf.d/' + KEY + '-gunicorn.conf', content) restart()
def custom_packages(): notify('Installing custom packages.') notify('Installing PhantomJS') cuisine.mode_sudo() cuisine.dir_ensure(MACHINE['DIR_USER_HOME']) with cd(MACHINE['DIR_USER_HOME']): sudo('wget -N https://phantomjs.googlecode.com/files/phantomjs-1.9.1-linux-x86_64.tar.bz2 -O phantomjs.tar.bz2') sudo('tar jxvf phantomjs.tar.bz2') sudo('mv phantomjs-1.9.1-linux-x86_64 /etc/phantomjs') cuisine.file_link('/etc/phantomjs/bin/phantomjs', '/usr/bin/phantomjs', symbolic=True) notify('Installing CasperJS') cuisine.mode_sudo() cuisine.dir_ensure(MACHINE['DIR_USER_HOME']) with cd(MACHINE['DIR_USER_HOME']): sudo('wget -N https://codeload.github.com/n1k0/casperjs/legacy.tar.gz/1.0.3 -O casperjs.tar.bz2') sudo('tar xzvf casperjs.tar.bz2') sudo('mv n1k0-casperjs-76fc831 /etc/casperjs') cuisine.file_link('/etc/casperjs/bin/casperjs', '/usr/bin/casperjs', symbolic=True)
def configure_user(): notify('Configuring user.') sudo('adduser moment', user='******') sudo('usermod -a -G sudo moment', user='******')
def pip_packages(): notify('Installing required system python packages.') cuisine.mode_sudo() cuisine.python_package_ensure('virtualenv') cuisine.python_package_ensure('virtualenvwrapper')
def locale_conf(): notify('Configuring locale defaults.') sudo('locale-gen --purge en_US.UTF-8') sudo('echo -e "LANG=\'en_US.UTF-8\'\nLANGUAGE=\'en_US:en\'\n" > /etc/default/locale') sudo('dpkg-reconfigure -f noninteractive locales')
def flushall(): notify('Flushing ALL Redis keys.') local('redis-cli FLUSHALL')
def deploy(): notify("Now starting the project deploy sequence") fetch() merge() restart()
def profile_conf(): notify('Configuring .profile settings.') profile = cuisine.text_template(templates.profile, MACHINE) cuisine.file_append(MACHINE['OWNER_PROFILE'], profile) run('source ' + MACHINE['OWNER_PROFILE'])
def tz_conf(): notify('Configuring timezone defaults.') sudo('echo "Etc/UTC" > /etc/timezone') sudo('dpkg-reconfigure -f noninteractive tzdata')
def deploy(): notify('Now starting the project deploy sequence') fetch() merge() restart()