Skip to content

Commit

Permalink
set permissions for /var/lib/rabbitmq
Browse files Browse the repository at this point in the history
For certain storage providers, the mounted directory
/var/lib/rabbitmq is created with root:root as owner
and 755 permissions. This causes issues to start the
rabbitmq server.
Change permissions for directory /var/lib/rabbitmq
to 777.
  • Loading branch information
hemanthnakkina committed Apr 1, 2024
1 parent 815938a commit ddb8f0e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
RABBITMQ_SERVICE = "rabbitmq"
RABBITMQ_USER = "rabbitmq"
RABBITMQ_GROUP = "rabbitmq"
RABBITMQ_DATA_DIR = "/var/lib/rabbitmq"
RABBITMQ_COOKIE_PATH = "/var/lib/rabbitmq/.erlang.cookie"

SELECTOR_ALL = "all"
Expand Down Expand Up @@ -201,6 +202,9 @@ def _on_config_changed(self, event: EventBase) -> None:
event.defer()
return

# Change permission of /var/lib/rabbitmq
self._set_permission_on_data_dir()

# Render and push configuration files
self._render_and_push_config_files()

Expand Down Expand Up @@ -711,6 +715,16 @@ def _initialize_operator_user(self) -> None:
logging.warning("Deleting the guest user.")
api.delete_user("guest")

def _set_permission_on_data_dir(self) -> None:
"""Set permission on /var/lib/rabbitmq."""
container = self.unit.get_container(RABBITMQ_CONTAINER)

logger.debug(f"Changing permission for {RABBITMQ_DATA_DIR}")
try:
container.exec(["chmod", "777", RABBITMQ_DATA_DIR])
except ExecError as e:
logger.error(f"Exited with code {e.exit_code}. Stderr:\n{e.stderr}")

def _render_and_push_config_files(self) -> None:
"""Render and push configuration files.
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_charm.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ def test_rabbitmq_pebble_ready(self):
"""Test pebble handler."""
# self.harness.charm._render_and_push_config_files = Mock()
# self.harness.charm._render_and_push_plugins = Mock()
self.harness.charm._set_ownership_on_lib_dir = Mock()
# Check the initial Pebble plan is empty
self.harness.set_can_connect("rabbitmq", True)
initial_plan = self.harness.get_container_pebble_plan("rabbitmq")
Expand Down

0 comments on commit ddb8f0e

Please sign in to comment.