Skip to content

Commit

Permalink
enable services to start on system start
Browse files Browse the repository at this point in the history
  • Loading branch information
MiaAltieri committed Sep 18, 2023
1 parent d9e7926 commit 5333c09
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ def _on_start(self, event: StartEvent) -> None:
self.unit.status = MaintenanceStatus("starting MongoDB")
snap_cache = snap.SnapCache()
mongodb_snap = snap_cache["charmed-mongodb"]
mongodb_snap.start(services=["mongod"])
mongodb_snap.start(services=["mongod"], enable=True)
self.unit.status = ActiveStatus()
except snap.SnapError as e:
logger.error("An exception occurred when starting mongod agent, error: %s.", str(e))
Expand Down Expand Up @@ -893,7 +893,7 @@ def _connect_mongodb_exporter(self) -> None:
snap_cache = snap.SnapCache()
mongodb_snap = snap_cache["charmed-mongodb"]
mongodb_snap.set({Config.Monitoring.URI_PARAM_NAME: self.monitor_config.uri})
mongodb_snap.restart(services=[Config.Monitoring.SERVICE_NAME])
mongodb_snap.restart(services=[Config.Monitoring.SERVICE_NAME], enable=True)

def _connect_pbm_agent(self) -> None:
"""Updates URI for pbm-agent."""
Expand All @@ -906,13 +906,13 @@ def _connect_pbm_agent(self) -> None:

snap_cache = snap.SnapCache()
pbm_snap = snap_cache["charmed-mongodb"]
pbm_snap.stop(services=[Config.Backup.SERVICE_NAME])
pbm_snap.stop(services=[Config.Backup.SERVICE_NAME], enable=True)
pbm_snap.set({Config.Backup.URI_PARAM_NAME: self.backup_config.uri})
try:
# Added to avoid systemd error:
# 'snap.charmed-mongodb.pbm-agent.service: Start request repeated too quickly'
time.sleep(1)
pbm_snap.start(services=[Config.Backup.SERVICE_NAME])
pbm_snap.start(services=[Config.Backup.SERVICE_NAME], enable=True)
except snap.SnapError as e:
logger.error(f"Failed to restart {Config.Backup.SERVICE_NAME}: {str(e)}")
self._get_service_status(Config.Backup.SERVICE_NAME)
Expand Down Expand Up @@ -1029,13 +1029,13 @@ def restart_mongod_service(self, auth=None):
try:
snap_cache = snap.SnapCache()
mongodb_snap = snap_cache["charmed-mongodb"]
mongodb_snap.stop(services=["mongod"])
mongodb_snap.stop(services=["mongod"], enable=True)
update_mongod_service(
auth,
self._unit_ip(self.unit),
config=self.mongodb_config,
)
mongodb_snap.start(services=["mongod"])
mongodb_snap.start(services=["mongod"], enable=True)
except snap.SnapError as e:
logger.error("An exception occurred when starting mongod agent, error: %s.", str(e))
self.unit.status = BlockedStatus("couldn't start MongoDB")
Expand Down Expand Up @@ -1081,7 +1081,7 @@ def start_backup_service(self) -> None:
"""
snap_cache = snap.SnapCache()
charmed_mongodb_snap = snap_cache["charmed-mongodb"]
charmed_mongodb_snap.start(services=["pbm-agent"])
charmed_mongodb_snap.start(services=["pbm-agent"], enable=True)

def restart_backup_service(self) -> None:
"""Restarts the pbm agent.
Expand All @@ -1091,7 +1091,7 @@ def restart_backup_service(self) -> None:
"""
snap_cache = snap.SnapCache()
charmed_mongodb_snap = snap_cache["charmed-mongodb"]
charmed_mongodb_snap.restart(services=["pbm-agent"])
charmed_mongodb_snap.restart(services=["pbm-agent"], enable=True)

def _scope_obj(self, scope: Scopes):
if scope == APP_SCOPE:
Expand Down

0 comments on commit 5333c09

Please sign in to comment.