def stop_db_service(self, service_candidates, timeout, disable_on_boot=False, update_db=False): """Stop the database service and wait for the database to shutdown. :param service_candidates: List of possible system service names. :type service_candidates: list :param timeout: Wait timeout in seconds. :type timeout: integer :param disable_on_boot: Disable service auto-start. The auto-start setting will be updated only if the service command succeeds. :type disable_on_boot: boolean :param update_db: Suppress the Trove instance heartbeat. :type update_db: boolean :raises: :class:`RuntimeError` on failure. """ LOG.info(_("Stopping database service.")) operating_system.stop_service(service_candidates) LOG.debug("Waiting for database to shutdown.") if not self._wait_for_database_service_status( instance.ServiceStatuses.SHUTDOWN, timeout, update_db): raise RuntimeError(_("Database failed to stop.")) LOG.info(_("Database has stopped successfully.")) if disable_on_boot: LOG.info(_("Disable service auto-start on boot.")) operating_system.disable_service_on_boot(service_candidates)
def _reset_admin_password(self): """ Reset the password of the Trove's administrative superuser. The service should not be running at this point. A general password reset procedure is: - disable user authentication and remote access - restart the service - update the password in the 'system_auth.credentials' table - re-enable authentication and make the host reachable - restart the service """ if self.status.is_running: raise RuntimeError(_("Cannot reset the administrative password. " "The service is still running.")) try: # Disable automatic startup in case the node goes down before # we have the superuser secured. operating_system.disable_service_on_boot(self.service_candidates) self.__disable_remote_access() self.__disable_authentication() # We now start up the service and immediately re-enable # authentication in the configuration file (takes effect after # restart). # Then we reset the superuser password to its default value # and restart the service to get user functions back. self.start_db(update_db=False, enable_on_boot=False) self.__enable_authentication() os_admin = self.__reset_user_password_to_default(self._ADMIN_USER) self.status = CassandraAppStatus(os_admin) self.restart() # Now change the administrative password to a new secret value. self.secure(update_user=os_admin) finally: self.stop_db() # Always restore the initial state of the service. # At this point, we should have a secured database with new Trove-only # superuser password. # Proceed to re-enable remote access and automatic startup. self.__enable_remote_access() operating_system.enable_service_on_boot(self.service_candidates)
def _disable_redis_on_boot(self): """ Disables redis on boot. """ LOG.info(_("Disabling Redis on boot.")) operating_system.disable_service_on_boot(system.SERVICE_CANDIDATES)