summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorJustin Dearing <jdearing@mongodb.org>2010-06-14 11:48:09 +0800
committerEliot <eliot@10gen.com>2010-06-14 12:08:25 +0800
commitd85697d41187390597ae7a90466dfd873055a88c (patch)
treee71ddf55238837ced39e9faee1b39b1e10a90ac9 /util
parentb7b0a7aa2a0ad10958eac7cf3ed6f0cc4498d940 (diff)
downloadmongo-d85697d41187390597ae7a90466dfd873055a88c.tar.gz
Improvements related to SERVER-1225.
If you specify --serviceUser without specifying a domain .\ is prepended to the name. Also fixed a typo in the logging.
Diffstat (limited to 'util')
-rw-r--r--util/ntservice.cpp29
1 files changed, 19 insertions, 10 deletions
diff --git a/util/ntservice.cpp b/util/ntservice.cpp
index 31dff9b20d6..e63ef5e6d89 100644
--- a/util/ntservice.cpp
+++ b/util/ntservice.cpp
@@ -85,7 +85,6 @@ namespace mongo {
SERVICE_ALL_ACCESS, SERVICE_WIN32_OWN_PROCESS,
SERVICE_AUTO_START, SERVICE_ERROR_NORMAL,
commandLineWide.str().c_str(), NULL, NULL, L"\0\0", NULL, NULL );
-
if ( schService == NULL ) {
log() << "Error creating service." << endl;
::CloseServiceHandle( schSCManager );
@@ -93,22 +92,32 @@ namespace mongo {
}
log() << "Service creation successful." << endl;
- log() << "Service can be started from the command line via 'net stop\"" << toUtf8String(serviceName) << "\"'." << endl;
+ log() << "Service can be started from the command line via 'net start \"" << toUtf8String(serviceName) << "\"'." << endl;
+
+ bool serviceInstalled;
// TODO: If neccessary grant user "Login as a Service" permission.
if ( !serviceUser.empty() ) {
- log() << "Setting service login credentials. User: " << toUtf8String(serviceUser) << endl;
- bool assignedUser = ChangeServiceConfig( schService, SERVICE_NO_CHANGE, SERVICE_NO_CHANGE, SERVICE_NO_CHANGE, NULL, NULL, NULL, NULL, serviceUser.c_str(), servicePassword.c_str(), NULL);
- if ( !assignedUser ) {
- log() << "Setting service login failed Service has 'LocalService' permissions." << endl;
+ std::wstring actualServiceUser;
+ if ( serviceUser.find(L"\\") == string::npos ) {
+ actualServiceUser = L".\\" + serviceUser;
+ }
+ else {
+ actualServiceUser = serviceUser;
}
- }
+ log() << "Setting service login credentials. User: " << toUtf8String(actualServiceUser) << endl;
+ serviceInstalled = ::ChangeServiceConfig( schService, SERVICE_NO_CHANGE, SERVICE_NO_CHANGE, SERVICE_NO_CHANGE, NULL, NULL, NULL, NULL, actualServiceUser.c_str(), servicePassword.c_str(), NULL );
+ if ( !serviceInstalled ) {
+ log() << "Setting service login failed. Service has 'LocalService' permissions." << endl;
+ }
+ }
+
+ // set the service description
SERVICE_DESCRIPTION serviceDescription;
serviceDescription.lpDescription = (LPTSTR)serviceDesc.c_str();
-
- // set new service description
- bool serviceInstalled = ::ChangeServiceConfig2( schService, SERVICE_CONFIG_DESCRIPTION, &serviceDescription );
+ serviceInstalled = ::ChangeServiceConfig2( schService, SERVICE_CONFIG_DESCRIPTION, &serviceDescription );
+
if ( serviceInstalled ) {
SC_ACTION aActions[ 3 ] = { { SC_ACTION_RESTART, 0 }, { SC_ACTION_RESTART, 0 }, { SC_ACTION_RESTART, 0 } };