From 0f1f7844ba66c532890df1cd485840b350d50528 Mon Sep 17 00:00:00 2001
From: smarcet <smarcet@gmail.com>
Date: Tue, 28 Jan 2014 13:03:39 -0300
Subject: [PATCH] Clean up puppet (deploy LAMP / setup app config)

Implements: blueprint openid-oauth2-infra-implementation-puppet-script

Prepares a raw server with all software stack needed to run
openstackid project:

* installs PHP
* installs Apache
* installs Redis Server
* creates a initial environment configuration for laravel application
  (using *.erb templates)

Change-Id: If6216da0d70a45609076e8111a67055dbc87c9e4
---
 manifests/init.pp            | 45 ++++++++++++++----------------------
 templates/init_script.erb    | 42 ---------------------------------
 templates/redis.2.2.conf.erb |  8 ++++---
 templates/redis.2.4.conf.erb |  8 ++++---
 templates/redis.2.6.conf.erb |  8 ++++---
 5 files changed, 32 insertions(+), 79 deletions(-)
 delete mode 100644 templates/init_script.erb

diff --git a/manifests/init.pp b/manifests/init.pp
index 07ad604..74b7aa2 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -18,14 +18,14 @@
 
 class redis(
   $redis_port = '6379',
-  $redis_max_memory = '1gb',
   $redis_bind = '127.0.0.1',
-  $redis_bin_dir = '/usr/bin',
+  $redis_password = '',
+  $redis_max_memory = '1gb',
   $version = '2.2.12',
 ) {
 
   package {'redis-server':
-    ensure  => installed,
+    ensure  => present,
   }
 
   case $version {
@@ -43,31 +43,20 @@ class redis(
     }
   }
 
-  file { '/etc/init.d/redis-server':
-    ensure  => present,
-    owner   => 'root',
-    group   => 'root',
-    mode    => '0755',
-    require => Package['redis-server'],
-    content => template('redis/init_script.erb'),
-  }
-
   file { '/etc/redis/redis.conf':
-    ensure  => present,
-    owner   => 'root',
-    group   => 'root',
-    mode    => '0644',
-    content => template("redis/${redis_conf_file}"),
-    require => Package['redis-server'],
-    notify  => Service['redis-server'],
-  }
+      ensure  => present,
+      owner   => 'root',
+      group   => 'root',
+      mode    => '0644',
+      replace => true,
+      content => template("redis/${redis_conf_file}"),
+      require => Package['redis-server'],
+    }
 
-  service { 'redis-server':
-    ensure     => running,
-    enable     => true,
-    hasstatus  => true,
-    hasrestart => true,
-    require    => [ File['/etc/redis/redis.conf'],  File['/etc/init.d/redis-server'], Package['redis-server'] ],
-  }
+    service { 'redis-server':
+      ensure     => running,
+      require    => Package['redis-server'],
+      subscribe  => File['/etc/redis/redis.conf'],
+    }
 
-}
+}
\ No newline at end of file
diff --git a/templates/init_script.erb b/templates/init_script.erb
deleted file mode 100644
index 47d48ec..0000000
--- a/templates/init_script.erb
+++ /dev/null
@@ -1,42 +0,0 @@
-#!/bin/sh
-#
-# Simple Redis init.d script conceived to work on Linux systems
-# as it does use of the /proc filesystem.
-
-REDISPORT="<%= redis_port %>"
-EXEC=<%= redis_bin_dir %>/redis-server
-CLIEXEC=<%= redis_bin_dir %>/redis-cli
-
-PIDFILE=/var/run/redis.pid
-CONF="/etc/redis/redis.conf"
-
-case "$1" in
-    start)
-        if [ -f $PIDFILE ]
-        then
-                echo "$PIDFILE exists, process is already running or crashed"
-        else
-                echo "Starting Redis server..."
-                $EXEC $CONF
-        fi
-        ;;
-    stop)
-        if [ ! -f $PIDFILE ]
-        then
-                echo "$PIDFILE does not exist, process is not running"
-        else
-                PID=$(cat $PIDFILE)
-                echo "Stopping ..."
-                $CLIEXEC -p $REDISPORT shutdown
-                while [ -x /proc/${PID} ]
-                do
-                    echo "Waiting for Redis to shutdown ..."
-                    sleep 1
-                done
-                echo "Redis stopped"
-        fi
-        ;;
-    *)
-        echo "Please use start or stop as first argument"
-        ;;
-esac
diff --git a/templates/redis.2.2.conf.erb b/templates/redis.2.2.conf.erb
index a5a4b11..bbde00a 100644
--- a/templates/redis.2.2.conf.erb
+++ b/templates/redis.2.2.conf.erb
@@ -14,7 +14,7 @@
 
 # By default Redis does not run as a daemon. Use 'yes' if you need it.
 # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
