Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Adds Wordpress demo as basis for tour.

  • Loading branch information...
commit c6e78c4cdc7f23b801373df54af1b8ea3c548007 1 parent 19a6c12
Henrik Lindberg hlindberg authored
23 .project
View
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>guide-stackhammer-tour</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.cloudsmith.geppetto.pp.dsl.ui.modulefileBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.cloudsmith.geppetto.pp.dsl.ui.puppetNature</nature>
+ <nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
+ </natures>
+</projectDescription>
9 modules/apache2/Modulefile
View
@@ -0,0 +1,9 @@
+name 'cloudsmith-apache2'
+version '0.1.0'
+
+author 'mruzicka'
+license ''
+project_page ''
+source ''
+summary 'Minimalistic Apache httpd for RedHat like OSs'
+description ''
11 modules/apache2/manifests/init.pp
View
@@ -0,0 +1,11 @@
+class apache2 {
+ package { 'httpd':
+ ensure => present,
+ }
+
+ service { 'httpd':
+ enable => true,
+ ensure => running,
+ require => Package['httpd'],
+ }
+}
9 modules/augeas/Modulefile
View
@@ -0,0 +1,9 @@
+name 'cloudsmith-augeas'
+version '0.1.0'
+
+author 'mruzicka'
+license ''
+project_page ''
+source ''
+summary 'Minimalistic Augaes for RedHat like OSs'
+description ''
38 modules/augeas/lib/facter/augeas_support.rb
View
@@ -0,0 +1,38 @@
+# This is a hack to install augeas during collecting of facts
+# so that even catalogs containing "augeas" resources can be
+# processed.
+lambda do # we wrap the code to a lambda so that we can use "return" to exit early
+ unless Puppet.features.augeas?
+ # We don't have augeas support so let's try to install the needed library.
+ begin
+ catalog = Puppet::Resource::Catalog.new()
+ catalog.add_resource(Puppet::Resource.new('Package', 'ruby-augeas'))
+ catalog.to_ral.apply()
+
+ # We need to re-open the Puppet module to reload the features
+ # as they are cached, otherwise the installation of ruby-augeas
+ # would go unnoticed.
+ module Puppet
+ @features = Puppet::Util::Feature.new('puppet/feature')
+ load 'puppet/feature/base.rb'
+ end
+
+ require 'augeas'
+ rescue SystemExit, NoMemoryError
+ raise
+ rescue Exception => e
+ Facter.debug("could not install augeas support: #{e}\n#{e.backtrace}")
+ return
+ end
+ end
+
+ Facter.add('augeas_support') do
+ setcode do
+ version = nil
+ Augeas::open('/', nil, Augeas::NO_MODL_AUTOLOAD) do |augeas|
+ version = augeas.get('/augeas/version')
+ end
+ version
+ end
+ end
+end.call
5 modules/augeas/manifests/init.pp
View
@@ -0,0 +1,5 @@
+class augeas {
+ package { 'augeas-libs':
+ ensure => present,
+ }
+}
10 modules/augeas/manifests/lens.pp
View
@@ -0,0 +1,10 @@
+define augeas::lens($source) {
+ file { "/usr/share/augeas/lenses/${name}.aug":
+ ensure => present,
+ source => "$source",
+ owner => root,
+ group => root,
+ mode => 0644,
+ require => Package['augeas-libs'],
+ }
+}
9 modules/mysql/Modulefile
View
@@ -0,0 +1,9 @@
+name 'cloudsmith-mysql'
+version '0.1.0'
+
+author 'mruzicka'
+license ''
+project_page ''
+source ''
+summary 'Minimalistic MySql for RedHat like OSs'
+description ''
15 modules/mysql/manifests/db.pp
View
@@ -0,0 +1,15 @@
+define mysql::db($user, $password) {
+ exec { "mysql_db_create-${name}":
+ unless => "mysql -u'root' ${name}",
+ command => "mysql -u'root' -e \"create database ${name};\"",
+ path => ['/usr/local/bin', '/bin', '/usr/bin'],
+ require => Service["mysqld"],
+ }
+
+ exec { "mysql_db_grant_privileges-${name}":
+ unless => "mysql -u'${user}' -p'${password}' ${name}",
+ command => "mysql -u'root' -e \"grant all on ${name}.* to '${user}'@'localhost' identified by '$password'; flush privileges;\"",
+ path => ['/usr/local/bin', '/bin', '/usr/bin'],
+ require => [Service["mysqld"], Exec["mysql_db_create-${name}"]],
+ }
+}
11 modules/mysql/manifests/init.pp
View
@@ -0,0 +1,11 @@
+class mysql {
+ package { 'mysql-server':
+ ensure => present,
+ }
+
+ service { 'mysqld':
+ enable => true,
+ ensure => running,
+ require => Package['mysql-server'],
+ }
+}
9 modules/php5/Modulefile
View
@@ -0,0 +1,9 @@
+name 'cloudsmith-php5'
+version '0.1.0'
+
+author 'mruzicka'
+license ''
+project_page ''
+source ''
+summary 'Minimalistic php for RedHat like OSs'
+description ''
7 modules/php5/manifests/init.pp
View
@@ -0,0 +1,7 @@
+class php5 {
+ include apache2
+
+ package { ['php', 'php-cli']:
+ ensure => present,
+ }
+}
9 modules/wordpress/Modulefile
View
@@ -0,0 +1,9 @@
+name 'cloudsmith-wordpress'
+version '0.1.0'
+
+author 'mruzicka'
+license ''
+project_page ''
+source ''
+summary 'Wordpress blog'
+description ''
83 modules/wordpress/files/wordpress.aug
View
@@ -0,0 +1,83 @@
+(* Wordpress configuration module for Augeas
+ Reference: PHP syntax
+*)
+
+module Wordpress
+ = autoload xfm
+
+(************************************************************************
+ * USEFUL PRIMITIVES *
+ ************************************************************************)
+
+let newline = /\r?\n/
+
+let php_prolog = del (/<\?php[ \t]*/ . newline) "<?php\n"
+
+let del_opt_ws_stem
+ = del /[ \t\n\r]*/
+
+let del_opt_ws = del_opt_ws_stem ""
+
+let del_opt_ws_sp
+ = del_opt_ws_stem " "
+
+let del_opt_ws_nl
+ = del_opt_ws_stem "\n"
+
+(************************************************************************
+ * COMMENTS *
+ ************************************************************************)
+
+let comment_c = del_opt_ws . Util.del_str "/*"
+ . [ label "comment-c" . store ((/[^*]/ | /(\*\*)*\*[^\/]/)*) ]
+ . Util.del_str "*/"
+
+let comment_cplusplus
+ = del_opt_ws_sp . Util.del_str "//"
+ . [ label "comment-c++" . store ((/[^\n\r]/ | /(\r\r)*\r[^\n]/)*) ]
+ . del newline "\n"
+
+let comment_shell
+ = del_opt_ws_sp . Util.del_str "#"
+ . [ label "comment-sh" . store ((/[^\n\r]/ | /(\r\r)*\r[^\n]/)*) ]
+ . del newline "\n"
+
+let comment = comment_c | comment_cplusplus | comment_shell
+
+(************************************************************************
+ * ENTRIES *
+ ************************************************************************)
+
+let identifier = /[A-Za-z_\177-\377][0-9A-Za-z_\177-\377]*/
+
+let quoted_identifier
+ = (/'/ . identifier . /'/) | (/"/ . identifier . /"/)
+
+let quoted_string
+ = /"([^"]|\\.)*"/ | /'([^']|\\.)*'/
+
+let boolean = /(true|false)/i
+
+let value = quoted_string | boolean
+
+let define = del_opt_ws_nl . Util.del_str "define" . del_opt_ws . Util.del_str "(" . del_opt_ws
+ . [ key quoted_identifier . del_opt_ws . Util.del_str "," . del_opt_ws . store value ]
+ . del_opt_ws . Util.del_str ")" . del_opt_ws . Util.del_str ";"
+
+let assignment = del_opt_ws_nl
+ . [ del /\$/ "$" . key identifier . del_opt_ws . Util.del_str "=" . del_opt_ws . store value ]
+ . del_opt_ws . Util.del_str ";"
+
+let entry = define | assignment
+
+let footer = del_opt_ws . [ label "footer" . (store /if[ \t\n\r]*\((.|\n)*/)? ]
+
+(************************************************************************
+ * LENS *
+ ************************************************************************)
+
+let lns = php_prolog . (comment|entry)* . footer
+
+let filter = incl "wp-config.php"
+
+let xfm = transform lns filter
42 modules/wordpress/manifests/config_param.pp
View
@@ -0,0 +1,42 @@
+define wordpress::config_param($wp_root, $key, $value) {
+ include internal::lens
+
+ # first try to see if there is a double quoted param of the specified name
+ # and if it is then replace it with a single quoted version and set it to the desired value
+ augeas { "wp_replace_double_quoted_config_param-${wp_root}-${key}":
+ incl => "${wp_root}/wp-config.php",
+ lens => 'Wordpress.lns',
+ context => "/files${wp_root}/wp-config.php",
+ onlyif => "match \"\\\"${key}\\\"\" != []",
+ changes => [
+ "insert \"'${key}'\" after \"\\\"${key}\\\"\"",
+ "remove \"\\\"${key}\\\"\"",
+ "set \"'${key}'\" \"'${value}'\"",
+ ],
+ require => [Augeas::Lens['wordpress'], File["${wp_root}/wp-config.php"]],
+ }
+
+ # if the parameter is not there yet, then insert it just before the footer
+ augeas { "wp_insert_new_config_param-${wp_root}-${key}":
+ incl => "${wp_root}/wp-config.php",
+ lens => 'Wordpress.lns',
+ context => "/files${wp_root}/wp-config.php",
+ onlyif => "match \"'${key}'\" == []",
+ changes => [
+ "insert \"'${key}'\" before \"footer\"",
+ "set \"'${key}'\" \"'${value}'\"",
+ ],
+ require => Augeas["wp_replace_double_quoted_config_param-${wp_root}-${key}"],
+ }
+
+ # else just set its value
+ augeas { "wp_set_config_param-${wp_root}-${key}":
+ incl => "${wp_root}/wp-config.php",
+ lens => 'Wordpress.lns',
+ context => "/files${wp_root}/wp-config.php",
+ changes => [
+ "set \"'${key}'\" \"'${value}'\"",
+ ],
+ require => Augeas["wp_insert_new_config_param-${wp_root}-${key}"],
+ }
+}
8 modules/wordpress/manifests/default.pp
View
@@ -0,0 +1,8 @@
+class wordpress::default {
+ wordpress::instance { 'blog':
+ }
+
+ wordpress::instance { 'blog2':
+ dbname => 'wordpress2',
+ }
+}
2  modules/wordpress/manifests/init.pp
View
@@ -0,0 +1,2 @@
+class wordpress {
+}
61 modules/wordpress/manifests/instance.pp
View
@@ -0,0 +1,61 @@
+define wordpress::instance($dbname = 'wordpress', $dbuser = 'wpdbuser', $dbpass = 'wpdbpass') {
+ include internal::prerequisites
+
+ $instance_alias = "$name"
+ $instance_root = "/var/www/wordpress-${instance_alias}"
+
+ file { "${instance_root}":
+ ensure => directory,
+ owner => root,
+ group => root,
+ mode => 0755,
+ }
+
+ exec { "wp_download-${instance_alias}":
+ command => "curl -sS \"http://wordpress.org/latest.tar.gz\" | tar -C \"${instance_root}\" --strip-components=1 --no-same-owner -xzf -",
+ path => ['/usr/local/bin', '/bin', '/usr/bin'],
+ creates => "${instance_root}/index.php",
+ require => [Package['httpd', 'curl', 'tar'], File["${instance_root}"]],
+ }
+
+ mysql::db { "$dbname":
+ user => "$dbuser",
+ password => "$dbpass",
+ }
+
+ file { "${instance_root}/wp-config.php":
+ ensure => present,
+ replace => false,
+ source => "${instance_root}/wp-config-sample.php",
+ require => Exec["wp_download-${instance_alias}"],
+ }
+
+ config_param { "wp_param-DB_NAME-${instance_alias}":
+ wp_root => "$instance_root",
+ key => 'DB_NAME',
+ value => "$dbname",
+ }
+ config_param { "wp_param-DB_USER-${instance_alias}":
+ wp_root => "$instance_root",
+ key => 'DB_USER',
+ value => "$dbuser",
+ }
+ config_param { "wp_param-DB_PASSWORD-${instance_alias}":
+ wp_root => "$instance_root",
+ key => 'DB_PASSWORD',
+ value => "$dbpass",
+ }
+
+ file { "/etc/httpd/conf.d/wordpress-${instance_alias}.conf":
+ ensure => present,
+ content => template('wordpress/wordpress.conf.erb'),
+ owner => root,
+ group => root,
+ mode => 0644,
+ require => [
+ Mysql::Db["$dbname"],
+ Config_param["wp_param-DB_NAME-${instance_alias}", "wp_param-DB_USER-${instance_alias}", "wp_param-DB_PASSWORD-${instance_alias}"],
+ ],
+ notify => Service['httpd'],
+ }
+}
5 modules/wordpress/manifests/internal/lens.pp
View
@@ -0,0 +1,5 @@
+class wordpress::internal::lens {
+ augeas::lens { 'wordpress':
+ source => 'puppet:///modules/wordpress/wordpress.aug',
+ }
+}
9 modules/wordpress/manifests/internal/prerequisites.pp
View
@@ -0,0 +1,9 @@
+class wordpress::internal::prerequisites {
+ include php5
+ include mysql
+ include augeas
+
+ package { ['curl', 'tar', 'php-mysql']:
+ ensure => present,
+ }
+}
45 modules/wordpress/templates/wordpress.conf.erb
View
@@ -0,0 +1,45 @@
+#
+# Wordpress configuration
+#
+Alias /<%= instance_alias %>/ "<%= instance_root %>/"
+Alias /<%= instance_alias %> "<%= instance_root %>"
+
+<Directory "<%= instance_root %>">
+ #
+ # Possible values for the Options directive are "None", "All",
+ # or any combination of:
+ # Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
+ #
+ # Note that "MultiViews" must be named *explicitly* --- "Options All"
+ # doesn't give it to you.
+ #
+ # The Options directive is both complicated and important. Please see
+ # http://httpd.apache.org/docs/2.2/mod/core.html#options
+ # for more information.
+ #
+ Options FollowSymLinks Indexes
+
+ #
+ # AllowOverride controls what directives may be placed in .htaccess files.
+ # It can be "All", "None", or any combination of the keywords:
+ # Options FileInfo AuthConfig Limit
+ #
+ AllowOverride None
+
+ #
+ # Cause the PHP interpreter to handle files with a .php extension.
+ #
+ AddHandler php5-script .php
+ AddType text/html .php
+
+ #
+ # Add index.php to the list of files that will be served as directory
+ # indexes.
+ #
+ DirectoryIndex index.php
+
+ #
+ # Controls who can get stuff from this server.
+ #
+ Order deny,allow
+</Directory>
Please sign in to comment.
Something went wrong with that request. Please try again.