This source file includes following definitions.
- main
- log_deprecation_warnings
- crmd_init
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <crm_internal.h>
20
21 #include <sys/param.h>
22 #include <stdio.h>
23 #include <sys/types.h>
24 #include <sys/stat.h>
25 #include <unistd.h>
26
27 #include <stdlib.h>
28 #include <errno.h>
29 #include <fcntl.h>
30
31 #include <crm/crm.h>
32 #include <crm/common/ipc.h>
33 #include <crm/common/xml.h>
34
35 #include <crmd.h>
36 #include <crmd_fsa.h>
37 #include <crmd_messages.h>
38
39 #define OPTARGS "hV"
40
41 void usage(const char *cmd, int exit_status);
42 int crmd_init(void);
43 void crmd_hamsg_callback(const xmlNode * msg, void *private_data);
44 extern void init_dotfile(void);
45
46 GMainLoop *crmd_mainloop = NULL;
47
48
49 static struct crm_option long_options[] = {
50
51 {"help", 0, 0, '?', "\tThis text"},
52 {"verbose", 0, 0, 'V', "\tIncrease debug output"},
53
54 {0, 0, 0, 0}
55 };
56
57
58 int
59 main(int argc, char **argv)
60 {
61 int flag;
62 int index = 0;
63 int argerr = 0;
64
65 crmd_mainloop = g_main_new(FALSE);
66 crm_log_preinit(NULL, argc, argv);
67 crm_set_options(NULL, "[options]", long_options,
68 "Daemon for aggregating resource and node failures as well as co-ordinating the cluster's response");
69
70 while (1) {
71 flag = crm_get_option(argc, argv, &index);
72 if (flag == -1)
73 break;
74
75 switch (flag) {
76 case 'V':
77 crm_bump_log_level(argc, argv);
78 break;
79 case 'h':
80 crm_help(flag, EX_OK);
81 break;
82 default:
83 ++argerr;
84 break;
85 }
86 }
87
88 if (argc - optind == 1 && safe_str_eq("metadata", argv[optind])) {
89 crmd_metadata();
90 return 0;
91 } else if (argc - optind == 1 && safe_str_eq("version", argv[optind])) {
92 fprintf(stdout, "CRM Version: %s (%s)\n", PACEMAKER_VERSION, BUILD_VERSION);
93 return 0;
94 }
95
96 crm_log_init(NULL, LOG_INFO, TRUE, FALSE, argc, argv, FALSE);
97 crm_info("CRM Git Version: %s (%s)", PACEMAKER_VERSION, BUILD_VERSION);
98
99 if (optind > argc) {
100 ++argerr;
101 }
102
103 if (argerr) {
104 crm_help('?', EX_USAGE);
105 }
106
107 if (crm_is_writable(PE_STATE_DIR, NULL, CRM_DAEMON_USER, CRM_DAEMON_GROUP, FALSE) == FALSE) {
108 crm_err("Bad permissions on " PE_STATE_DIR ". Terminating");
109 fprintf(stderr, "ERROR: Bad permissions on " PE_STATE_DIR ". See logs for details\n");
110 fflush(stderr);
111 return 100;
112
113 } else if (crm_is_writable(CRM_CONFIG_DIR, NULL, CRM_DAEMON_USER, CRM_DAEMON_GROUP, FALSE) ==
114 FALSE) {
115 crm_err("Bad permissions on " CRM_CONFIG_DIR ". Terminating");
116 fprintf(stderr, "ERROR: Bad permissions on " CRM_CONFIG_DIR ". See logs for details\n");
117 fflush(stderr);
118 return 100;
119 }
120
121 return crmd_init();
122 }
123
124 static void
125 log_deprecation_warnings()
126 {
127 enum cluster_type_e cluster_type = get_cluster_type();
128
129 if (cluster_type != pcmk_cluster_corosync) {
130 crm_warn("Support for cluster infrastructure %s "
131 " is deprecated and will be removed in a future release",
132 name_for_cluster_type(cluster_type));
133
134 }
135
136 #if ENABLE_SNMP
137 crm_warn("Compile-time support for crm_mon SNMP options"
138 " is deprecated and will be removed in a future release"
139 " (configure alerts instead)",
140 name_for_cluster_type(cluster_type));
141 #endif
142 #if ENABLE_ESMTP
143 crm_warn("Compile-time support for crm_mon SMTP options"
144 " is deprecated and will be removed in a future release"
145 " (configure alerts instead)",
146 name_for_cluster_type(cluster_type));
147 #endif
148
149 if (getenv("LRMD_MAX_CHILDREN")) {
150 crm_warn("The LRMD_MAX_CHILDREN environment variable"
151 " is deprecated and will be removed in a future release"
152 " (use PCMK_node_action_limit instead)");
153 }
154 }
155
156 int
157 crmd_init(void)
158 {
159 int exit_code = 0;
160 enum crmd_fsa_state state;
161
162 log_deprecation_warnings();
163
164 fsa_state = S_STARTING;
165 fsa_input_register = 0;
166
167 init_dotfile();
168 crm_debug("Starting %s", crm_system_name);
169 register_fsa_input(C_STARTUP, I_STARTUP, NULL);
170
171 crm_peer_init();
172 state = s_crmd_fsa(C_STARTUP);
173
174 if (state == S_PENDING || state == S_STARTING) {
175
176 crm_trace("Starting %s's mainloop", crm_system_name);
177
178 #ifdef REALTIME_SUPPORT
179 static int crm_realtime = 1;
180
181 if (crm_realtime == 1) {
182 cl_enable_realtime();
183 } else if (crm_realtime == 0) {
184 cl_disable_realtime();
185 }
186 cl_make_realtime(SCHED_RR, 5, 64, 64);
187 #endif
188 g_main_run(crmd_mainloop);
189 if (is_set(fsa_input_register, R_STAYDOWN)) {
190 crm_info("Inhibiting automated respawn");
191 exit_code = 100;
192 }
193
194 } else {
195 crm_err("Startup of %s failed. Current state: %s",
196 crm_system_name, fsa_state2string(state));
197 exit_code = 1;
198 }
199
200 crm_info("%lu stopped: %s (%d)",
201 (unsigned long) getpid(), pcmk_strerror(exit_code), exit_code);
202 return crmd_fast_exit(exit_code);
203 }