1 mike 1.25 //%/////////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM
4 //
5 // Permission is hereby granted, free of charge, to any person obtaining a copy
6 // of this software and associated documentation files (the "Software"), to
7 // deal in the Software without restriction, including without limitation the
8 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
9 // sell copies of the Software, and to permit persons to whom the Software is
10 // furnished to do so, subject to the following conditions:
11 //
12 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN
13 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED
14 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
15 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
16 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
17 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
18 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
19 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 //
21 //==============================================================================
22 mike 1.25 //
23 // Author: Mike Brasher (mbrasher@bmc.com)
24 //
25 // Modified By: Mike Day (mdday@us.ibm.com)
26 // =======
27 // Modified By: Karl Schopmeyer (k.schopmeyer@opengroup.org)
28 //
29 //%/////////////////////////////////////////////////////////////////////////////
30
31
32 //////////////////////////////////////////////////////////////////////
33 //
34 // Notes on deamon operation (Unix) and service operation (Win 32):
35 //
36 // To run pegasus as a daemon on Unix platforms, use the -d option:
37 //
38 // cimserver -d
39 //
40 // The -d option has no effect on windows operation.
41 //
42 // To run pegasus as an NT service, there are FOUR different possibilities:
43 mike 1.25 //
44 // To INSTALL the Pegasus service,
45 //
46 // cimserver -install
47 //
48 // To REMOVE the Pegasus service,
49 //
50 // cimserver -remove
51 //
52 // To START the Pegasus service,
53 //
54 // net start cimserver
55 //
56 // To STOP the Pegasus service,
57 //
58 // net stop cimserver
59 //
60 // Alternatively, you can use the windows service manager. Pegasus shows up
61 // in the service database as "Pegasus CIM Object Manager"
62 //
63 // Mike Day, mdday@us.ibm.com
64 mike 1.25 //
65 //////////////////////////////////////////////////////////////////////
66
67
68 #include <iostream>
69 #include <cstdlib>
70 #include <Pegasus/Common/FileSystem.h>
71 #include <Pegasus/Common/Selector.h>
72 #include <Pegasus/Common/OptionManager.h>
73 #include <Pegasus/Server/CIMServer.h>
74 #include <Pegasus/Common/PegasusVersion.h>
75 #include <Pegasus/Protocol/Handler.h>
76 #include <Pegasus/Common/Logger.h>
77 #include <Pegasus/Common/System.h>
|
79 mike 1.25
80
81
82 #if defined(PEGASUS_OS_TYPE_WINDOWS)
83 # include "cimserver_windows.cpp"
84 #elif defined(PEGASUS_OS_TYPE_UNIX)
85 # include "cimserver_unix.cpp"
86 #else
87 # error "Unsupported platform"
88 #endif
89
90 PEGASUS_USING_PEGASUS;
91 PEGASUS_USING_STD;
92
93 void GetEnvironmentVariables(
94 const char* arg0,
95 String& pegasusHome)
96 {
97 // Get environment variables:
98
99 const char* tmp = getenv("PEGASUS_HOME");
100 mike 1.25
101 if (!tmp)
102 {
103 cerr << arg0 << ": PEGASUS_HOME environment variable undefined" << endl;
104 exit(1);
105 }
106
107 pegasusHome = tmp;
108 FileSystem::translateSlashes(pegasusHome);
109 }
110
111 /** GetOptions function - This function defines the Options Table
112 and sets up the options from that table using the option manager.
113 */
114 void GetOptions(
115 OptionManager& om,
116 int& argc,
117 char** argv,
118 const String& pegasusHome)
119 {
120 static struct OptionRow optionsTable[] =
121 mike 1.25 {
122 {"port", "5988", false, Option::WHOLE_NUMBER, 0, 0, "port",
123 "specifies port number to listen on" },
124 {"trace", "false", false, Option::BOOLEAN, 0, 0, "t",
125 "turns on trace of Client IO to console "},
126 {"logtrace", "false", false, Option::BOOLEAN, 0, 0, "l",
127 "Turns on trace of Client IO to trace log "},
128 {"options", "false", false, Option::BOOLEAN, 0, 0, "options",
129 " Displays the settings of the Options "},
130 {"severity", "ALL", false, Option::STRING, 0, 0, "s",
131
132 "Sets the severity level that will be logged "},
133 {"logs", "ALL", false, Option::STRING, 0, 0, "X",
134 "Not Used "},
135 {"daemon", "false", false, Option::BOOLEAN, 0, 0, "d",
136 "Detach Pegasus from the console and run it in the background "},
137 {"logdir", "./logs", false, Option::STRING, 0, 0, "logdir",
138 "Directory for log files"},
139 {"cleanlogs", "false", false, Option::BOOLEAN, 0, 0, "clean",
140 "Clears the log files at startup"},
141 {"version", "false", false, Option::BOOLEAN, 0, 0, "v",
142 mike 1.25 "Displays Pegasus Version "},
143 {"help", "false", false, Option::BOOLEAN, 0, 0, "h",
144 "Prints help message with command line options "},
145 {"install", "false", false, Option::BOOLEAN, 0, 0, "install",
146 "Installs Pegasus as a Windows NT Service "},
147 {"remove", "false", false, Option::BOOLEAN, 0, 0, "remove",
148 "Removes Pegasus as a Windows NT Service "},
149 {"debug", "false", false, Option::BOOLEAN, 0, 0, "d",
150 "Not Used "},
|
152 mike 1.25 "Register Pegasus as a Service with SLP"}
153 };
154 const Uint32 NUM_OPTIONS = sizeof(optionsTable) / sizeof(optionsTable[0]);
155
156 om.registerOptions(optionsTable, NUM_OPTIONS);
157
158 String configFile = pegasusHome + "/testclient.conf";
159
160 cout << "Config file from " << configFile << endl;
161
162 if (FileSystem::exists(configFile))
163 om.mergeFile(configFile);
164 if(argc && argv != NULL)
165 om.mergeCommandLine(argc, argv);
166
167 om.checkRequiredOptions();
168 }
169
170 /* PrintHelp - This is temporary until we expand the options manager to allow
171 options help to be defined with the OptionRow entries and presented from
172 those entries.
173 mike 1.25 */
174 void PrintHelp(const char* arg0)
175 {
176 cout << '\n';
177 cout << PEGASUS_NAME << PEGASUS_VERSION << endl;
178 cout << '\n';
179 cout << "Usage: " << arg0 << endl;
180 cout << endl;
181 }
182
183 //////////////////////////////////////////////////////////////////////////
184 // MAIN
185 //////////////////////////////////////////////////////////////////////////
186 int main(int argc, char** argv)
187 {
188 // on Windows NT if there are no command-line options, run as a service
189
190 if (argc == 1 )
191 cim_server_service(argc, argv) ;
192
193 // Get environment variables:
194 mike 1.25
195 String pegasusHome;
196
197 GetEnvironmentVariables(argv[0], pegasusHome);
198
199 // Get options (from command line and from configuration file); this
200 // removes corresponding options and their arguments fromt he command
201 // line.
202
203 OptionManager om;
204
205 try
206 {
207 GetOptions(om, argc, argv, pegasusHome);
208 // om.print();
209 }
210 catch (Exception& e)
211 {
212 cerr << argv[0] << ": " << e.getMessage() << endl;
213 exit(1);
214 }
215 mike 1.25
216 // At this point, all options should have been extracted; print an
217 // error if there are any remaining:
218
219 if (argc != 1)
220 {
221 cerr << argv[0] << ": unrecognized options: ";
222
223 for (int i = 1; i < argc; i++)
224 cerr << argv[i] << ' ';
225 cout << endl;
226 exit(1);
227 }
228
229 // Check to see if we should (can) install as a NT service
230
231 String installOption;
232 if(om.lookupValue("install", installOption) && installOption == "true")
233 {
234 if( 0 != cimserver_install_nt_service( pegasusHome ))
235 cout << "\nPegasus installed as NT Service";
236 mike 1.25 exit(0);
237 }
238
239 // Check to see if we should (can) remove Pegasus as an NT service
240
241 String removeOption;
242 if(om.lookupValue("remove", removeOption) && removeOption == "true")
243 {
244 if( 0 != cimserver_remove_nt_service() )
245 cout << "\nPegasus removed as NT Service";
246 exit(0);
247
248 }
249
250 // Check to see if user asked for the version (-v otpion):
251
252 String versionOption;
253
254 if (om.lookupValue("version", versionOption) && versionOption == "true")
255 {
256 cerr << PEGASUS_VERSION << endl;
257 mike 1.25 exit(0);
258 }
259
260 // Check to see if user asked for help (-h otpion):
261 String helpOption;
262
263 if (om.lookupValue("help", helpOption) && helpOption == "true")
264 {
265 PrintHelp(argv[0]);
266 om.printHelp();
267 exit(0);
268 }
269
270 // Check the trace options and set global variable
271 Boolean pegasusIOTrace = false;
272 if (om.valueEquals("trace", "true"))
273 {
274 Handler::setMessageTrace(true);
275 pegasusIOTrace = true;
276 }
277
278 mike 1.25 Boolean pegasusIOLog = false;
279 if (om.valueEquals("logtrace", "true"))
280 {
281 Handler::setMessageLogTrace(true);
282 pegasusIOLog = true;
283 }
284
285 // Grab the port otpion:
286
287 String portOption;
288 om.lookupValue("port", portOption);
289
290 // Get the log file directory definition.
291 // We put String into Cstring because
292 // Directory functions only handle Cstring.
293 // ATTN-KS: create String based directory functions.
294 String logsDirectory;
295 om.lookupValue("logdir", logsDirectory);
296
297 // Set up the Logger. This does not open the logs
298 // Might be more logical to clean before set.
299 mike 1.25 // ATTN: Need tool to completely disable logging.
300 Logger::setHomeDirectory(logsDirectory);
301
302 if (om.valueEquals("cleanlogs", "true"))
303 {
304 Logger::clean(logsDirectory);;
305 }
306
|