diff options
author | Silvio Rhatto <rhatto@riseup.net> | 2010-01-19 14:29:32 -0200 |
---|---|---|
committer | Silvio Rhatto <rhatto@riseup.net> | 2010-01-19 14:29:32 -0200 |
commit | b70a99a624f177c2ce0aa28dd826ff4c3e1816d0 (patch) | |
tree | 652dcab7a8f36b1bff17e8ab51fb61bd7133bfac | |
parent | 855c3ab1df06611cb17fc9728d484233f69c5b1e (diff) | |
download | puppet-mysql-b70a99a624f177c2ce0aa28dd826ff4c3e1816d0.tar.gz puppet-mysql-b70a99a624f177c2ce0aa28dd826ff4c3e1816d0.tar.bz2 |
Using just change_mysql_rootpw
-rw-r--r-- | files/setmysqlpass.sh | 18 | ||||
-rw-r--r-- | manifests/init.pp | 46 | ||||
-rw-r--r-- | templates/setmysqlpass.sh.erb | 36 |
3 files changed, 56 insertions, 44 deletions
diff --git a/files/setmysqlpass.sh b/files/setmysqlpass.sh deleted file mode 100644 index 586775e..0000000 --- a/files/setmysqlpass.sh +++ /dev/null @@ -1,18 +0,0 @@ -#!/bin/bash -# -# Set MySQL password. -# - -CONF="/root/.my.cnf" - -# Check config file -if [ ! -e "$CONF" ]; then - echo "File not found: $CONF" - exit 1 -fi - -# Get password from configuration -passwd="`grep ^'password='` $CONF | cut -d '=' -f 2" - -# Set the password -echo "USE mysql; UPDATE user SET Password=PASSWORD('$passwd') WHERE User='root' AND Host='localhost';" | /usr/bin/mysql -u root diff --git a/manifests/init.pp b/manifests/init.pp index 8143a80..35bd0f5 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -4,46 +4,40 @@ class mysql { package { "mysql-client": - ensure => installed, + ensure => installed, } } class mysql::server inherits mysql { package { "mysql-server": - ensure => installed, + ensure => installed, } + service { "mysql": - ensure => running, - enable => true, - hasrestart => true, - hasstatus => true, - require => Package["mysql-server"], + ensure => running, + enable => true, + hasrestart => true, + hasstatus => true, + require => Package["mysql-server"], } case $mysql_rootpw { - '': { fail("You need to define a mysql root password! Please set \$mysql_rootpw in your site.pp or host config") } + '': { fail("You need to define a mysql root password! Please set \$mysql_rootpw in your site.pp or host config") } } - file{ '/usr/local/sbin/setmysqlpass.sh': - source => "puppet://$server/modules/mysql/setmysqlpass.sh", - require => Package[mysql-server], - owner => root, - group => root, - mode => 0500, + file { '/usr/local/sbin/setmysqlpass.sh': + content => template('mysqk/setmysqlpass.sh.erb'), + require => Package[mysql-server], + owner => root, + group => root, + mode => 0500, } - exec{'set_mysql_rootpw': - command => "/usr/local/sbin/setmysqlpass.sh", - unless => "mysqladmin -uroot status > /dev/null", - require => [ File['/usr/local/sbin/setmysqlpass.sh'], Package[mysql-server] ], - user => root, - } - - exec{'change_mysql_rootpw': - command => "/usr/local/sbin/setmysqlpass.sh", - require => [ File['/usr/local/sbin/setmysqlpass.sh'], Package[mysql-server] ], - refreshonly => true, - user => root, + exec { 'change_mysql_rootpw': + command => "/usr/local/sbin/setmysqlpass.sh", + require => [ File['/usr/local/sbin/setmysqlpass.sh'], Package[mysql-server] ], + refreshonly => true, + user => root, } mysql::cnf { "root": diff --git a/templates/setmysqlpass.sh.erb b/templates/setmysqlpass.sh.erb new file mode 100644 index 0000000..902336a --- /dev/null +++ b/templates/setmysqlpass.sh.erb @@ -0,0 +1,36 @@ +#!/bin/bash +# +# Set MySQL password. +# + +# Config +SERVICE="/etc/init.d/mysql" +PASSWORD="<%= mysql_rootpw %>" +DATADIR="/var/lib/mysql/data" +LOGBIN="/var/lib/mysql/mysql-bin" +USER="mysql" +GROUP="mysql" +DEFAULTS="/etc/mysql/debian.cnf" + +# Stop service +#$SERVICE stop + +# Start without grant tables +# This seems unsafe as opens a race condition. +#/usr/libexec/mysqld --skip-grant-tables --user=root --datadir=$DATADIR log-bin=$LOGBIN & + +# Wait +#sleep 5 + +# Change root password +echo "USE mysql; UPDATE user SET Password=PASSWORD('$PASSWORD') WHERE User='root' AND Host='localhost';" | \ + /usr/bin/mysql --defaults-file=$DEFAULTS + +# Kill the daemon +#killall mysqld + +# Chown to be on the safe side +#chown $USER.$GROUP $LOGBIN* + +# Start service +#$SERVICE start |