Hi
I automating the install of Piwik on my server using fabric. See http://docs.fabfile.org/
I wanted to know if anyone had any suggestions to automate the config file creation process rather than have to use the webpage?
def install_piwik():
""" Install the pretty Piwik web analytics software """
sudo('mkdir -p %(www_path)s/%(piwikdomain)s/{public,private,log,cgi-bin,backup}' % env, pty=True)
apt_get('p7zip-full')
with cd('/tmp'):
# MAKE SURE YOU HAVE PROXY SET in /etc/wgetrc
sudo('wget -q http://piwik.org/latest.zip',pty=True)
#fabric.contrib.files.exists(path, use_sudo=False, verbose=False)
if exists('/tmp/piwik'):
sudo('rm -fR /tmp/piwik',pty=True)
sudo('7za x -y latest.zip',pty=True)
sudo('cp -r /tmp/piwik/* %(www_path)s/%(piwikdomain)s/public' % env) #,pty=True)
fix_perms_piwik()
install_piwik_apache()
db_create_piwik()
def install_piwik_apache():
""" Install the piwik apache configurations"""
put('etc/apache2/sites-available/piwik_site_template', '/tmp')
sed('/tmp/piwik_site_template', 'piwik_site_template', '%(piwikdomain)s' % env, limit='' , use_sudo=True)
sudo('cp /tmp/piwik_site_template /etc/apache2/sites-available/%(piwikdomain)s' % env,pty=True)
# With custom dir structure for website we need to make sure logfile is also kept undercontrol
# http://articles.slicehost.com/2010/6/30/understanding-logrotate-on-ubuntu-part-1
put('etc/logrotate.d/my_website_domain_template','/tmp')
sed('/tmp/my_website_domain_template', 'template_dir_path_for_website', '%(www_path)s/%(piwikdomain)s' % env, limit='' , use_sudo=True)
sed('/tmp/my_website_domain_template', 'template_dir_owner', '%(www_user)s' % env, limit='' , use_sudo=True)
sed('/tmp/my_website_domain_template', 'template_dir_group', '%(www_user)s' % env, limit='' , use_sudo=True)
sudo('cp /tmp/my_website_domain_template /etc/logrotate.d/%(piwikdomain)s' % env,pty=True)
apache_ensite('%(piwikdomain)s' % env)
apache_reload()
def fix_perms_piwik():
""" Fix the permissions on the piwik directory """
piwikdir="%(www_path)s/%(piwikdomain)s/public" % env
if env.fix_perms:
# All files should be owned by your user account, and should be writable by you.
sudo("chown -Rf %(www_user)s:%(apache_group)s %(www_path)s;" % env, pty=True)
# Default permissions
sudo("find %(www_path)s -type f -exec chmod 0644 {} \;" % env, pty=True)
sudo("find %(www_path)s -type d -exec chmod 2775 {} \;" % env, pty=True)
sudo("find %(www_path)s/%(piwikdomain)s/public/ -maxdepth 1 -type f -exec chmod 644 {} \; " % env, pty=True)
def db_create_piwik():
""" Create My-SQL database for piwik site """
env.db_name_piwik='piwik'
env.db_piwikuser_name='xxxxxxx'
env.db_piwikuser_pass='pppppppp'
if not env.db_root_pass:
env.db_root_pass = getpass("Database password: ")
run('mysqladmin --host=%(db_host)s --user=%(db_root_user)s --password=%(db_root_pass)s create %(db_name_piwik)s' % env,pty=True)
# To work with databases
# mysql -u root -p
# Use mysql> show databases; to list all databases.
run('echo "GRANT ALL PRIVILEGES ON %(db_name_piwik)s.* TO \'%(db_piwikuser_name)s\'@\'localhost\' IDENTIFIED BY \'%(db_piwikuser_pass)s\';" | mysql --host=%(db_host)s --user=%(db_root_user)s --password=%(db_root_pass)s %(db_name_piwik)s' % env,pty=True)