-daemonize no
+daemonize yes
 
 # When running daemonized, Redis writes a pid file in /var/run/redis.pid by
 # default. You can specify a custom pid file location here.
@@ -49,7 +49,7 @@ loglevel verbose
 # Specify the log file name. Also 'stdout' can be used to force
 # Redis to log on the standard output. Note that if you use standard
 # output for logging but daemonize, logs will be sent to /dev/null
-logfile stdout
+logfile /var/log/redis/redis-server.log
 
 # To enable logging to the system logger, just set 'syslog-enabled' to yes,
 # and optionally update the other syslog parameters to suit your needs.
@@ -147,7 +147,9 @@ slave-serve-stale-data yes
 # 150k passwords per second against a good box. This means that you should
 # use a very strong password otherwise it will be very easy to break.
 #
-# requirepass foobared
+<% if redis_password != "" %>
+requirepass <%= redis_password %>
+<% end %>
 
 # Command renaming.
 #
diff --git a/templates/redis.2.4.conf.erb b/templates/redis.2.4.conf.erb
index 1692a67..11c9190 100644
--- a/templates/redis.2.4.conf.erb
+++ b/templates/redis.2.4.conf.erb
@@ -14,7 +14,7 @@
 
 # By default Redis does not run as a daemon. Use 'yes' if you need it.
 # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
-daemonize no
+daemonize yes
 
 # When running daemonized, Redis writes a pid file in /var/run/redis.pid by
 # default. You can specify a custom pid file location here.
@@ -50,7 +50,7 @@ loglevel verbose
 # Specify the log file name. Also 'stdout' can be used to force
 # Redis to log on the standard output. Note that if you use standard
 # output for logging but daemonize, logs will be sent to /dev/null
-logfile stdout
+logfile /var/log/redis/redis-server.log
 
 # To enable logging to the system logger, just set 'syslog-enabled' to yes,
 # and optionally update the other syslog parameters to suit your needs.
@@ -178,7 +178,9 @@ slave-priority 100
 # 150k passwords per second against a good box. This means that you should
 # use a very strong password otherwise it will be very easy to break.
 #
-# requirepass foobared
+<% if redis_password != "" %>
+requirepass <%= redis_password %>
+<% end %>
 
 # Command renaming.
 #
diff --git a/templates/redis.2.6.conf.erb b/templates/redis.2.6.conf.erb
index 92f1c6f..2719e94 100644
--- a/templates/redis.2.6.conf.erb
+++ b/templates/redis.2.6.conf.erb
@@ -14,7 +14,7 @@
 
 # By default Redis does not run as a daemon. Use 'yes' if you need it.
 # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
-daemonize no
+daemonize yes
 
 # When running daemonized, Redis writes a pid file in /var/run/redis.pid by
 # default. You can specify a custom pid file location here.
@@ -61,7 +61,7 @@ tcp-keepalive 0
 # verbose (many rarely useful info, but not a mess like the debug level)
 # notice (moderately verbose, what you want in production probably)
 # warning (only very important / critical messages are logged)
-loglevel notice
+logfile /var/log/redis/redis-server.log
 
 # Specify the log file name. Also 'stdout' can be used to force
 # Redis to log on the standard output. Note that if you use standard
@@ -255,7 +255,9 @@ slave-priority 100
 # 150k passwords per second against a good box. This means that you should
 # use a very strong password otherwise it will be very easy to break.
 #
-# requirepass foobared
+<% if redis_password != "" %>
+requirepass <%= redis_password %>
+<% end %>
 
 # Command renaming.
 #