This repository has been archived by the owner on Oct 31, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
save wp-content data to a separate volume #16
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
660e5bc
add a volume for saving wp-content data
afeld fedd17a
mount volume after it's attached
afeld 3f15530
fix automatic mounting of volume
afeld 4ec1503
change the wordpress files to be owned by the apache user
afeld d820392
remove need for symlinking volume mounting
afeld 5ab523c
use an elastic IP for the EC2 instance
afeld d7a6f1c
move the volume configuration to its own file
afeld 2119322
encrypt the EBS volume
afeld 85292c6
prevent destruction of the EBS volume and the RDS instance
afeld b4806ce
don't copy mount info into fstab if already present
afeld 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
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
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
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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#!/bin/bash | ||
|
||
# adapted from | ||
# https://github.com/hashicorp/terraform/issues/2740#issuecomment-288549352 | ||
|
||
set -e | ||
set -x | ||
|
||
# note the name doesn't match the device_name in Terraform | ||
DEVICE=/dev/xvdf | ||
OWNER=www-data | ||
DEST=/usr/share/wordpress/wp-content | ||
OLDDEST=$DEST-old | ||
# if this directory is present, assume volume contains initial data | ||
CHECK_DIR=$DEST/themes | ||
|
||
devpath=$(readlink -f $DEVICE) | ||
|
||
if [[ $(sudo file -s $devpath) != *ext4* && -b $devpath ]]; then | ||
# Filesystem has not been created. Create it! | ||
sudo mkfs -t ext4 $devpath | ||
fi | ||
|
||
sudo mv $DEST $OLDDEST | ||
sudo mkdir -p $DEST | ||
|
||
# add to fstab if not present | ||
if ! egrep "^${devpath}" /etc/fstab; then | ||
echo "$devpath $DEST ext4 defaults,nofail,noatime,nodiratime,barrier=0,data=writeback 0 2" | sudo tee -a /etc/fstab > /dev/null | ||
fi | ||
sudo mount $DEST | ||
|
||
sudo chown $OWNER:$OWNER $DEST | ||
sudo chmod 0775 $DEST | ||
|
||
# TODO: /etc/rc3.d/S99local to maintain on reboot | ||
echo deadline | sudo tee /sys/block/$(basename "$devpath")/queue/scheduler | ||
echo never | sudo tee /sys/kernel/mm/transparent_hugepage/enabled | ||
|
||
if [ ! -d "$CHECK_DIR" ]; then | ||
# Copy initial content in. | ||
# https://askubuntu.com/a/86891/501568 | ||
sudo cp -a $OLDDEST/. $DEST/ | ||
fi |
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
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
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
resource "aws_ebs_volume" "wp_content" { | ||
availability_zone = "${data.aws_subnet.public.availability_zone}" | ||
type = "gp2" | ||
size = 10 | ||
encrypted = true | ||
|
||
lifecycle { | ||
prevent_destroy = true | ||
} | ||
} | ||
|
||
resource "aws_volume_attachment" "wp_content" { | ||
device_name = "/dev/sdf" | ||
volume_id = "${aws_ebs_volume.wp_content.id}" | ||
instance_id = "${aws_instance.wordpress.id}" | ||
|
||
# https://github.com/hashicorp/terraform/issues/2740#issuecomment-288549352 | ||
skip_destroy = true | ||
provisioner "remote-exec" { | ||
script = "files/attach-data-volume.sh" | ||
connection { | ||
user = "${var.ssh_user}" | ||
host = "${aws_eip.public.public_ip}" | ||
} | ||
} | ||
} |
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.
Not positive that we want to allow automatic updates...? That would mean WordPress itself wouldn't be deployed immutably. Happy to take the conversation to an issue.
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.
If the upstream source that deploys Wordpress on the instance is in sync with the updates, it may not be too bad. Wordpress updates download into /wp-content/updates and then deploy into the main directory. Sometimes those updates contain schema updates for the database as well. Lots to consider.
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.
So, the way that I did this for our modified version of cf-ex-wordpress (deploying in cloud.gov) was to do some json in a particular schema, and feed that to wp-cli.
Relevant python bits here: cloud-gov/cf-ex-wordpress@25be580#diff-81085e34fc3ba4cf38cba76d477219bdR59 . I'm sure that could be turned into some ansible code.
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.
Let's worry about it separately, if that's ok with you both: #23.