-
Notifications
You must be signed in to change notification settings - Fork 23
save wp-content data to a separate volume #16
Changes from 9 commits
660e5bc
fedd17a
3f15530
4ec1503
d820392
5ab523c
d7a6f1c
2119322
85292c6
b4806ce
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
- hosts: all | ||
become: true | ||
vars: | ||
apache_user: www-data | ||
apache_group: "{{ apache_user }}" | ||
wp_install_dir: /usr/share/wordpress | ||
wp_content_dir: "{{ wp_install_dir }}/wp-content" | ||
tasks: | ||
|
@@ -33,6 +35,17 @@ | |
src: config.php | ||
# https://superuser.com/a/559371/102684 | ||
dest: /etc/wordpress/config-default.php | ||
owner: "{{ apache_user }}" | ||
group: "{{ apache_group }}" | ||
|
||
# https://help.ubuntu.com/community/WordPress#Install_WordPress | ||
- name: Fix permissions on WordPress directory | ||
file: | ||
path: "{{ wp_install_dir }}" | ||
owner: "{{ apache_user }}" | ||
group: "{{ apache_group }}" | ||
state: directory | ||
recurse: true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe 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 commentThe 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 commentThe 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. |
||
|
||
- name: Configure Apache | ||
template: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/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 | ||
|
||
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 | ||
|
||
echo "$devpath $DEST ext4 defaults,nofail,noatime,nodiratime,barrier=0,data=writeback 0 2" | sudo tee -a /etc/fstab > /dev/null | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should probably check that it doesn't exist before appending to fstab, yeah? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will look into the best way to do that. This script got complex enough that I'm considering changing it to Ansible (as a follow-up), which takes care of checks like that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (but let me know if you know of an example) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should be able to do with an egrep and regex:
|
||
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 themes directory doesn't exist... | ||
if [ ! -d "$DEST/themes" ]; then | ||
# ...volume doesn't contain initial data. Copy initial content in. | ||
# https://askubuntu.com/a/86891/501568 | ||
sudo cp -a $OLDDEST/. $DEST/ | ||
fi |
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}" | ||
} | ||
} | ||
} |
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.
I learned the hard way that WordPress saves the URL where it's accessed for the initial setup in the database, and therefore having the public IP change frequently was making parts of the site inaccessible. While a custom domain is what you'd actually use, an Elastic IP is good enough for now.
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.
You may want to look at installing the
wp-cli
to make changes like this easier to do from the machine itself in case you can't get in to the web interface.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.
Good call! Added as follow-up task: #22.