Hosting the CHT on self run infrastracture
AWS Hosting in CHT 3.x
Most production CHT instances are deployed on AWS EC2. Leveraging Elastic Compute Cloud (EC2) and Elastic Block Store (EBS), CHT instances can easily be scaled up with larger EC2 instances and have easy increased disk space, backup and restores with EBS.
This guide will walk you through the process of creating an EC2 instance, mounting an EBS volume and provisioning Docker containers.
Create and Configure EC2 Instance
Create EC2 (use security best practices)
Review the CHT hardware requirements and start with an appropriately sized instance. After creating the instance and downloading the
.pemfile, change permissions to
sudo chmod 0600 ~/Downloads/name_of_file.pem
You should now be able to SSH into the EC2 instance using the EIP and the
Goal: SSH into instance
Create or Restore EBS Volume
- Create or Restore your EBS Volume, tagging appropriately, so it can be found later.
- Attach volume to EC2 instance
- Increase disk size (Optional)
- If you are using a newly created EBS Volume, you will have to format the disk appropriately:
- SSH into instance
- Follow the instructions here: Using EBS Volumes
sudo mkfs -t ext4 <location>in step 4
- Mount disk to
Goal: Mount EBS volume to
Provision Docker server
Follow README & Run scripts in cht-infrastructure repository.
Goal: CHT Application bootstraps and comes online
- Point DNS
Arecord to EIP given to Docker server in the prior step.
- Point DNS
Review SSL certificates
- Location of certs is
- Name the key file is
default.keyand the certificate file is
- See SSL Certficates to install new certificates
- Location of certs is
Configure couch2pg See the couch2pg basic configuration in the
Setup postgres to work with couch2pg
- Creating the database, setting up permissions, exploring the tables and what they store
- Understanding the log and what the entries mean
- Helpful docker commands (includes getting shell on containers)
- Inside container, all appropriate logs can be found in:
Upgrading the container
Backup all data (EBS)
Log into container and stop all services
To prepare for the upgrade, delete all other files in
medic-coredirectory is where the CHT stores user data. Of key importance is
./medic-core/couchdb/local.d/where custom CouchDB configuration is stored.
Launch new containers with appropriate
Upgrading the webapp
- Use Admin GUI page
- CLI via horticulturalist
Restoring from backup
- Create volume from snapshot
- Tag appropriately for backups
- Mount volume to docker server
Increasing disk size
Monitor disk usage so alerts are sent before all disk spaces is used up. If free disk space falls below 40%, increase the disk space as follows:
- Stop medic:
sudo supervisorctl stop medic
- Go to EBS in AWS and take a snapshot of the volume.
- Modify the volume size (Increase it by 2x preferably). Wait until the modification succeeds.
- Make the instance recognize the additional space
- Turn medic back on:
sudo supervisorctl start medic
Monitoring & Backup
- AWS CloudWatch and monitoring tab. Enable detailed monitoring (This costs more money)
- Set up Lifecycle Management for EBS snapshots
- Steps to mounting a backup snapshot to the instance and restarting the application
- Please see the second-half of “Increasing disk size” reference above
- Setup a TLS cert & DNS registration
Dealing with out-of-memory errors in couch2pg
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.