-
Notifications
You must be signed in to change notification settings - Fork 2
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 #49
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b5acc79
feat: Do not change permissions on existing data directory
Gu1nness ebf7ff3
fix: better file, handle log and lib
Gu1nness 7922242
fix: right permissions to be set
Gu1nness 5486519
fix: add documentation
Gu1nness 47009dc
fix: remove useless checks
Gu1nness e855760
fix: chdir to $SNAP before running command
Gu1nness File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
# 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/"* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still needed?