def setup(name, **kwargs): env = Environment.get_instance() config = env.config.mongodb.copy() config.update(kwargs) config['configpath'] = "/etc/mongodb/%s.conf" % name if 'dbpath' not in kwargs: config['dbpath'] = os.path.join(config.dbpath, name) if 'logfilename' not in kwargs: config['logfilename'] = "%s.log" % name Directory("/etc/mongodb", owner="root", group="root", mode=0755) Directory(config.dbpath, owner="mongodb", group="mongodb", mode=0755, recursive=True) File(config.configpath, owner="root", group="root", mode=0644, content=Template("mongodb/mongodb.conf.j2", variables=dict(mongodb=config))) # notifies = [("restart", env.resources["MonitService"]["mongodb-%s" % name])]) controller = kwargs.get("controller") if controller == "monit": env.include_recipe("monit") env.cookbooks.monit.rc( "mongodb-%s" % name, Template("mongodb/monit.conf.j2", variables=dict(name=name, mongodb=config))) env.cookbooks.monit.MonitService( "mongodb-%s" % name, subscribes=[("restart", env.resources["File"][config.configpath])]) elif controller == "supervisord": env.include_recipe("supervisor") env.cookbooks.supervisor.configuration( "mongodb-%s" % name, Template("mongodb/supervisord.conf.j2", variables=dict(name=name, mongodb=config))) env.cookbooks.supervisor.SupervisorService( "mongodb-%s" % name, subscribes=[("restart", env.resources["File"][config.configpath])]) else: Service("mongodb-%s" % name, subscribes=[("restart", env.resources["File"][config.configpath])]) File("/etc/init/mongodb-%s.conf" % name, owner="root", group="root", mode=0644, content=Template("mongodb/upstart.conf.j2", variables=dict(mongodb=config)), notifies=[ ("reload", env.resources["Service"]["mongodb-%s" % name], True), ])
def install_package(name, url, creates): import os filename = url.rsplit('/', 1)[-1] dirname = filename while dirname.rsplit('.', 1)[-1] in ('gz', 'tar', 'tgz', 'bz2'): dirname = dirname.rsplit('.', 1)[0] if not dirname: raise Fail( "Unable to figure out directory name of project for URL %s" % url) Script("install-%s" % name, not_if=lambda: os.path.exists(creates), cwd="/usr/local/src", code=("wget %(url)s\n" "tar -zxvf %(filename)s\n" "cd %(dirname)s\n" "./configure && make install\n" "ldconfig\n") % dict(url=url, dirname=dirname, filename=filename)) install_package( "skytools", creates="/usr/local/bin/pgqadm.py", url="http://pgfoundry.org/frs/download.php/2370/skytools-2.1.10.tar.gz") Directory("/etc/skytools", owner="root", mode=0755)
from kokki import Package, Directory, Link, File, Template env.include_recipe("cloudera") Package("flume") Directory("/etc/flume/conf.kokki", owner="root", group="root", mode=0755) Link("/etc/flume/conf", to="/etc/flume/conf.kokki") File("flume-config", path="/etc/flume/conf.kokki/flume-conf.xml", owner="root", group="root", mode=0644, content=Template("flume/flume-conf.xml.j2")) File("flume-site-config", path="/etc/flume/conf.kokki/flume-site.xml", owner="root", group="root", mode=0644, content=Template("flume/flume-site.xml.j2")) File("flume-log-config", path="/etc/flume/conf.kokki/log4j.properties", owner="root", group="root", mode=0644, content=Template("flume/log4j.properties.j2"))
dirname = filename while dirname.rsplit('.', 1)[-1] in ('gz', 'tar', 'tgz', 'bz2'): dirname = dirname.rsplit('.', 1)[0] if not dirname: raise Fail( "Unable to figure out directory name of project for URL %s" % url) Script("install-%s" % name, not_if=lambda: os.path.exists(creates), cwd="/usr/local/src", code=("wget %(url)s\n" "tar -zxvf %(filename)s\n" "cd %(dirname)s\n" "./configure && make install\n" "ldconfig\n") % dict(url=url, dirname=dirname, filename=filename)) Package("uuid-dev") Package("libevent-dev") Package("g++") install_package( "gearmand", creates="/usr/local/sbin/gearmand", url= "http://launchpad.net/gearmand/trunk/0.14/+download/gearmand-0.14.tar.gz") Directory("/var/run/gearmand", owner="nobody", mode=0755) env.cookbooks.monit.rc("gearmand", content=Template("gearmand/monit.conf.j2"))
notifies=[("run", env.resources["Execute"]["apt-update-mongo"], True)]) ### Package("mongodb-stable") if env.config.mongodb.nodefault: Service("mongodb") File(env.config.mongodb.configpath, action="delete", notifies=[("stop", env.resources["Service"]["mongodb"], True)]) File("/etc/init/mongodb.conf", action="delete") File("/etc/init.d/mongodb", action="delete") else: Directory(env.config.mongodb.dbpath, owner="mongodb", group="mongodb", mode=0755, recursive=True) Service("mongodb") File("/etc/init/mongodb.conf", owner="root", group="root", mode=0644, content=Template("mongodb/upstart.conf.j2", variables=dict(mongodb=env.config.mongodb)), notifies=[ ("restart", env.resources["Service"]["mongodb"], True), ])
import os from kokki import Package, File, Directory, Service, Template # env.include_recipe("monit") Package("supervisor") # provider = "kokki.providers.package.easy_install.EasyInstallProvider") File("supervisord.conf", path=env.config.supervisor.config_path, content=Template("supervisor/supervisord.conf.j2")) Directory("supervisor.d", path=env.config.supervisor.custom_config_path) supervisorctl = os.path.join(env.config.supervisor.binary_path, "supervisorctl") Service("supervisor", restart_command="%s reload" % supervisorctl, reload_command="%s update" % supervisorctl, subscribes=[("reload", env.resources["File"]["supervisord.conf"])]) #env.cookbooks.monit.rc("supervisord", # content = Template("supervisor/monit.conf.j2")) #env.cookbooks.monit.MonitService("supervisord", # subscribes = [("restart", env.resources["File"]["supervisord.conf"])])
import os from kokki import Directory, Package, File, Template, Service Package("python-rackspace-cloudfiles") Package("duplicity") Directory("{0}/dbdumps/".format(env.config.cloudfiles.deploy_home), owner = "postgres", group = "deploy", mode = 0750) # /etc/crontab and the files in /etc/cron.d must be owned by root# and must *not* be group- or other-writable File("/etc/cron.d/dbdumps", owner = "root", group = "root", mode = 0644, content = Template("postgresql-cloudfiles-backup/cronfile.j2"), ) File("{0}/duplicity_uploader.sh".format(env.config.cloudfiles.deploy_home), owner = "postgres", group = "postgres", mode = 0740, content = Template("postgresql-cloudfiles-backup/duplicity_uploader.sh.j2"), ) File("{0}/duplicity_downloader.sh".format(env.config.cloudfiles.deploy_home), owner = "postgres", group = "postgres", mode = 0740,
env.include_recipe("ssh") Group("sysadmin", gid=2300) for username, user in env.config.users.items(): home = "/home/%s" % username User(username, uid=user['id'], home=home, groups=user.get('groups', []), password=user.get('password')) Directory(env.cookbooks.ssh.ssh_path_for_user(username), owner=username, group=username, mode=0700) if user.get('sshkey'): env.cookbooks.ssh.SSHAuthorizedKey("%s-%s" % (username, user['sshkey_id']), user=username, keytype=user['sshkey_type'], key=user['sshkey']) File(os.path.join(env.cookbooks.ssh.ssh_path_for_user(username), "authorized_keys"), owner=username, group=username, mode=0600)
from kokki import Package, Directory, File, Template Package("munin") Directory(env.config.munin.dbdir, owner="munin", group="munin", mode=0755) File("/etc/munin/munin.conf", owner="root", group="root", mode=0644, content=Template("munin/munin.conf.j2"))
from kokki import Package, Directory, File, Template, Service Package("nginx") Directory(env.config.nginx.log_dir, mode=0755, owner=env.config.nginx.user, action='create') for nxscript in ('nxensite', 'nxdissite'): File("/usr/sbin/%s" % nxscript, content=Template("nginx/%s.j2" % nxscript), mode=0755, owner="root", group="root") File("nginx.conf", path="%s/nginx.conf" % env.config.nginx.dir, content=Template("nginx/nginx.conf.j2"), owner="root", group="root", mode=0644) File("%s/sites-available/default" % env.config.nginx.dir, content=Template("nginx/default-site.j2"), owner="root", group="root", mode=0644) Service("nginx", supports_status=True,
from kokki import Package, Directory, File, Template, Service if not env.config.nginx.user: if env.system.platform == "amazon": env.config.nginx.user = "******" else: env.config.nginx.user = "******" Package("nginx") Directory(env.config.nginx.log_dir, mode=0755, owner=env.config.nginx.user, action='create') for nxscript in ('nxensite', 'nxdissite'): File("/usr/sbin/%s" % nxscript, content=Template("nginx/%s.j2" % nxscript), mode=0755, owner="root", group="root") File("nginx.conf", path="%s/nginx.conf" % env.config.nginx.dir, content=Template("nginx/nginx.conf.j2"), owner="root", group="root", mode=0644) Directory("%s/sites-available" % env.config.nginx.dir, mode=0755,
from kokki import Directory, Execute, File, Template, Package, Service env.include_recipe("mysql.client") if env.system.platform in ("debian", "ubuntu"): Directory("/var/cache/local/preseeding", owner="root", group="root", mode=0755, recursive=True) Execute( "preseed mysql-server", command= "debconf-set-selections /var/cache/local/preseeding/mysql-server.seed", action="nothing") File("/var/cache/local/preseeding/mysql-server.seed", owner="root", group="root", mode=0600, content=Template("mysql/mysql-server.seed.j2"), notifies=[("run", env.resources["Execute"]["preseed mysql-server"], True)]) File("/etc/mysql/debian.cnf", owner="root", group="root", mode=0600, content=Template("mysql/debian.cnf.j2"))
import os from kokki import Package, Directory, Script, File, Service env.include_recipe("java.jre") Package("screen") Directory(env.config.minecraft.path, owner=env.config.minecraft.user) Script( "install-minecraft-server", not_if=lambda: os.path.exists( os.path.join(env.config.minecraft.path, "minecraft_server.jar")), code=("cd {config.minecraft.path}\n" "wget {config.minecraft.package_url}\n").format(config=env.config)) File( "%s/server.sh", mode=0755, content=("#!/bin/sh\n" "cd {0}\n" "java -Xmx1024M -Xms1024M -jar {0}/minecraft_server.jar nogui\n" ).format(env.config.minecraft.path), ) Service( "minecraft-server", start_command="screen -dmS minecraft -- %s/server.sh" % env.config.minecraft.path, stop_command='screen -S minecraft -X stuff "stop\n"', status_command="nc -z localhost 25565",
Service("monit", supports_status=False, supports_restart=True, action="nothing") File("%s/monitrc" % env.config.monit.config_path, owner="root", group="root", mode=0700, content=Template("monit/monitrc.j2"), notifies=[("restart", env.resources["Service"]["monit"])]) if env.system.platform == "ubuntu": File("/etc/default/monit", content=Template("monit/default.j2"), notifies=[("restart", env.resources["Service"]["monit"])]) Directory("%s/monit.d" % env.config.monit.config_path, owner="root", group="root", mode=0700) Directory("/var/monit", owner="root", group="root", mode=0700)
command = "apt-get update", action = "nothing") Execute("curl http://www.serverdensity.com/downloads/boxedice-public.key | apt-key add -", not_if = "(apt-key list | grep 'Server Density' > /dev/null)") File(apt_list_path, owner = "root", group ="root", mode = 0644, content = apt+"\n", notifies = [("run", env.resources["Execute"]["apt-update-serverdensity"], True)]) Package("sd-agent") Directory(env.config.serverdensity.plugin_directory, owner = "sd-agent", group = "sd-agent", mode = 0770, recursive = True) Service("sd-agent", supports_restart = True) File("/etc/sd-agent/config.cfg", owner = "sd-agent", group = "sd-agent", mode = 0660, content = Template("serverdensity/config.cfg.j2"), notifies = [("restart", env.resources["Service"]["sd-agent"])])
PLATFORM_CONFIGS = dict( centos="httpd", redhat="httpd", fedora="httpd", suse="httpd", debian="apache2", ubuntu="apache2", ) Package("apache2", package_name="httpd" if env.system.platform in ("centos", "redhat", "fedora", "suse") else "apache2") Directory(env.config.apache.log_dir, mode=0700, owner=env.config.apache.user, group=env.config.apache.user) if env.system.platform in ("centos", "redhat", "fedora", "suse"): Service("apache2", service_name="httpd", restart_command="/sbin/service httpd restart && sleep 1", reload_command="/sbin/service httpd reload && sleep 1", supports_restart=True, supports_reload=True, supports_status=True) File("/usr/local/bin/apache2_module_conf_generate.pl", mode=0755, owner="root",
from kokki import Directory, File, Template Directory("{0}gunicorn/".format(env.config.deploy_home), mode=0755, owner="deploy", action="create") for site in env.config.gunicorn.sites: File("{0}gunicorn/{1}.conf".format(env.config.deploy_home, site["name"]), content=Template( "gunicorn/gunicorn.conf.j2", variables={ "name": site["name"], "port": site["port"], "worker_count": site["worker_count"], "python_version": env.config.python_version, "virtualenvs_root": env.config.virtualenvs_root, }, ), owner="root", group="root", mode=0644)
File("pg_hba.conf", owner="postgres", group="postgres", mode=0600, path=os.path.join(env.config.postgresql9.config_dir, "pg_hba.conf"), content=Template("postgresql9/pg_hba.conf.j2"), notifies=[("reload", env.resources["Service"]["postgresql"])]) File("postgresql.conf", owner="postgres", group="postgres", mode=0600, path=os.path.join(env.config.postgresql9.config_dir, "postgresql.conf"), content=Template("postgresql9/postgresql.conf.j2"), notifies=[("restart", env.resources["Service"]["postgresql"])]) File("30-postgresql-shm.conf", owner="root", group="root", mode=0644, path="/etc/sysctl.d/30-postgresql-shm.conf", content=Template("postgresql9/30-postgresql-shm.conf.j2"), notifies=[("restart", env.resources["Service"]["postgresql"])]) # BUG requries reboot Directory("/usr/share/postgresql/9.1/contrib/", owner="root", group="root", mode=0655)
import os from kokki import Package, Directory, Execute, File, Template env.include_recipe("mongodb") env.include_recipe("supervisor") env.cookbooks.supervisor.SupervisorService("avatartare") Package("python-pycurl") Package("python-imaging") # Clone project Directory(os.path.dirname(env.config.avatartare.path), mode=0755) Execute( "git clone git://github.com/samuel/avatartare.git %s" % env.config.avatartare.path, creates=env.config.avatartare.path, ) # Bootstrap the environment Execute( "avatartare-bootstrap", command="python bin/bootstrap.py env", cwd=env.config.avatartare.path, creates="%s/env" % env.config.avatartare.path, ) # Config File("avatartare-local_settings.py", path="%s/local_settings.py" % env.config.avatartare.path, content=Template("avatartare/local_settings.py.j2"),
cwd = "/usr/local/src", code = ( "wget %(url)s\n" "tar -zxvf %(filename)s\n" "cd %(dirname)s\n" "make install\n") % dict(url=url, dirname=dirname, filename=filename)) Service("redis", supports_restart=True, supports_reload=True, supports_status=True, action="nothing") Directory(env.config.redis.dbdir, owner = "root", group = "root", mode = 0700, recursive = True) File("redis.conf", path = env.config.redis.configfile, owner = "root", group = "root", mode = 0644, content = Template("redis/redis.conf.j2"), notifies = [("reload", env.resources["Service"]["redis"], True)]) # env.cookbooks.monit.rc("redis", # content = Template("redis/monit.conf.j2")) File("/etc/init.d/redis",
import os from kokki import Package, File, Directory, Service, Template, Link # env.include_recipe("monit") if env.system.platform == "ubuntu": Package("supervisor") else: Package( "supervisor", provider="kokki.providers.package.easy_install.EasyInstallProvider") Directory(os.path.dirname(env.config.supervisor.config_path), action="create") Directory(env.config.supervisor.custom_config_path, action="create") Directory(os.path.dirname(env.config.supervisor.pidfile), action="create") Directory(os.path.dirname(env.config.supervisor.logfile), action="create") Directory(env.config.supervisor.childlogdir, action="create") if env.config.supervisor.config_path != "/etc/supervisord.conf": Link("/etc/supervisord.conf", to=env.config.supervisor.config_path) File("supervisord.conf", path=env.config.supervisor.config_path, content=Template("supervisor/supervisord.conf.j2")) Directory("supervisor.d", path=env.config.supervisor.custom_config_path) supervisorctl = os.path.join(env.config.supervisor.binary_path, "supervisorctl") Service("supervisor", restart_command="%s reload" % supervisorctl, reload_command="%s update" % supervisorctl,