Home | History | Annotate | Download | only in sapdb
      1 /*
      2  * CDDL HEADER START
      3  *
      4  * The contents of this file are subject to the terms of the
      5  * Common Development and Distribution License (the License).
      6  * You may not use this file except in compliance with the License.
      7  *
      8  * You can obtain a copy of the license at usr/src/CDDL.txt
      9  * or http://www.opensolaris.org/os/licensing.
     10  * See the License for the specific language governing permissions
     11  * and limitations under the License.
     12  *
     13  * When distributing Covered Code, include this CDDL HEADER in each
     14  * file and include the License file at usr/src/CDDL.txt.
     15  * If applicable, add the following below this CDDL HEADER, with the
     16  * fields enclosed by brackets [] replaced with your own identifying
     17  * information: Portions Copyright [yyyy] [name of copyright owner]
     18  *
     19  * CDDL HEADER END
     20  */
     21 
     22 /*
     23  * Copyright 2003 Sun Microsystems, Inc.  All rights reserved.
     24  * Use is subject to license terms.
     25  *
     26  * sapdb_validate.c - validate method for SAPDB.
     27  */
     28 
     29 #pragma ident	"@(#)sapdb_validate.c	1.8	07/06/06 SMI"
     30 
     31 #include <ds_common.h>
     32 #include "sapdb.h"
     33 
     34 /* Use 50% of the validate timeout to check db w/ logical host */
     35 #define	TIMEOUT_PCT	50
     36 
     37 /*
     38  * Check to make sure that the properties have been set properly.
     39  */
     40 
     41 int
     42 main(int argc, char *argv[])
     43 {
     44 	scds_handle_t   scds_handle;
     45 	int		rc;
     46 	int		timeout = 0;
     47 	sapdb_extprops_t	sapdbxpropsp;
     48 	char			*db_state_cmd = NULL;
     49 	boolean_t		hsp_online_not_local;
     50 
     51 	/* I18N stuff */
     52 	(void) setlocale(LC_ALL, "");
     53 	(void) textdomain(TEXT_DOMAIN);
     54 	(void) bindtextdomain(TEXT_DOMAIN, MESSAGE_DIR);
     55 
     56 	/* Process arguments passed by RGM and initialize syslog */
     57 	if ((rc = scds_initialize(&scds_handle, argc, argv))
     58 		!= SCHA_ERR_NOERR) {
     59 		scds_syslog(LOG_ERR, "Failed to retrieve the resource "
     60 			"handle: %s", scds_error_string(rc));
     61 		(void) fprintf(stderr, gettext("Failed to retrieve the "
     62 			"resource handle: %s\n"), scds_error_string(rc));
     63 		return (1);
     64 	}
     65 
     66 	if (get_sapdb_extension(scds_handle, &sapdbxpropsp, B_TRUE) != 0) {
     67 		scds_close(&scds_handle);
     68 		return (1);
     69 	}
     70 
     71 	rc = svc_validate(scds_handle, &sapdbxpropsp, B_TRUE,
     72 		&hsp_online_not_local);
     73 
     74 	if (rc != SCHA_ERR_NOERR) {
     75 		scds_syslog(LOG_ERR, "Failed to validate configuration.");
     76 		(void) fprintf(stderr, gettext("Failed to validate "
     77 			"configuration.\n"));
     78 		goto finished;
     79 	}
     80 
     81 	if (hsp_online_not_local == B_TRUE) {
     82 		/* hsp is online not local, skip the rest xserver checks */
     83 		scds_syslog_debug(SCDS_DBG_HIGH, "Won't check xserver "
     84 			"because hsp online not local.");
     85 		rc = 0;
     86 		goto finished;
     87 	}
     88 
     89 	/*
     90 	 * check xserver running or not locally. Timeout is retrieved
     91 	 * in db_state_local() and pass back since db_state() needs the
     92 	 * timeout too.
     93 	 */
     94 	rc = db_state_local(scds_handle, sapdbxpropsp.ext_indep_prog_path,
     95 		SCHA_VALIDATE_TIMEOUT, &timeout, B_TRUE);
     96 
     97 	if (rc != 0) { /* xserver is not running, exit 0 */
     98 		(void) fprintf(stderr, gettext("\nSAP xserver is not running, "
     99 			"User_Key and related information were not verified."));
    100 		rc = 0;
    101 		goto finished;
    102 	}
    103 
    104 	/* xserver is running, do further checks w/ logical host */
    105 	db_state_cmd = ds_string_format(
    106 		"%s/%s %s/bin/dbmcli %s %s %s>/dev/null",
    107 		scds_get_rt_rt_basedir(scds_handle),
    108 		CHECK_DB_STATE, sapdbxpropsp.ext_indep_prog_path,
    109 		sapdbxpropsp.ext_user_key,
    110 		sapdbxpropsp.ext_pid_dir,
    111 		sapdbxpropsp.ext_db_name);
    112 	if (db_state_cmd == NULL) {
    113 		ds_internal_error("Failed to create command string to "
    114 			"check SAP DB state");
    115 		rc = 1;
    116 		goto finished;
    117 	}
    118 
    119 	/*
    120 	 * Need to run the check under 50% of validate timeout.
    121 	 * otherwise, RGM will time it out and we won't know the reason.
    122 	 * 1 minute (50% of 120 seconds) should be sufficient to get the
    123 	 * status of sapdb using logical host. If the logical host is
    124 	 * running, but this check times out, that means the system is
    125 	 * really slow, then increasing the validate timeout will help to
    126 	 * solve the timeout problem.
    127 	 */
    128 	timeout = timeout * TIMEOUT_PCT / 100;
    129 	scds_syslog_debug(SCDS_DBG_HIGH, "run-db-cmd timeout =%d", timeout);
    130 
    131 	rc = run_db_command(scds_handle, &sapdbxpropsp, timeout,
    132 		db_state_cmd, B_TRUE);
    133 
    134 	switch (rc) {
    135 		case DB_ONLINE:
    136 		case XSVR_DOWN:
    137 		case XSVR_UP:
    138 		case PARENT_DIE:
    139 					/*
    140 					 * this can happen if the DB was up
    141 					 * then crashed before HA is brought up
    142 					 * Failing it in Validate will not
    143 					 * help. So let Start handle it since
    144 					 * Start do db_clear before starting
    145 					 * DB. That should clear the problem.
    146 					 */
    147 		case PPID_FILE_GONE:
    148 					/*
    149 					 * validate is being run on all
    150 					 * potential master nodes. On the node
    151 					 * DB is not online, the ppid file
    152 					 * won't exist. So shouldn't check it
    153 					 * however, probe will do that.
    154 					 */
    155 		case DB_TIMEOUT:
    156 					/*
    157 					 * this can happen if the logical host
    158 					 * is not up at Validate time.
    159 					 */
    160 			rc = 0;
    161 			break;
    162 
    163 	default: /* Other errors, need to fail validate */
    164 		rc = 1;
    165 	}
    166 
    167 	free(db_state_cmd);
    168 	scds_syslog_debug(SCDS_DBG_HIGH, "in svc_validate rc = %d", rc);
    169 
    170 finished:
    171 	/* free memory allocated by get_sapdb_extension */
    172 	free_sapdb_property(&sapdbxpropsp);
    173 
    174 	/* Free up all the memory allocated by scds_initialize */
    175 	scds_close(&scds_handle);
    176 
    177 	/* Return the result of validate method */
    178 	return (rc);
    179 }
    180