Property changes on: trunk
___________________________________________________________________
Modified: svn:mergeinfo
- /branches/DEV-capside/release-3.9.0:6365-6370
/branches/DEV-extra-notification-data:6734-6746
/branches/DEV-odw-calculations:9016-9160
/branches/DEV-restapi-monitoringservers:9778
/branches/DEV-snmp-multi:7324-7376
/branches/US187:9403-9479
/branches/US198b:8875-8994
/branches/US310:9851-9873
/branches/US539:12178-12182
/branches/enterprise/BRAN-3.14:6874,6882,6956
/branches/enterprise/DEV-professional:6494-8475,8477-8478,8486,8490,8492,8494,8499-8500,8515,8518-8519,8524,8527-8529,8531-8532,8536,8538,8540-8544,8547-8552,8554,8557,8600-8601,8637,8749,8772,8897,8917,8944-8945,8947,8950-8952,8967,8969,8979,8982,8987,8998,9006,9008,9011,9013,9026,9033-9036,9038,9040,9042,9044,9048,9050-9053,9062,9064-9065,9069,9078,9081,9088,9096,9099-9101,9103,9105,9115,9118,9347,9353-9354,9411,9432,9445,9486,9538-9550,9569-9571,9620,9635,9637-9638,9645-9647,9693,9699,9721,9814,9825,9857,9879,9881,9939,10002,10029,10038-10041,10070,10086,10093,10345,10347,10388,10407,10481,10549,10560-10562,10565,10568,10571,10577,10932,11025,11035,11360-11612,11798-11799,12189,12322,12355,12401-12406
/branches/nagvis-iframe:9764-9786
/branches/opsview2runtime:10960-11258
/branches/opsview2runtime_xs:11279-11303
/branches/us168:8759,8762-8763,8766-8768,8770,8774-8777,8794,8798-8799,8801-8803,8821-8822,8834,8837-8838,8932,8937,8947,8969,8977,8981,9004,9007,9009-9010,9012,9024,9049
/commercial/branches/BRAN-4.2:10944,11017
/commercial/branches/US306-slaves:9804-9823
/commercial/branches/US307-network-map:9685-9837
+ /branches/DEV-capside/release-3.9.0:6365-6370
/branches/DEV-extra-notification-data:6734-6746
/branches/DEV-odw-calculations:9016-9160
/branches/DEV-restapi-monitoringservers:9778
/branches/DEV-snmp-multi:7324-7376
/branches/US187:9403-9479
/branches/US198b:8875-8994
/branches/US310:9851-9873
/branches/US539:12178-12182
/branches/enterprise/BRAN-3.14:6874,6882,6956
/branches/enterprise/DEV-professional:6494-8475,8477-8478,8486,8490,8492,8494,8499-8500,8515,8518-8519,8524,8527-8529,8531-8532,8536,8538,8540-8544,8547-8552,8554,8557,8600-8601,8637,8749,8772,8897,8917,8944-8945,8947,8950-8952,8967,8969,8979,8982,8987,8998,9006,9008,9011,9013,9026,9033-9036,9038,9040,9042,9044,9048,9050-9053,9062,9064-9065,9069,9078,9081,9088,9096,9099-9101,9103,9105,9115,9118,9347,9353-9354,9411,9432,9445,9486,9538-9550,9569-9571,9620,9635,9637-9638,9645-9647,9693,9699,9721,9814,9825,9857,9879,9881,9939,10002,10029,10038-10041,10070,10086,10093,10345,10347,10388,10407,10481,10549,10560-10562,10565,10568,10571,10577,10932,11025,11035,11360-11612,11798-11799,12189,12322,12355,12401-12406,12428
/branches/nagvis-iframe:9764-9786
/branches/opsview2runtime:10960-11258
/branches/opsview2runtime_xs:11279-11303
/branches/us168:8759,8762-8763,8766-8768,8770,8774-8777,8794,8798-8799,8801-8803,8821-8822,8834,8837-8838,8932,8937,8947,8969,8977,8981,9004,9007,9009-9010,9012,9024,9049
/commercial/branches/BRAN-4.2:10944,11017
/commercial/branches/BRAN-4.3:12423-12426
/commercial/branches/US306-slaves:9804-9823
/commercial/branches/US307-network-map:9685-9837
Modified: trunk/opsview-core/debian/postinst
===================================================================
--- trunk/opsview-core/debian/postinst 2013-06-04 12:44:11 UTC (rev 12429)
+++ trunk/opsview-core/debian/postinst 2013-06-04 12:45:50 UTC (rev 12430)
@@ -4,7 +4,7 @@
# see: dh_installdeb(1)
#
# AUTHORS:
-# Copyright (C) 2003-2013 Opsview Limited. All rights reserved
+# Copyright (C) 2003-2013 Opsview Limited. All rights reserved
#
# This file is part of Opsview
#
@@ -40,11 +40,18 @@
# the debian-policy package
#
-# Expects $1=db
+die() {
+ echo $1
+ exit 1
+}
+
+# This function gets the root password for mysql
+# This should not be DB specific, but would rather not change this just yet
db_getroot() {
proceed=0
db_subst opsview-core/db_rootpass db $1
+ db_subst opsview-core/db_rootpass dbhost $2
while [ ${proceed} -eq 0 ]; do
# Only prompts on db_go
# This works quite nicely because $RET will be empty, which is default mysql root
@@ -52,12 +59,14 @@
db_get opsview-core/db_rootpass
mysql_root_pw=$RET
+ set +e
# Try to connect
echo exit | mysql -u root --password="${mysql_root_pw}" -h "$2" > /dev/null 2>&1
retval=$?
+ set -e
if [ ${retval} -ne 0 ]; then
- echo "Failed to connect to database - requesting root password" >&2
+ echo "Failed to connect to mysql - requesting root password" >&2
db_reset opsview-core/db_rootpass
db_input critical opsview-core/db_rootpass
db_go || return 1;
@@ -69,65 +78,40 @@
return ${retval};
}
-# Need to iterate through each database, because new dbs are created
-install_or_upgrade() {
+install_tasks() {
- # Will be set to true if any database exists - close enough to truth
- opsview_upgrade=0
+ # Get mysql root password
+ db_getroot opsview localhost
- eval `/usr/local/nagios/bin/opsview.sh`
+ # Setup all the permissions for mysql
+ if ! su - nagios -c "/usr/local/nagios/bin/db_mysql -u root -p '${mysql_root_pw}'" > /dev/null ; then
+ die "Problem with db_mysql, exiting install"
+ fi
- # Group dbs according to likelyhood of being on same server
- for db in opsview runtime; do
-
- # Check if db exists. Must do before db_mysql because this creates it
- su - nagios -c "/usr/local/nagios/bin/db_$db db_exists" 2>/dev/null
- db_exists=$?
-
- if [ $db_exists -eq 0 ] ; then
- opsview_upgrade=1
- echo "Database $db detected - upgrading ..."
- su - nagios -c "/usr/local/nagios/installer/upgradedb_$db.pl" || exit 1
- else
- # Don't need to specify host in db_mysql, because uses opsview.conf automatically
- db_getroot $db "localhost" || exit 1
- su - nagios -c "/usr/local/nagios/bin/db_mysql -u root -p '${mysql_root_pw}' $db" > /dev/null
- if [ $? -ne 0 ] ; then
- echo "Problem with db_mysql, exiting install"
- return 1
- fi
- echo "Creating database $db"
- su - nagios -c "/usr/local/nagios/bin/db_$db db_install" || exit 1
- fi
+ for db in opsview runtime dashboard odw; do
+ echo "Creating database $db"
+ su - nagios -c "/usr/local/nagios/bin/db_$db db_install" || die "Cannot create db $db"
done
- # Remove passwords from database
+ # Remove passwords from package management
db_clear
db_unregister opsview-core/db_rootpass
+}
- if [ $opsview_upgrade -eq 1 ]; then
- su - nagios -c '/usr/local/nagios/bin/install_all_opspacks --dir /usr/local/nagios/import/opspacks'
- su - nagios -c '/usr/local/nagios/bin/populate_db.pl'
- fi
+upgrade_tasks() {
+ su - nagios -c '/usr/local/nagios/installer/upgradedb.pl' || die "Cannot upgradedb"
- # NOSTART so Debian will startup daemon itself
- if [ -f /tmp/opsview4_upgrade_config_generation.lock ] ; then
- echo "Upgrading to Opsview 4 - you must activate Opsview now before reloading"
- else
- echo "Generating configs"
- su - nagios -c 'OPSVIEW_NOSTART=true /usr/local/nagios/bin/rc.opsview gen_config'
- fi
+ echo "Sending new files to slaves..."
+ # send2slaves to update slaves with new opsview code
+ su - nagios -c '/usr/local/nagios/bin/send2slaves'
+
+ echo "Updating plugin help information - there maybe warnings here but they can be ignored"
+ su - nagios -c '/usr/local/nagios/bin/populate_db.pl'
}
set_opsview_db_passwords() {
- db_input critical opsview-core/db_opspass
- db_go
- db_get opsview-core/db_opspass
- mysql_opsview_pw=$RET
- db_unregister opsview-core/db_opspass
-
- su - nagios -c "/usr/local/nagios/installer/create_initial_opsview_conf ${mysql_opsview_pw}"
- return $?
+ mysql_opsview_pw=`perl -I/usr/local/nagios/perl/lib -MData::UUID -i -e '$ug = new Data::UUID; print $ug->to_string( $ug->create )'`
+ su - nagios -c "/usr/local/nagios/installer/create_initial_opsview_conf ${mysql_opsview_pw}" || die "Cannot set initial opsview conf file"
}
set_profile() {
@@ -136,20 +120,21 @@
}
opsview_postinst() {
+ # NOSTART so Debian will startup daemon itself
+ if [ -f /tmp/opsview4_upgrade_config_generation.lock ] ; then
+ echo "Upgrading to Opsview 4 - you must activate Opsview now before reloading"
+ else
+ echo "Generating configs"
+ su - nagios -c 'OPSVIEW_NOSTART=true /usr/local/nagios/bin/rc.opsview gen_config' || die "Error generating configuration"
+ fi
+
# If it exists, run the Opsview post install script
+ echo "Running common postinstall tasks"
test -f /usr/local/nagios/installer/postinstall_root && /usr/local/nagios/installer/postinstall_root 3>/dev/null
test -f /usr/local/nagios/installer/postinstall && su - nagios -c '/usr/local/nagios/installer/postinstall' 3>/dev/null
return 0
}
-move_files() {
- dir=$1
- for copy in $(/bin/ls $dir/*.copy); do
- icon=`echo $copy | sed -e 's/\.copy//'`
- mv $copy $icon || exit 1
- done
-}
-
case "$1" in
install)
;;
@@ -157,15 +142,35 @@
upgrade)
;;
+ # We now create databases altogether. It used to be checked individually, but
+ # that is different from all the instructions we have for other platforms
configure)
- if [ "x$2" = "x" ] ; then
- echo "New install - prompting for new database passwords"
- set_opsview_db_passwords || exit 1
- fi
- set_profile || exit 1
- install_or_upgrade || exit 1
- opsview_postinst || exit 1
- rm -f /usr/local/nagios/var/upgrade.lock
+
+ set_profile || die "Cannot set_profile"
+
+ # Flag to determine if opsview already exists
+ # This is required because otherwise deinstallation of a package and then
+ # reinstallation will wipe all the current data, which is dangerous
+ opsview_upgrade=1
+ echo "Checking if Opsview database already exists"
+
+ if su - nagios -c "/usr/local/nagios/bin/db_opsview db_exists" 2>/dev/null ; then
+ echo "Opsview DB already exists"
+ else
+ echo "No Opsview DB found"
+ opsview_upgrade=0
+ fi
+
+ if [ $opsview_upgrade -eq 0 ] ; then
+ echo "New install - creating databases with random passwords"
+ set_opsview_db_passwords
+ install_tasks
+ else
+ echo "Upgrading all databases"
+ upgrade_tasks
+ fi
+ opsview_postinst
+ rm -f /usr/local/nagios/var/upgrade.lock
;;
abort-upgrade|abort-remove|abort-deconfigure)