Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Database fixes for #7. #9

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Modulefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name 'kreczko-apelpublisher'
name 'heppuppet-apelpublisher'
version '0.0.2'

author 'kreczko'
author 'HEP-Puppet'
license 'Apache License, Version 2.0'
project_page 'https://github.com/HEP-Puppet'
source '[email protected]:HEP-Puppet/puppet-apelpublisher.git'
summary 'A Puppet module for the installation and setup of a Apel publisher'
description 'A Puppet module for the installation and setup of a Apel publisher'
dependency 'puppetlabs/mysql', '>=0.6.1'
dependency 'puppetlabs/mysql', '>=2.0.0'
14 changes: 7 additions & 7 deletions manifests/config.pp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
$logging_logfile = $apelpublisher::params::logging_logfile,
$logging_level = $apelpublisher::params::logging_level,
$logging_console = $apelpublisher::params::logging_console,
) inherits apelpublisher::params {
) inherits apelpublisher::params {

file { '/etc/apel/client.cfg':
owner => "root",
group => "root",
ensure => "present",
owner => 'root',
group => 'root',
ensure => 'present',
content => template("${module_name}/client.cfg.erb"),
require => [Package['apel-client'],Package['apel-ssm']],
mode => 600,
mode => '0600',
}

include apelpublisher::ssm::sender
}
20 changes: 10 additions & 10 deletions manifests/config/mysql.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,29 @@
$mysql_backup_folder = $apelpublisher::params::mysql_backup_folder,
$mysql_apel_password = $apelpublisher::params::mysql_apel_password,
) inherits apelpublisher::params {

if !$mysql_root_password {
notify { "Using empty ROOT password. Please fix.": }
notify { 'Using empty ROOT password. Please fix.': }
}

############################
# MySQL server and settings
############################
class { 'mysql::server':
config_hash => {
'root_password' => $mysql_root_password,
root_password => $mysql_root_password,
override_options => {
mysqld => { 'bind_address' => '0.0.0.0' }
}
}

class { 'mysql':
}

if $mysql_configure_backup {
class { 'mysql::backup':
backupuser => 'root',
# it always tries to create the backup user,
# using 'root' here causes a 'duplicate declaration' error
backupuser => 'mysqlbackup',
backuppassword => $mysql_root_password,
backupdir => $mysql_backup_folder,
}
}

}
18 changes: 12 additions & 6 deletions manifests/create_database.pp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
$mysql_user = $apelpublisher::params::mysql_user,
$mysql_root_password = $apelpublisher::params::mysql_root_password,
$mysql_apel_password = $apelpublisher::params::mysql_apel_password,
$list_of_apel_parser_hosts = $apelpublisher::params::list_of_apel_parser_hosts,) inherits apelpublisher::params {
$list_of_apel_parser_hosts = $apelpublisher::params::list_of_apel_parser_hosts,
) inherits apelpublisher::params {

mysql::db { $mysql_database:
user => $mysql_user,
password => $mysql_apel_password
Expand All @@ -19,13 +21,17 @@
}

exec { 'create-apel-mysql-tables':
command => '/usr/bin/mysql --defaults-file=/root/.my.cnf apelclient < /usr/share/apel/client.sql',
command => "/usr/bin/mysql --defaults-file=/root/.my.cnf ${mysql_database} < /usr/share/apel/client.sql",
require => [
Class["apelpublisher::install"],
Database[$mysql_database]],
Mysql_database[$mysql_database]
],
# needs check if already exists, otherwise will wipe the tables!
onlyif => [
'/usr/bin/test `/usr/bin/mysql --defaults-file=/root/.my.cnf -e "use apelclient; show tables;SELECT FOUND_ROWS();" 2>&1 | cut -f1 | egrep "^(0|[1-9][0-9]*)$"` -eq 0',
'/usr/bin/test -f /usr/share/apel/client.sql'],
# only run if the database exists and does not contain any tables (found rows == 0), don't run in all other cases
"/usr/bin/mysql --defaults-file=/root/.my.cnf -BNe 'show tables; SELECT FOUND_ROWS();' ${mysql_database} | /bin/grep '^0$'",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure if this is correct. Shouldn't you use "/usr/bin/test -eq 0" for the test?
What is the behaviour otherwise?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it works. grep returns false if the regex doesn't match anything (or if there's a processing error), see "exit status" in grep man page. The exec will only run if stdout of the mysql command contains a line with only a 0 in it. Mysql doesn't allow 0 as a table name and error messages are printed to stderr (and I've removed the redirect to stdout, puppet prints the stderr of onlyif commands if you run it with --debug). So, you only get a 0 in the mysql output if the database exists and there are no tables in the database.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the clarification.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On 14/03/14 17:28, kreczko wrote:

  # needs check if already exists, otherwise will wipe the tables!
  onlyif  =>  [
  •  '/usr/bin/test `/usr/bin/mysql --defaults-file=/root/.my.cnf -e "use apelclient; show tables;SELECT FOUND_ROWS();" 2>&1 | cut -f1 | egrep "^(0|[1-9][0-9]*)$"` -eq 0',
    
  •  '/usr/bin/test -f /usr/share/apel/client.sql'],
    
  •  # only run if the database exists and does not contain any tables (found rows == 0), don't run in all other cases
    
  •  "/usr/bin/mysql --defaults-file=/root/.my.cnf -BNe 'show tables; SELECT FOUND_ROWS();' ${mysql_database} | /bin/grep '^0$'",
    

