Skip to content
Browse files

Ported wordpress sketch to cf-sketch format.

Included params/wordpress-base.json contains the system-specific params
for different systems, and params/wordpress.json contains the
user-configurable parameters.
  • Loading branch information...
1 parent 574e827 commit cbd89aa792d31012f09dea27a63df174ef22ded2 @zzamboni zzamboni committed Jun 5, 2012
View
69 sketches/web_apps/wordpress/README.md
@@ -1,58 +1,45 @@
# Install and configure Wordpress
-Original author: Aleksey Tsalolikhin. Enhancements and maintenance: Diego Zamboni.
+Authors: Aleksey Tsalolikhin, Diego Zamboni.
-This sketch contains bundles to install and configure a Wordpress installation.
+This sketch installs and configures a Wordpress installation.
-## Sample usage
+## Usage
- body common control
- {
- bundlesequence => { wp_install("g.wp_config") };
- inputs => { "cfengine_stdlib.cf", "sketches/wordpress/wordpress.cf" };
- }
+Install the sketch using cf-sketch:
+
+ cf-sketch --install WebApps::wordpress_install
- bundle common g
+Look at `params/wordpress.json` for the minimum set of parameters that
+you need to configure:
+
{
- vars:
- "wp_config[DB_NAME]" string => "wordpress";
- "wp_config[DB_USER]" string => "wordpress";
- "wp_config[DB_PASSWORD]" string => "lopsa10linux";
- debian::
- "wp_config[_htmlroot]" string => "/var/www";
- redhat::
- "wp_config[_htmlroot]" string => "/var/www/html";
- any::
- "wp_config[_wp_dir]" string => "$(wp_config[_htmlroot])/blog";
+ "wp_dir" : "/var/www/wordpress",
+ "wp_params" : {
+ "DB_NAME" : "wordpress_db",
+ "DB_USER" : "wordpress_user",
+ "DB_PASSWORD" : "wordpress_pass"
+ },
+ "include": [ "wordpress-base.json" ],
}
-Any parameters in `params` that do not start with an underscore (`_`)
-will be edited/added to the `wp-config.php` file. You can use this to
-modify any other Wordpress parameters you want, for example:
+The `params/wordpress-base.json` file contains system-specific
+parameters that you can also configure. As shipped, this file contains
+the parameters for `debian`, `redhat` and `centos` systems.
- "wp_config[AUTH_KEY]" string => "foobarbaz";
+Once you have configured the parameters file, enable the sketch using
+cf-sketch:
-## Public entry points
+ cf-sketch --activate WebApps::wordpress_install --params /var/cfengine/masterfiles/params/wordpress.json
-- bundle agent wp_install(params)
+Finally, you can generate the runfile, either as a standalone file, or
+ready to be included in other policy files:
- Make sure wordpress is installed and configured correctly.
- Mandatory parameters in the "params" array:
-
- - `DB_NAME`
- - `DB_USER`
- - `DB_PASSWORD`
- - `_htmlroot`
- - `_wp_dir` (final wordpress install directory)
-
-- bundle agent wp_config(params)
-
- Make sure wordpress is configured correctly. It must be installed already.
- Mandatory parameters in the "params" array:
-
- - `_wp_dir` (directory where wordpress is installed)
+ cf-sketch --generate
+
+ cf-sketch --generate --no-standalone
-## Steps followed by `wp_install`
+## Steps followed by the sketch
1. Install Infrastructure:
1. Install httpd and mod_php and PHP MySQL client.
View
53 sketches/web_apps/wordpress/params/wordpress-base.json
@@ -0,0 +1,53 @@
+{
+ "activated" : true,
+ "wp_dir" : "/var/www/wordpress",
+ "wp_params" : {
+ "DB_NAME" : "wordpress_db",
+ "DB_USER" : "wordpress_user",
+ "DB_PASSWORD" : "wordpress_pass"
+ },
+ "bycontext" : {
+ "debian": {
+ "htmlroot" : "/var/www",
+ "packages" : [
+ "apache2",
+ "php5",
+ "php5-mysql",
+ "mysql-server"
+ ],
+ "mysql_process" : "/usr/sbin/mysqld",
+ "httpd_process" : "/usr/sbin/apache2",
+ "service_cmd" : "/usr/sbin/service",
+ "apache_srv" : "apache2",
+ "mysql_srv" : "mysqld"
+ },
+ "redhat": {
+ "htmlroot" : "/var/www/html",
+ "packages" : [
+ "httpd",
+ "php",
+ "php-mysql",
+ "mysql-server"
+ ],
+ "mysql_process" : "^mysqld",
+ "httpd_process" : "^httpd",
+ "service_cmd" : "/sbin/service",
+ "apache_srv" : "httpd",
+ "mysql_srv" : "mysqld"
+ },
+ "centos": {
+ "htmlroot" : "/var/www/html",
+ "packages" : [
+ "httpd",
+ "php",
+ "php-mysql",
+ "mysql-server"
+ ],
+ "mysql_process" : "/usr/libexec/mysqld",
+ "httpd_process" : "/usr/sbin/httpd",
+ "service_cmd" : "/sbin/service",
+ "apache_srv" : "httpd",
+ "mysql_srv" : "mysqld"
+ },
+ }
+}
View
37 sketches/web_apps/wordpress/params/wordpress.json
@@ -1,42 +1,9 @@
{
- "activated" : true,
+ "wp_dir" : "/var/www/wordpress",
"wp_params" : {
"DB_NAME" : "wordpress_db",
"DB_USER" : "wordpress_user",
"DB_PASSWORD" : "wordpress_pass"
},
- "bycontext" : {
- "debian": {
- "htmlroot" : "/var/www",
- "wp_dir" : "/var/www/wordpress",
- "packages" : [
- "apache2",
- "php5",
- "php5-mysql",
- "mysql-server"
- ],
- "mysql_process" : "/usr/sbin/mysqld",
- "httpd_process" : "/usr/sbin/apache2",
- "service_cmd" : "/usr/sbin/service",
- "apache_srv" : "apache2",
- },
- "redhat": {
- "htmlroot" : "/var/www/html",
- "wp_dir" : "/var/www/html/wordpress",
- "packages" : [
- "httpd",
- "php",
- "php-mysql",
- "mysql-server"
- ],
- "mysql_process" : "^mysqld",
- "httpd_process" : "^httpd",
- "service_cmd" : "/sbin/service",
- "apache_srv" : "httpd",
- },
- "any" : {
- "mysql_srv" : "httpd",
- }
- }
+ "include": [ "wordpress-base.json" ],
}
-
View
1 sketches/web_apps/wordpress/sketch.json
@@ -5,6 +5,7 @@
"wordpress.cf": { "desc": "main file" },
"README.md": { "documentation": true },
+ "params/wordpress-base.json": { "comment": "Base configuration parameters for different platforms" },
"params/wordpress.json": { "comment": "Example configuration parameters" },
},
View
34 sketches/web_apps/wordpress/wordpress.cf
@@ -30,7 +30,7 @@ bundle agent wp_install(prefix)
"wp_svcs" usebundle => wp_services_up("wp_vars.conf");
"wp_tar" usebundle => wp_tarball_is_present("wp_vars.conf");
"wp_xpnd" usebundle => wp_tarball_is_unrolled("wp_vars.conf");
- "wp_mysql" usebundle => wp_mysql_configuration("wp_vars.conf");
+ "wp_mysql" usebundle => wp_mysql_configuration("wp_vars.conf", "$(prefix)wp_params");
"wp_cfgcp" usebundle => wp_config_exists("wp_vars.conf");
"wp_cfg" usebundle => wp_is_properly_configured("wp_vars.conf", "$(prefix)wp_params");
}
@@ -56,27 +56,17 @@ bundle agent meta_wp_install
"argument[bycontext]" string => "array";
}
-# Make sure wordpress is configured correctly. It must be installed already.
-# Mandatory parameters in the "params" array:
-# _wp_dir (directory where wordpress is installed)
-bundle agent wp_config(params)
-{
- methods:
- "wp_vars" usebundle => wp_vars("$(params)");
- "wp_cfgcp" usebundle => wp_config_exists("wp_vars.conf");
- "wp_cfg" usebundle => wp_is_properly_configured("wp_vars.conf");
-}
-
#############################################
bundle agent wp_vars(prefix, context)
{
vars:
"class_prefix" string => lastnode("$(prefix)", "\."); # strip out the bundle prefix
- "wp_dir" string => "$($(prefix)bycontext[$(context)][wp_dir])";
+ "wp_dir" string => "$($(prefix)wp_dir)";
# Default configuration values. Internal parameters start with _
"conf[_htmlroot]" string => "$($(prefix)bycontext[$(context)][htmlroot])";
+ "conf[_wp_dir]" string => "$($(prefix)wp_dir)";
"conf[_tarfile]" string => "$($(prefix)tarfile)";
"conf[_downloadurl]" string => "$($(prefix)downloadurl)";
"conf[_wp_config]" string => "$(wp_dir)/wp-config.php";
@@ -142,7 +132,7 @@ bundle agent wp_tarball_is_present(params)
comment => "Downloading latest version of WordPress.";
reports:
- wordpress_tarball_is_present::
+ wordpress_tarball_is_present.verbose::
"WordPress tarball is on disk.";
}
@@ -155,7 +145,7 @@ bundle agent wp_tarball_is_unrolled(params)
"wordpress_final_dir_is_present" expression => fileexists("$($(params)[_wp_dir])");
reports:
- wordpress_final_dir_is_present::
+ wordpress_final_dir_is_present.verbose::
"WordPress directory is present.";
commands:
@@ -170,14 +160,14 @@ bundle agent wp_tarball_is_unrolled(params)
#############################################
-bundle agent wp_mysql_configuration(params)
+bundle agent wp_mysql_configuration(params, wpparams)
{
commands:
"/usr/bin/mysql -u root -e \"
- CREATE DATABASE IF NOT EXISTS $($(params)[DB_NAME]);
- GRANT ALL PRIVILEGES ON $($(params)[DB_NAME]).*
- TO '$($(params)[DB_USER])'@localhost
- IDENTIFIED BY '$($(params)[DB_PASSWORD])';
+ CREATE DATABASE IF NOT EXISTS $($(wpparams)[DB_NAME]);
+ GRANT ALL PRIVILEGES ON $($(wpparams)[DB_NAME]).*
+ TO '$($(wpparams)[DB_USER])'@localhost
+ IDENTIFIED BY '$($(wpparams)[DB_PASSWORD])';
FLUSH PRIVILEGES;\"
";
}
@@ -196,9 +186,9 @@ bundle agent wp_config_exists(params)
copy_from => backup_local_cp("$($(params)[_wp_cfgsample])");
reports:
- wordpress_config_file_exists::
+ wordpress_config_file_exists.verbose::
"WordPress config file $($(params)[_wp_config]) is present";
- !wordpress_config_file_exists::
+ !wordpress_config_file_exists.verbose::
"WordPress config file $($(params)[_wp_config]) is not present";
}

0 comments on commit cbd89aa

Please sign in to comment.
Something went wrong with that request. Please try again.