Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Do not change permissions on existing data directory #48

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 28 additions & 11 deletions snap/hooks/install
Original file line number Diff line number Diff line change
@@ -1,28 +1,45 @@
#!/bin/bash
#!/usr/bin/env bash
# Installation hook for charmed-mongodb snap

set -eux

export CONF="${SNAP_DATA}"/etc/mongod
export PBM_CONF="${SNAP_DATA}"/etc/pbm
export DATA="${SNAP_COMMON}"/var/lib/mongodb
export LOGS="${SNAP_COMMON}"/var/log/mongodb
export MONGO_CONFIG_FILE="${CONF}"/mongod.conf

# Create the necessary parent directories
mkdir -p "${SNAP_DATA}/etc/pbm/"
mkdir -p "${SNAP_DATA}/etc/mongod/"
mkdir -p "${SNAP_COMMON}/var/lib/mongodb/"
mkdir -p "${SNAP_COMMON}/var/log/mongodb/"
mkdir -p $DATA
mkdir -p $LOGS
mkdir -p $PBM_CONF
mkdir -p $CONF

# If we just created the directory, we set up permissions
if [ stat -c '%u' "$DATA" == 0 ]; then
chmod -R 770 "${SNAP_COMMON}"
chmod 750 "${DATA}"
fi
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be recursive?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, as there will be no data in here in case we just created the directory, and we enter this block only if that's the case.
For a bit more exaplanation, there will be a complementary code on the charm side when attaching a storage to grant the right permissions to the attached storage, like they did in kafka operator.


# If we just created the directory, we set up permissions
if [ stat -c '%u' "$LOGS" == 0 ]; then
chmod -R 770 "${SNAP_COMMON}"
chmod g+s "$LOGS"/*
fi

chown -R 584788:root "${SNAP_COMMON}"/*

# Copy over the mongod.conf and create needed directories/files
MONGO_CONFIG_FILE="${SNAP_DATA}/etc/mongod/mongod.conf"
echo "configuration file does not exist."
echo "copying default config to ${MONGO_CONFIG_FILE}"
cp -r ${SNAP}/etc/mongod.conf ${MONGO_CONFIG_FILE}


# mongod.conf default values are not consistent with the snap directory system.
sed -i "s/fork: true/fork: false/g" $MONGO_CONFIG_FILE
sed -i "s:/var/log/mongodb:$SNAP_COMMON/var/log/mongodb:g" $MONGO_CONFIG_FILE
sed -i "s:/var/lib/mongodb:$SNAP_COMMON/var/lib/mongodb:g" $MONGO_CONFIG_FILE
sed -i "s:/var/log/mongodb:$LOGS:g" $MONGO_CONFIG_FILE
sed -i "s:/var/lib/mongodb:$DATA:g" $MONGO_CONFIG_FILE
sed -i "s:/var/run:/tmp:g" $MONGO_CONFIG_FILE

# Change ownership of snap directories to allow snap_daemon to read/write
chmod g+s "${SNAP_COMMON}/var/log/"*
chown -R 584788:root "${SNAP_DATA}"/*
chown -R 584788:root "${SNAP_COMMON}"/*
chgrp root "${SNAP_COMMON}/var/log/"*
Loading