version 1.57, 2002/06/01 00:25:05
|
version 1.60, 2002/06/04 01:42:38
|
|
|
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
// | // |
// Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM |
// Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM, |
|
// The Open Group, Tivoli Systems |
// | // |
// Permission is hereby granted, free of charge, to any person obtaining a copy | // Permission is hereby granted, free of charge, to any person obtaining a copy |
// of this software and associated documentation files (the "Software"), to | // of this software and associated documentation files (the "Software"), to |
|
|
// | // |
// Notes on deamon operation (Unix) and service operation (Win 32): | // Notes on deamon operation (Unix) and service operation (Win 32): |
// | // |
// To run pegasus as a daemon on Unix platforms, use the -d option: |
// To run pegasus as a daemon on Unix platforms: |
// | // |
// cimserver -d |
// cimserver |
// | // |
// The -d option has no effect on windows operation. |
// To NOT run pegasus as a daemon on Unix platforms, set the daemon config |
|
// property to false: |
|
// |
|
// cimserver daemon=false |
|
// |
|
// The daemon config property has no effect on windows operation. |
// | // |
// To shutdown pegasus, use the -s option: | // To shutdown pegasus, use the -s option: |
// | // |
// cimserver -s [-t timeout_value] |
// cimserver -s |
// | // |
// To run pegasus as an NT service, there are FOUR different possibilities: | // To run pegasus as an NT service, there are FOUR different possibilities: |
// | // |
|
|
| |
| |
#include <Pegasus/Common/Config.h> | #include <Pegasus/Common/Config.h> |
|
#include <Pegasus/Common/Constants.h> |
#include <Pegasus/suballoc/suballoc.h> | #include <Pegasus/suballoc/suballoc.h> |
#include <iostream> | #include <iostream> |
#include <cassert> | #include <cassert> |
|
|
| |
static const char OPTION_SHUTDOWN = 's'; | static const char OPTION_SHUTDOWN = 's'; |
| |
static const char OPTION_FORCE = 'f'; |
|
|
|
static const char OPTION_TIMEOUT = 't'; |
|
|
|
#if defined(PEGASUS_OS_HPUX) | #if defined(PEGASUS_OS_HPUX) |
static const char OPTION_BINDVERBOSE = 'X'; | static const char OPTION_BINDVERBOSE = 'X'; |
#endif | #endif |
| |
static const String NAMESPACE = "root/PG_Internal"; |
|
static const String CLASSNAME_SHUTDOWNSERVICE = "PG_ShutdownService"; |
|
static const String PROPERTY_TIMEOUT = "shutdownTimeout"; | static const String PROPERTY_TIMEOUT = "shutdownTimeout"; |
static const String CIMSERVERSTART_FILE = "/etc/wbem/cimserver_start.conf"; | static const String CIMSERVERSTART_FILE = "/etc/wbem/cimserver_start.conf"; |
| |
|
|
usage.append (COMMAND_NAME); | usage.append (COMMAND_NAME); |
usage.append (" [ [ options ] | [ configProperty=value, ... ] ]\n"); | usage.append (" [ [ options ] | [ configProperty=value, ... ] ]\n"); |
usage.append (" options\n"); | usage.append (" options\n"); |
usage.append (" -v - displays pegasus version number\n"); |
usage.append (" -v - displays CIM Server version number\n"); |
usage.append (" -h - prints this help message\n"); | usage.append (" -h - prints this help message\n"); |
|
usage.append (" -s - shuts down CIM Server\n"); |
|
#ifndef PEGASUS_OS_HPUX |
usage.append (" -D [home] - sets pegasus home directory\n"); | usage.append (" -D [home] - sets pegasus home directory\n"); |
usage.append (" -d - runs pegasus as a daemon\n"); |
#endif |
usage.append (" -s [-t timeout] \n"); |
#if defined(PEGASUS_OS_TYPE_WINDOWS) |
usage.append (" - shuts down pegasus\n"); |
|
#if !defined(PEGASUS_OS_HPUX) |
|
usage.append (" -cleanlogs - clears the log files at startup\n"); |
|
usage.append (" -install - installs pegasus as a Windows NT Service\n"); | usage.append (" -install - installs pegasus as a Windows NT Service\n"); |
usage.append (" -remove - removes pegasus as a Windows NT Service\n"); | usage.append (" -remove - removes pegasus as a Windows NT Service\n"); |
usage.append (" -slp - registers pegasus as a service with SLP\n\n"); |
|
usage.append (" -SSL - uses SSL\n\n"); |
|
#endif | #endif |
usage.append (" configProperty=value\n"); | usage.append (" configProperty=value\n"); |
usage.append (" port=nnnn - sets port number to listen on\n"); |
usage.append (" - sets CIM Server configuration property\n"); |
usage.append (" logdir=/pegasus/logs - directory for log files\n"); |
|
| |
cout << endl; | cout << endl; |
cout << PEGASUS_NAME << PEGASUS_VERSION << endl; | cout << PEGASUS_NAME << PEGASUS_VERSION << endl; |
|
|
// so that the command client does not timeout before the cimserver | // so that the command client does not timeout before the cimserver |
// terminates | // terminates |
// | // |
Uint32 clientTimeout; |
client.setTimeOut( (timeoutValue+2)*1000 ); |
if (timeoutValue == 0) |
|
{ |
|
String configTimeout = |
|
configManager->getCurrentValue("shutdownTimeout"); |
|
ArrayDestroyer<char> timeoutCString(configTimeout.allocateCString()); |
|
clientTimeout = |
|
((strtol(timeoutCString.getPointer(), (char **)0,10))+2)*1000; |
|
} |
|
else |
|
{ |
|
clientTimeout = (timeoutValue + 2)*1000; |
|
} |
|
|
|
client.setTimeOut(clientTimeout); |
|
} | } |
catch(CIMClientException& e) | catch(CIMClientException& e) |
{ | { |
|
|
// | // |
String referenceStr = "//"; | String referenceStr = "//"; |
referenceStr.append(hostStr); | referenceStr.append(hostStr); |
referenceStr.append(PEGASUS_NAMESPACENAME_CIMV2); |
referenceStr.append(PEGASUS_NAMESPACENAME_SHUTDOWN); |
referenceStr.append(":"); | referenceStr.append(":"); |
referenceStr.append(PEGASUS_CLASSNAME_SHUTDOWN); | referenceStr.append(PEGASUS_CLASSNAME_SHUTDOWN); |
CIMObjectPath reference(referenceStr); | CIMObjectPath reference(referenceStr); |
|
|
CIMValue(Uint32(timeoutValue)))); | CIMValue(Uint32(timeoutValue)))); |
| |
CIMValue retValue = client.invokeMethod( | CIMValue retValue = client.invokeMethod( |
NAMESPACE, |
PEGASUS_NAMESPACENAME_SHUTDOWN, |
reference, | reference, |
"shutdown", | "shutdown", |
inParams, | inParams, |
|
|
Boolean useSSL = false; | Boolean useSSL = false; |
Boolean daemonOption = false; | Boolean daemonOption = false; |
Boolean shutdownOption = false; | Boolean shutdownOption = false; |
Boolean timeoutOption = false; |
Uint32 timeoutValue = 0; |
String timeoutStr = String::EMPTY; |
|
long timeoutValue = 0; |
|
| |
// | // |
// Get environment variables: | // Get environment variables: |
|
|
} | } |
else | else |
{ | { |
// Get help, version and home options |
// Get help, version, and shutdown options |
| |
for (int i = 1; i < argc; ) | for (int i = 1; i < argc; ) |
{ | { |
|
|
// | // |
else if (*option == OPTION_SHUTDOWN) | else if (*option == OPTION_SHUTDOWN) |
{ | { |
|
|
// | // |
// check to see if user is root | // check to see if user is root |
// | // |
|
|
memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*)); | memmove(&argv[i], &argv[i + 1], (argc-i) * sizeof(char*)); |
argc--; | argc--; |
} | } |
else if (*option == OPTION_TIMEOUT) |
|
{ |
|
// |
|
// Check to see if shutdown has been specified: |
|
// |
|
if (!shutdownOption) |
|
{ |
|
cout << "Invalid option -" << option << endl; |
|
exit(0); |
|
} |
|
|
|
if (timeoutOption) |
|
{ |
|
cout << "Duplicate timeout option specified." << endl; |
|
exit(0); |
|
} |
|
|
|
timeoutOption = true; |
|
|
|
if (i + 1 < argc) |
|
{ |
|
// get timeout value |
|
timeoutStr.assign(argv[i + 1]); |
|
|
|
// validate timeout value string |
|
char* tmp = timeoutStr.allocateCString(); |
|
char* end = 0; |
|
timeoutValue = strtol(tmp, &end, 10); |
|
|
|
if (!end || *end != '\0') |
|
{ |
|
cout << "invalid timeout value specified: "; |
|
cout << timeoutStr << endl; |
|
delete [] tmp; |
|
exit(0); |
|
} |
|
} |
|
else |
|
{ |
|
cout << "Missing argument for option -"; |
|
cout << option << endl; |
|
exit(0); |
|
} |
|
|
|
// remove the option from the command line |
|
memmove(&argv[i], &argv[i + 2], (argc-i-1) * sizeof(char*)); |
|
argc -= 2; |
|
} |
|
else | else |
i++; | i++; |
} | } |
|
|
exit(1); | exit(1); |
} | } |
| |
|
|
try | try |
{ | { |
// | // |
|
|
// | // |
if (shutdownOption) | if (shutdownOption) |
{ | { |
// |
String configTimeout = |
// if timeout was specified, validate the timeout value |
configManager->getCurrentValue("shutdownTimeout"); |
// |
ArrayDestroyer<char> timeoutCString(configTimeout.allocateCString()); |
if (timeoutOption) |
timeoutValue = strtol(timeoutCString.getPointer(), (char **)0, 10); |
{ |
|
Boolean valid = configManager->validatePropertyValue( |
|
PROPERTY_TIMEOUT, |
|
timeoutStr); |
|
if (!valid) |
|
{ |
|
cout << "Invalid timeout value specified: " << timeoutValue; |
|
cout << endl; |
|
exit(1); |
|
} |
|
} |
|
| |
shutdownCIMOM(timeoutValue); | shutdownCIMOM(timeoutValue); |
| |
cout << "Pegasus CIM Server stopped." << endl; |
cout << "CIM Server stopped." << endl; |
exit(0); | exit(0); |
} | } |
| |
|
|
} | } |
catch(Exception& e) | catch(Exception& e) |
{ | { |
Logger::put(Logger::STANDARD_LOG, "CIMServer", Logger::INFORMATION, |
|
"$0 .Abnormal Termination.", e.getMessage()); |
|
|
|
PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl); | PEGASUS_STD(cerr) << "Error: " << e.getMessage() << PEGASUS_STD(endl); |
return 1; | return 1; |
} | } |