Thank you for the clarification.

I've another comment on your initial test, which you should be aware
of. It doesn't matter in this case, but under other circumstances it's
the "/usr/bin/test ... -eq 0" that's dangerous. In your original test,
if the mysql command fails (for whatever reasons), ... won't produce
any output. so the test would be "/usr/bin/test -eq 0" which is invalid
because -eq is missing a parameter. This evaluates to false which
wouldn't cause any problems in this case because it's still false, but
could cause serious problems if the condition would be inverted (unless
=> "/usr/bin/test ... -ne 0") . If you compare the output of other
scripts or commands, avoid numerical comparison (-eq, -ne), use string
comparison (= or !=) instead and always test for empty strings. Safer
versions of your original test would be either.
'/usr/bin/test "..." = "0"' or
'/usr/bin/test x... = x0'

'/usr/bin/test -f /usr/share/apel/client.sql'
],
logoutput => 'on_failure',
}
}
}
9 changes: 6 additions & 3 deletions manifests/db_permissions.pp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
$host = $title,
$mysql_user = $apelpublisher::params::mysql_user,
$mysql_database = $apelpublisher::params::mysql_database,) {
database_grant { "'${mysql_user}'@'${host}'/${mysql_database}": privileges => [
'all'], }
}
mysql_grant { "'${mysql_user}@${host}'/${mysql_database}":
privileges => ['all'],
table => "${mysql_database}.*",
user => "${mysql_user}@${host}"
}
}
1 change: 0 additions & 1 deletion manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

$joiner_local_jobs = false
$joiner_enabled = true

$unloader_enabled = true
$unloader_dir_location = "/var/spool/apel/"
$unloader_send_summaries = false
Expand Down
6 changes: 4 additions & 2 deletions manifests/repositories.pp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class apelpublisher::repositories {
class apelpublisher::repositories inherits apelpublisher::params {

yumrepo { 'epel':
descr => 'Extra Packages for Enterprise Linux 6 - $basearch',
enabled => 1,
Expand Down Expand Up @@ -47,4 +48,5 @@
enabled => 1,
priority => 40,
}
}

}
15 changes: 10 additions & 5 deletions manifests/service.pp
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
class apelpublisher::service (
$runboot = false,
$runcron = true,) {
$runcron = true,
) {
if $::osfamily == 'RedHat' and $::operatingsystemversion =~ /^5\..*/ {
$pkgname = fetch-crl3
$pkgname = 'fetch-crl3'
} else {
$pkgname = fetch-crl
$pkgname = 'fetch-crl'
}

package { $pkgname :
ensure => 'present',
}

service { "${pkgname}-boot":
ensure => $runboot,
enable => $runboot,
Expand All @@ -19,6 +24,6 @@
enable => $runcron,
hasstatus => true,
hasrestart => true,
require => Class["fetchcrl::install"];
require => Package[$pkgname];
}
}
}
10 changes: 5 additions & 5 deletions manifests/ssm/sender.pp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* This sets up the SSM sender
*
*
* The erb curently is not using any option
*/
class apelpublisher::ssm::sender(
Expand All @@ -9,11 +9,11 @@
$ldap_host = $apelpublisher::params::ldap_host,
$use_ssl = $apelpublisher::params::use_ssl,
) inherits apelpublisher::params {

file { '/etc/apel/sender.cfg':
owner => "root",
group => "root",
ensure => "present",
owner => 'root',
group => 'root',
ensure => 'present',
content => template("${module_name}/sender.cfg.erb"),
require => Package['apel-ssm'],
}
Expand Down
6 changes: 3 additions & 3 deletions metadata.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "kreczko-apelpublisher",
"name": "heppuppet-apelpublisher",
"version": "0.0.2",
"summary": "A Puppet module for the installation and setup of a Apel publisher",
"author": "kreczko",
"author": "HEP-Puppet",
"description": "A Puppet module for the installation and setup of a Apel publisher",
"dependencies": [
{
Expand All @@ -15,4 +15,4 @@
"source": "[email protected]:HEP-Puppet/puppet-apelpublisher.git",
"project_page": "https://github.com/HEP-Puppet",
"license": "Apache License, Version 2.0"
}
}
4 changes: 2 additions & 2 deletions templates/sender.cfg.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

[broker]

# The SSM will query a BDII to find brokers available. These details are for the
# The SSM will query a BDII to find brokers available. These details are for the
# EGI production broker network
bdii: ldap://<%= @ldap_host %>:2170
network: <%= @msg_network %>
Expand All @@ -13,7 +13,7 @@ network: <%= @msg_network %>
#port: 6163

# broker authentication. If use_ssl is set, the certificates configured
# in the mandatory [certificates] section will be used.
# in the mandatory [certificates] section will be used.
use_ssl: <%= @use_ssl %>


Expand Down