This repository has been archived by the owner on Jan 15, 2019. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add new database create scripts for oracle,postgresql and mysql #1358
refs #1358
- Loading branch information
Showing
4 changed files
with
273 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
#!/bin/sh | ||
#-- -------------------------------------------------------- | ||
#-- create_mysqldb.sh | ||
#-- DB definition for MySQL | ||
#-- | ||
#-- Copyright (c) 2009-2011 Icinga Development Team (http://www.icinga.org) | ||
#-- | ||
#-- current version: 2011-05-03 Thomas Dressler | ||
#-- -- -------------------------------------------------------- | ||
|
||
|
||
#set -x | ||
#where to connect | ||
#edit this! | ||
DB=icinga | ||
DBUSER=icinga | ||
DBPASS=icinga | ||
DBHOST=localhost | ||
DBADMIN=root | ||
|
||
WD=`dirname $0` | ||
cd $WD | ||
WD=`pwd` | ||
cd ../mysql | ||
|
||
echo "Enter password for mysql user '$DBADMIN' or <enter> if none" | ||
read ROOTPASS | ||
if [ -s "ROOTPASS" ];then | ||
P=-p$ROOTPASS | ||
fi | ||
echo "drop existing DB $DB and user $DBUSER..." | ||
mysql -u $DBADMIN -h $DBHOST $P mysql <<EOS1 | ||
DROP DATABASE IF EXISTS $DB; | ||
DROP USER '$DBUSER'@'$DBHOST' ; | ||
flush privileges; | ||
\q | ||
EOS1 | ||
|
||
echo "create new DB $DB, user $DBUSER and objects..." | ||
mysql -u $DBADMIN -h $DBHOST $P --verbose >$WD/create_mysqldb.log mysql <<EOS2 | ||
CREATE DATABASE $DB; | ||
CREATE USER '$DBUSER'@'$DBHOST' IDENTIFIED BY '$DBPASS'; | ||
GRANT USAGE ON *.* TO '$DBUSER'@'$DBHOST' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0; | ||
GRANT SELECT , INSERT , UPDATE , DELETE ON $DB.* to '$DBUSER'@'$DBHOST'; | ||
FLUSH PRIVILEGES ; | ||
use $DB; | ||
select "START Schema Script"; | ||
select now(); | ||
source mysql.sql | ||
select "END Schema Script"; | ||
select now(); | ||
\q | ||
EOS2 | ||
|
||
if [ $? == 0 ]; then | ||
echo "Check icinga schema version with DB User $DBUSER..." | ||
mysql $DB -u $DBUSER -p$DBPASS -h $DBHOST -s <<EOS3 | ||
select "DB-Version",version from icinga_dbversion where name='idoutils'; | ||
\q | ||
EOS3 | ||
|
||
if [ $? == 0 ]; then | ||
echo "Database ready" | ||
RET=0 | ||
else | ||
echo "Database creation failed" | ||
RET=2 | ||
fi | ||
else | ||
echo "Error while creating Database/User" | ||
RET=1 | ||
fi | ||
echo "Logfiles:" | ||
cd $WD | ||
ls -l *mysql*.log | ||
exit $RET |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
#!/bin/sh | ||
#-- -------------------------------------------------------- | ||
#-- create_oracledb.sh | ||
#-- DB definition for Oracle | ||
#-- | ||
#-- Copyright (c) 2009-2011 Icinga Development Team (http://www.icinga.org) | ||
#-- | ||
#-- current version: 2011-05-03 Thomas Dressler | ||
#-- -- -------------------------------------------------------- | ||
|
||
#where database to connect | ||
#edit this! | ||
DB=XE | ||
DBUSER=icinga | ||
DBPASS=icinga | ||
|
||
#set -x | ||
SP=`which sqlplus` | ||
if [ ! -x "$SP" ]; then | ||
echo "cannot find oracle sqlplus executable, terminate.." | ||
echo "make sure your oracle environment is set properly before starting this!" | ||
exit 4 | ||
fi | ||
WD=`dirname $0` | ||
cd $WD | ||
WD=`pwd` | ||
cd ../oracle | ||
|
||
|
||
if [ ! -r icinga_defines.sql ]; then | ||
echo create default parameter file icinga_defines.sql | ||
echo " | ||
/* | ||
filesystems to use for distributing index and data. In low frequency environments | ||
this can be the same. trailing slash is mandantory | ||
EDIT THIS! | ||
*/ | ||
DEFINE DATAFS=./ | ||
DEFINE IDXFS=./ | ||
DEFINE LOBFS=./ | ||
/* | ||
icinga tablespaces and user must fit definitions in create_icinga_objects_oracle.sql | ||
EDIT THIS! | ||
*/ | ||
DEFINE DATATBS=ICINGA_DATA1 | ||
DEFINE IDXTBS=ICINGA_IDX1 | ||
DEFINE LOBTBS=ICINGA_LOB1 | ||
DEFINE ICINGA_USER=$DBUSER | ||
DEFINE ICINGA_PASSWORD=$DBPASS | ||
" >icinga_defines.sql | ||
|
||
fi | ||
|
||
#run sqlplus as sys | ||
echo "Enter password for oracle user 'SYS' on $DB to drop and create new Tablespaces and user $DBUSER" | ||
read SYSPASS | ||
$SP /nolog <<EOS1 | ||
--exit if connect errornous | ||
whenever sqlerror exit failure | ||
connect sys/${SYSPASS}@${DB} as sysdba; | ||
-- ----------------------------------------- | ||
-- run user and tablespace creation | ||
-- CAUTION: THIS WILL DROP EXISTING USER AND TABLESPACES WITH SAME NAME | ||
-- ----------------------------------------- | ||
@create_oracle_sys.sql | ||
EOS1 | ||
RET=$? | ||
|
||
if [ $RET == 0 ]; then | ||
#create icinga schema objects using newly created user | ||
$SP /nolog <<EOS2 | ||
--exit if connect errornous | ||
whenever sqlerror exit failure | ||
connect ${DBUSER}/${DBPASS}@${DB} | ||
-- ----------------------------------------- | ||
-- create icinga objects | ||
-- CAUTION: THIS WILL DROP EXISTING USER AND TABLESPACE WITH SAME NAME | ||
-- ----------------------------------------- | ||
@oracle.sql | ||
EOS2 | ||
RET=$? | ||
#check if dbversion entered(last insert) | ||
if [ $RET == 0 ]; then | ||
echo "Connecting now as $DBUSER on $DB and create icinga Schema objects" | ||
$SP /nolog <<EOS3 | ||
connect ${DBUSER}/${DBPASS}@${DB} | ||
Alter session set nls_date_format='YYYY-MM-DD HH24:MI'; | ||
select 'DB-Version'||version from dbversion where name='idoutils'; | ||
select 'END' from dual; | ||
select sysdate from dual; | ||
exit; | ||
EOS3 | ||
|
||
if [ $? == 0 ]; then | ||
echo "Database ready" | ||
RET=0 | ||
else | ||
echo "Schema creation check failed" | ||
RET=3 | ||
fi | ||
|
||
else | ||
echo "Schema creation failed" | ||
RET=2 | ||
fi | ||
else | ||
echo "Error while running Oracle SYS part" | ||
echo "Terminated" | ||
RET=1 | ||
fi | ||
|
||
mv -f *oracle*.log $WD/. | ||
cd $WD | ||
echo "Logfiles:" | ||
ls -l *oracle*.log | ||
exit $RET |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
#!/bin/sh | ||
#-- -------------------------------------------------------- | ||
#-- create_pgsqldb.sh | ||
#-- DB definition for Postgresql | ||
#-- | ||
#-- Copyright (c) 2009-2011 Icinga Development Team (http://www.icinga.org) | ||
#-- | ||
#-- current version: 2011-05-03 Thomas Dressler | ||
#-- -- -------------------------------------------------------- | ||
|
||
#set -x | ||
WD=`dirname $0` | ||
cd $WD | ||
WD=`pwd` | ||
#prepare scripts in /tmp for running with user postgres | ||
cp -r ../pgsql /tmp/. | ||
chmod a+r /tmp/pgsql/* | ||
chmod 777 /tmp/pgsql | ||
( | ||
cat <<'PGSCRIPT' | ||
#!/bin/sh | ||
#set -x | ||
cd `dirname $0` | ||
#where to connect | ||
#edit this! | ||
DB=icinga | ||
DBUSER=icinga | ||
DBPASS=icinga | ||
echo "Create icinga DB and User, Errors regarding non existing objects kann be ignored" | ||
psql postgres >create_pgsqldb.log <<EOS1 | ||
-- \set ECHO all | ||
DROP DATABASE $DB; | ||
DROP USER $DBUSER; | ||
CREATE DATABASE $DB; | ||
CREATE USER $DBUSER WITH PASSWORD '$DBPASS'; | ||
\q | ||
EOS1 | ||
if [ $? == 0 ]; then | ||
createlang plpgsql icinga; | ||
echo "Create icinga objects..." | ||
PGPASSWORD=$DBPASS | ||
psql $DB -U $DBUSER >create_icinga_objects_pgsqldb.log 2>&1 <<EOS2 | ||
\set ECHO all | ||
\set ON_ERROR_STOP 1 | ||
\echo "START" | ||
select now(); | ||
\i pgsql.sql | ||
select version as DBVersion from icinga_dbversion where name='idoutils'; | ||
\echo "END"; | ||
select now(); | ||
\q | ||
EOS2 | ||
if [ $? == 0 ]; then | ||
echo "Database ready" | ||
else | ||
echo "Database creation failed" | ||
exit 2 | ||
fi | ||
else | ||
echo "Error while creating Database/User" | ||
echo "Terminated" | ||
exit 1 | ||
fi | ||
PGSCRIPT | ||
)> /tmp/pgsql/pgsqldb.sh | ||
chmod a+rx /tmp/pgsql/pgsqldb.sh | ||
|
||
#run it | ||
#set -x | ||
su - postgres -c /tmp/pgsql/pgsqldb.sh | ||
RET=$? | ||
mv -f /tmp/pgsql/*.log . | ||
echo "Dont forget to modify pg_hba.conf to trust icinga!(see icinga documentation)" | ||
rm -rf /tmp/pgsql | ||
echo "Logfiles:" | ||
ls -l *pgsql*.log | ||
exit $RET |