forked from ungleich-public/cdist
new type 'mysql_database'
installs a database on an existing mysql_server remotely
This commit is contained in:
parent
23eba4c5e1
commit
cfaee39e70
3 changed files with 100 additions and 0 deletions
48
conf/type/__mysql_database/gencode-remote
Executable file
48
conf/type/__mysql_database/gencode-remote
Executable file
|
@ -0,0 +1,48 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# 2012 Benedikt Koeppel (code@benediktkoeppel.ch)
|
||||
#
|
||||
# This file is part of cdist.
|
||||
#
|
||||
# cdist is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# cdist is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
#
|
||||
|
||||
# if --database was specified
|
||||
if [ -f "$__object/parameter/database" ]; then
|
||||
database="$(cat "$__object/parameter/database")"
|
||||
else # otherwise use the object id as database name
|
||||
database="$__object_id"
|
||||
fi
|
||||
|
||||
mysql -u root -p <<-EOF
|
||||
CREATE DATABASE IF NOT EXISTS $database
|
||||
EOF
|
||||
|
||||
# if --user was specified
|
||||
if [ -f "$__object/parameter/user" ]; then
|
||||
user="$(cat "$__object/parameter/user")"
|
||||
|
||||
# if --password was specified
|
||||
if [ -f "$__object/parameter/password" ]; then
|
||||
password="$(cat "$__object/parameter/password")"
|
||||
mysql -u root -p <<-EOF
|
||||
GRANT ALL PRIVILEGES ON $database.* to '$user'@'localhost' IDENTIFIED BY '$password';
|
||||
EOF
|
||||
else
|
||||
mysql -u root -p <<-EOF
|
||||
GRANT ALL PRIVILEGES ON $database.* to '$user'@'localhost';
|
||||
EOF
|
||||
fi
|
||||
fi
|
49
conf/type/__mysql_database/man.text
Normal file
49
conf/type/__mysql_database/man.text
Normal file
|
@ -0,0 +1,49 @@
|
|||
cdist-type__mysql_database(7)
|
||||
=============================
|
||||
Benedikt Koeppel <code@benediktkoeppel.ch>
|
||||
|
||||
|
||||
NAME
|
||||
----
|
||||
cdist-type__mysql_database - Manage a MySQL database
|
||||
|
||||
|
||||
DESCRIPTION
|
||||
-----------
|
||||
This cdist type allows you to install a MySQL database.
|
||||
|
||||
|
||||
REQUIRED PARAMETERS
|
||||
-------------------
|
||||
None.
|
||||
|
||||
OPTIONAL PARAMETERS
|
||||
-------------------
|
||||
database::
|
||||
The name of the database to install
|
||||
defaults to the object id
|
||||
|
||||
user::
|
||||
A user that should have access to the database
|
||||
|
||||
password::
|
||||
The password for the user who manages the database
|
||||
|
||||
|
||||
EXAMPLES
|
||||
--------
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
__mysql_database "cdist" --database "cdist" --user "myuser" --password "mypwd"
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
SEE ALSO
|
||||
--------
|
||||
- cdist-type(7)
|
||||
|
||||
|
||||
COPYING
|
||||
-------
|
||||
Copyright \(C) 2012 Benedikt Koeppel. Free use of this software is
|
||||
granted under the terms of the GNU General Public License version 3 (GPLv3).
|
3
conf/type/__mysql_database/parameter/optional
Normal file
3
conf/type/__mysql_database/parameter/optional
Normal file
|
@ -0,0 +1,3 @@
|
|||
database
|
||||
user
|
||||
password
|
Loading…
Reference in a new issue