/* Copyright (c) Oracle Corporation 1997. All Rights Reserved */ /*************************************************************** NAME stopServices.vrf DESCRIPTION Script that gets called from other scripts which gets a list of all the services currently running on the users machine. It then picks out all of the Ora* services which belong to the current home. It will display these services to the user and allow the user the following options: a) Cancel the installation b) Select services to be stopped and continue. OWNER NT Install Technologies Group within Server Technologies. MODIFIED MM/DD/YY Reason zzerhoun 06/08/98 Better handling of service queries Convert List displayName into string mmckerle 11/04/97 Created. ****************************************************************/ { /*** Initial Declaration of some variables and strings ***/ searchString = "Oracle"; OracleServices = list(); # This list will contain all running Oracle Services whose name matches Ora* ServicesToExtract = list(); # This list is used to compile the services to extract from the OracleServices list tryAgain = list(); # This list will contain any services which we should try again to shut down. /*** First execute services.vrf to define some variables used in the services ***/ execute("%installer_home%\services.vrf"); /*** Main logic: First get a list of all services. One by one, search the service name to see if it matches Ora*. If it doesn't, then search the DiplayName (if it exists) to see if it matches Ora*. If either of these is true, then add the service name to the OracleServices list. ***/ AllServices = win32_enumerate_keys("HKEY_LOCAL_MACHINE", "SYSTEM\CurrentControlSet\Services"); tempServices = AllServices; DNExists = TRUE; /*** Boolean to indicate whether the DisplayName of the service exists or not ***/ while(not(empty(tempServices))) { service = first(tempServices); if(contains(service, searchString)) { add(OracleServices, service); } else /*** search for the DisplayName ***/ { { DisplayName = win32_get_value("HKEY_LOCAL_MACHINE", "SYSTEM\CurrentControlSet\Services\%service%", "DisplayName"); { DisplayName = implode(DisplayName," "); } ['default: continue();] } [ 'DEFAULT: { DNExists = FALSE; continue(); } ] if(DNExists) { if(contains(DisplayName, searchString)) add(OracleServices, service); } } tempServices = rest(tempServices); DNExists = TRUE; } /*** Parse this list for any Oracle Service with an ImagePath pointing to the currently chosen Oracle Home. If the ImagePath does not match the Oracle_Home path, remove it from the list ***/ tempServices = OracleServices; while(not(empty(tempServices))) { service = first(tempServices); { ImagePath = win32_get_value("HKEY_LOCAL_MACHINE", "SYSTEM\CurrentControlSet\Services\%service%", "ImagePath"); } [ 'DEFAULT: { ImagePath = ""; continue(); } ] if(not(contains(ImagePath, "%oracle_home%\"))) { add(ServicesToExtract, service); } { tempServices = rest(tempServices); } [ 'EMPTY_LIST: continue(); ] } /*** Extract the appropriate services from the list and clear out ServicesToExtract list ***/ subtract(OracleServices, ServicesToExtract); ServicesToExtract = list(); /*** Now determine if any of these select Oracle Services are running ***/ tempServices = OracleServices; while(not(empty(tempServices))) { service = first(tempServices); status = winnt_query_service_status(service); if(status == SERVICE_STOPPED) add(ServicesToExtract, service); { tempServices = rest(tempServices); } [ 'EMPTY_LIST: continue(); ] } /*** Extract the appropriate services from the list and clear out ServicesToExtract list ***/ subtract(OracleServices, ServicesToExtract); ServicesToExtract = list(); /*** Now that the services have all been analyzed, if there are any running Oracle services, prompt the user ***/ if(not(empty(OracleServices))) { stopem = yesno_dialog( servicesDialogPrompt, servicesDialogTitle, servicesDialogHelp, 'NOCANCEL ); if(stopem) { tempServices = OracleServices; while(not(empty(tempServices))) { ui_action(instantiate(stopServicesMessage)); service = first(tempServices); while (TRUE) { service_status = nt_query_service_status(service); /* wait until current operation completes */ if (member(list(SERVICE_STOP_PENDING,SERVICE_START_PENDING, SERVICE_CONTINUE_PENDING,SERVICE_PAUSE_PENDING), service_status)) continue(); /* exit if stopped */ if (service_status == SERVICE_STOPPED) break(); /* stop if running or paused */ { nt_stop_service(service); } ['NO_RESPONSE: continue();] } tempServices = rest(tempServices); } /*** Because there may be dependencies of some services on others, and because the order in which the stopping of services occurs is not predetermined, we check to see if the tryAgain list has any more members, and try to stop these services again. If these still cannot be stopped, we raise an error. This algorithm will catch the OracleStartSID-OracleServiceSID dependency, for example ***/ if(not(empty(tryAgain))) { exitNow = FALSE; /*** flag which informs script to break out of loop ***/ tempServices = tryAgain; while(not(empty(tempServices))) { ui_action(instantiate(stopServicesMessage)); service = first(tempServices); { while (TRUE) { service_status = nt_query_service_status(service); /* wait until current operation completes */ if (member(list(SERVICE_STOP_PENDING,SERVICE_START_PENDING, SERVICE_CONTINUE_PENDING,SERVICE_PAUSE_PENDING), service_status)) continue(); /* exit if stopped */ if (service_status == SERVICE_STOPPED) break(); /* stop if running or paused */ { nt_stop_service(service); } ['NO_RESPONSE: continue();] } }['default: { information_dialog( couldNotStopMessage, couldNotStopTitle, couldNotStopHelp ); exitNow = TRUE; break(); } ] if(exitNow) break(); tempServices = rest(tempServices); } } } } }