Search code examples
mysqlpuppettravis-ci

Why puppet is removing my database in Travis CI on MySQL restart?


I've the following puppet recipe to apply the new configuration and restart the MySQL server when running my build on Travis CI:

class { '::mysql::server':
  root_password    => 'root',
  override_options => {
    'mysqld' => {
      'max_connections' => '512',
      'max_allowed_packet' => '12M'
    }
  },
  restart => true
}

But after I'm applying this recipe, my MySQL database is gone.

The log is:

$ echo "SHOW DATABASES" | mysql -uroot -proot 
Database
information_schema
mysql
performance_schema
travis_ads_test
$ sudo puppet apply puppet/ads.dev.configure-site.pp
Warning: Setting templatedir is deprecated. See http://links.puppetlabs.com/env-settings-deprecations
   (at /usr/lib/ruby/vendor_ruby/puppet/settings.rb:1117:in `issue_deprecation_warning')
Warning: Config file /etc/puppet/hiera.yaml not found, using Hiera defaults
Notice: Compiled catalog for ads.localdomain in environment production in 2.29 seconds
Notice: /Stage[main]/Mysql::Server::Config/File[/etc/mysql/my.cnf]/content: content changed '{md5}b199076b6b1a40b6cd6f8f0c464977e9' to '{md5}0d8e003c4dfe5cfd85de1d06cc7c4eb7'
Notice: /Stage[main]/Mysql::Server::Service/Service[mysqld]: Triggered 'refresh' from 1 events
Notice: /Stage[main]/Mysql::Server::Service/File[/var/log/mysql/error.log]/group: group changed 'adm' to 'mysql'
Notice: /Stage[main]/Mysql::Server::Root_password/Mysql_user[root@localhost]/password_hash: defined 'password_hash' as '*81F5E21E35407D884A6CD4A731AEBFB6AF209E1B'
Notice: /Stage[main]/Mysql::Server::Root_password/File[/root/.my.cnf]/ensure: defined content as '{md5}f2ee51638cc14fb3396202254d9f14a0'
Notice: /Stage[main]/Main/Apache::Vhost[ads.localhost]/File[/var/www/ads]/owner: owner changed 'travis' to 'root'
Notice: /Stage[main]/Main/Apache::Vhost[ads.localhost]/File[/var/www/ads]/group: group changed 'travis' to 'root'
Notice: /Stage[main]/Main/Apache::Vhost[ads.localhost]/File[25-ads.localhost.conf]/ensure: created
Notice: /Stage[main]/Main/Apache::Vhost[ads.localhost]/File[25-ads.localhost.conf symlink]/ensure: created
Notice: /Stage[main]/Apache::Service/Service[httpd]: Triggered 'refresh' from 2 events
Notice: Finished catalog run in 7.08 seconds
The command "sudo puppet apply puppet/ads.dev.configure-site.pp" exited with 0.
$ echo "SHOW DATABASES" | mysql -uroot -proot && echo "SHOW TABLES" | drush sql-cli
Database
information_schema
mysql
performance_schema
Calling proc_open(mysql --database=travis_ads_test --host=localhost --port=3306 --user=root --password=root);
ERROR 1049 (42000): Unknown database 'travis_ads_test'

And my database travis_ads_test is gone. Any reason why?

I am doing anything wrong with MySQL restart via puppet, or it's some kind of Travis CI feature?


Solution

  • It seems that restart is not needed, as puppetlabs-mysql module will manage all the restarts required for the configuration changes, as you can see from the following messages:

    Config/File[/etc/mysql/my.cnf]/content: content changed
    Service/Service[mysqld]: Triggered 'refresh' from 1 events
    

    If you really need the restart, then check: Restarting mysql utilizing the puppetlabs/mysql module?

    So the solution is to remove restart => true, but why the database is missing, I'm not sure.

    Probably your database it was not dropped, but by changing the credentials, you changed the privileges for that user with the access on a database. If you had root password before the change, old_root_password is required, if you wish to change the root password via Puppet.

    Check the documentation for further information: