⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 control.c

📁 linux集群服务器软件代码包
💻 C
📖 第 1 页 / 共 2 页
字号:
/*  * Copyright (C) 2004 Andrew Beekhof <andrew@beekhof.net> *  * This program 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 2.1 of the License, or (at your option) any later version. *  * This software 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 this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */#include <sys/param.h>#include <crm/crm.h>#include <crm/cib.h>#include <crm/msg_xml.h>#include <crm/common/ctrl.h>#include <crmd.h>#include <crmd_fsa.h>#include <fsa_proto.h>#include <crmd_messages.h>#include <crmd_callbacks.h>#include <sys/types.h>#include <sys/stat.h>#include <crm/dmalloc_wrapper.h>extern void crmd_ha_connection_destroy(gpointer user_data);extern gboolean stop_all_resources(void);gboolean crm_shutdown(int nsig, gpointer unused);gboolean register_with_ha(ll_cluster_t *hb_cluster, const char *client_name);GHashTable   *ipc_clients = NULL;/*	 A_HA_CONNECT	*/enum crmd_fsa_inputdo_ha_control(long long action,	       enum crmd_fsa_cause cause,	       enum crmd_fsa_state cur_state,	       enum crmd_fsa_input current_input,	       fsa_data_t *msg_data){	gboolean registered = FALSE;		if(action & A_HA_DISCONNECT) {		if(fsa_cluster_conn != NULL) {			fsa_cluster_conn->llc_ops->signoff(fsa_cluster_conn);		}			}		if(action & A_HA_CONNECT) {		if(fsa_cluster_conn == NULL)			fsa_cluster_conn = ll_cluster_new("heartbeat");		/* make sure we are disconnected first */		fsa_cluster_conn->llc_ops->signoff(fsa_cluster_conn);				registered = register_with_ha(			fsa_cluster_conn, crm_system_name);				if(registered == FALSE) {			register_fsa_error(C_FSA_INTERNAL, I_FAIL, NULL);			return I_NULL;		}	} 		if(action & ~(A_HA_CONNECT|A_HA_DISCONNECT)) {		crm_err("Unexpected action %s in %s",		       fsa_action2string(action), __FUNCTION__);	}			return I_NULL;}/*	 A_SHUTDOWN	*/enum crmd_fsa_inputdo_shutdown(long long action,	    enum crmd_fsa_cause cause,	    enum crmd_fsa_state cur_state,	    enum crmd_fsa_input current_input,	    fsa_data_t *msg_data){	enum crmd_fsa_input next_input = I_NULL;	enum crmd_fsa_input tmp = I_NULL;	/* just in case */	set_bit_inplace(fsa_input_register, R_SHUTDOWN);		/* last attempt to shut these down */	if(is_set(fsa_input_register, R_PE_CONNECTED)) {		crm_warn("Last attempt to shutdown the PolicyEngine");		tmp = do_pe_control(A_PE_STOP, cause, cur_state,				    current_input, msg_data);		if(tmp != I_NULL) {			next_input = I_ERROR;			crm_err("Failed to shutdown the PolicyEngine");		}	}	if(is_set(fsa_input_register, R_TE_CONNECTED)) {		crm_warn("Last attempt to shutdown the Transitioner");		tmp = do_pe_control(A_TE_STOP, cause, cur_state,				    current_input, msg_data);		if(tmp != I_NULL) {			next_input = I_ERROR;			crm_err("Failed to shutdown the Transitioner");		}	}	crm_info("Stopping all remaining local resources");	stop_all_resources();		return next_input;}/*	 A_SHUTDOWN_REQ	*/enum crmd_fsa_inputdo_shutdown_req(long long action,	    enum crmd_fsa_cause cause,	    enum crmd_fsa_state cur_state,	    enum crmd_fsa_input current_input,	    fsa_data_t *msg_data){	enum crmd_fsa_input next_input = I_NULL;	HA_Message *msg = NULL;		crm_info("Sending shutdown request to DC");	msg = create_request(		CRM_OP_SHUTDOWN_REQ, NULL, NULL,		CRM_SYSTEM_DC, CRM_SYSTEM_CRMD, NULL);	set_bit_inplace(fsa_input_register, R_STAYDOWN);		if(send_request(msg, NULL) == FALSE) {		next_input = I_ERROR;	}	return next_input;}/*	 A_EXIT_0, A_EXIT_1	*/enum crmd_fsa_inputdo_exit(long long action,	enum crmd_fsa_cause cause,	enum crmd_fsa_state cur_state,	enum crmd_fsa_input current_input,	fsa_data_t *msg_data){	int exit_code = 0;	gboolean do_exit = FALSE;	if(action & A_EXIT_0) {		do_exit = TRUE;		crm_info("Performing %s - gracefully exiting the CRMd",			 fsa_action2string(action));	} else {		do_exit = TRUE;		exit_code = 1;		crm_warn("Performing %s - forcefully exiting the CRMd... now!",			 fsa_action2string(action));	}	if(is_set(fsa_input_register, R_STAYDOWN)) {		crm_info("Inhibiting respawn by Heartbeat");		exit_code = 100;	}	if(do_exit) {		crm_info("[%s] stopped (%d)", crm_system_name, exit_code);		exit(exit_code);	}		return I_NULL;}/*	 A_STARTUP	*/enum crmd_fsa_inputdo_startup(long long action,	   enum crmd_fsa_cause cause,	   enum crmd_fsa_state cur_state,	   enum crmd_fsa_input current_input,	   fsa_data_t *msg_data){	int was_error = 0;	int interval = 1; /* seconds between DC heartbeats */	crm_info("Register Signal Handler");	G_main_add_SignalHandler(		G_PRIORITY_HIGH, SIGTERM, crm_shutdown, NULL, NULL);	ipc_clients = g_hash_table_new(g_str_hash, g_str_equal);		if(was_error == 0) {		crm_info("Init server comms");		was_error = init_server_ipc_comms(			crm_strdup(CRM_SYSTEM_CRMD), crmd_client_connect,			default_ipc_connection_destroy);	}		if(was_error == 0) {		crm_info("Creating CIB object");		fsa_cib_conn = cib_new();	}		/* set up the timers */	crm_malloc(dc_heartbeat, sizeof(fsa_timer_t));	crm_malloc(integration_timer, sizeof(fsa_timer_t));	crm_malloc(finalization_timer, sizeof(fsa_timer_t));	crm_malloc(election_trigger, sizeof(fsa_timer_t));	crm_malloc(election_timeout, sizeof(fsa_timer_t));	crm_malloc(shutdown_escalation_timer, sizeof(fsa_timer_t));	crm_malloc(wait_timer, sizeof(fsa_timer_t));	interval = interval * 1000;	if(election_trigger != NULL) {		election_trigger->source_id = -1;		election_trigger->period_ms = -1;		election_trigger->fsa_input = I_DC_TIMEOUT;		election_trigger->callback = timer_popped;	} else {		was_error = TRUE;	}		if(dc_heartbeat != NULL) {		dc_heartbeat->source_id = -1;		dc_heartbeat->period_ms = -1;		dc_heartbeat->fsa_input = I_NULL;		dc_heartbeat->callback = do_dc_heartbeat;	} else {		was_error = TRUE;	}		if(election_timeout != NULL) {		election_timeout->source_id = -1;		election_timeout->period_ms = -1;		election_timeout->fsa_input = I_ELECTION_DC;		election_timeout->callback = timer_popped;	} else {		was_error = TRUE;	}		if(integration_timer != NULL) {		integration_timer->source_id = -1;		integration_timer->period_ms = -1;		integration_timer->fsa_input = I_INTEGRATED;		integration_timer->callback = timer_popped;	} else {		was_error = TRUE;	}		if(finalization_timer != NULL) {		finalization_timer->source_id = -1;		finalization_timer->period_ms = -1;		finalization_timer->fsa_input = I_FINALIZED;		finalization_timer->callback = timer_popped;	} else {		was_error = TRUE;	}		if(shutdown_escalation_timer != NULL) {		shutdown_escalation_timer->source_id = -1;		shutdown_escalation_timer->period_ms = -1;		shutdown_escalation_timer->fsa_input = I_TERMINATE;		shutdown_escalation_timer->callback = timer_popped;	} else {		was_error = TRUE;	}		if(wait_timer != NULL) {		wait_timer->source_id = -1;		wait_timer->period_ms = 3*1000;		wait_timer->fsa_input = I_NULL;		wait_timer->callback = timer_popped;	} else {		was_error = TRUE;	}		/* set up the sub systems */	crm_malloc(cib_subsystem, sizeof(struct crm_subsystem_s));	crm_malloc(te_subsystem,  sizeof(struct crm_subsystem_s));	crm_malloc(pe_subsystem,  sizeof(struct crm_subsystem_s));	if(cib_subsystem != NULL) {		cib_subsystem->pid      = -1;			cib_subsystem->path     = BIN_DIR;		cib_subsystem->name     = CRM_SYSTEM_CIB;		cib_subsystem->command  = BIN_DIR"/"CRM_SYSTEM_CIB;		cib_subsystem->args     = "-VVc";		cib_subsystem->flag_connected = R_CIB_CONNECTED;			cib_subsystem->flag_required  = R_CIB_REQUIRED;		} else {		was_error = TRUE;	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -