Production NodeJS
How to set up couch2pg on Ubuntu Server 22 with NodeJS
CHT couch2pg is deprecated. For data synchronization, refer to CHT Sync.
This guide is for NodeJS on Ubuntu. See related Docker Compose on Ubuntu guide.
Assumptions
These instructions assume you’re on Ubuntu server 22.04 and are running both CHT Core and Postgres on other servers.
Prerequisites
- Postgres server with enough free space to sync all of CouchDB data
- Ubuntu server with minimum 4 cores 8GB RAM, 50GB disk
- Credentials for couch2pg to access Postgres
- Credentials for couch2pg to access CHT
Deployment
All commands are run as root
unless specified to run as couch2pg
:
- Install all the prerequisites. Note that we’re intentionally installing an old version of NodeJS (12.x LTS):
apt update && apt -y dist-upgrade && apt -y install postgresql-client curl git jq sudo apt update sudo apt -y install curl dirmngr apt-transport-https lsb-release ca-certificates curl -sL https://deb.nodesource.com/setup_12.x | sudo -E bash - sudo apt -y install nodejs npm
- Test with
psql
client on couch2pg server that it can connect and successfully authenticate to Postgres server. Be sure to use the IP of your SQL server (172.18.0.1
), user (postgres_root
) and database (cht
):psql -U cht_couch2pg -h 192.168.68.26 cht
- Test with
curl
client on couch2pg server that it can connect and successfully authenticate to CHT server. Again, be sure to use the correct CHT Core URL with login and password:curl -s https://medic:password@192-168-68-23.local-ip.medicmobile.org:10443/medic/ | jq
- Create
couch2pg
user on the Ubuntu server - As
couch2pg
user, clone couch2pg repo:git clone https://github.com/medic/cht-couch2pg.git
- As
couch2pg
user, install couch2pg dependencies:cd cht-couch2pg && npm ci
- As
couch2pg
user, test couch2pg. Be sure to use correct values forCOUCHDB_URL
andPOSTGRESQL_URL
:COUCHDB_URL=https://medic:password@192-168-68-23.local-ip.medicmobile.org:10443/medic \ POSTGRESQL_URL=postgres://cht_couch2pg:postgres_password@192.168.68.26:5432/cht \ node .
- Configure couch2pg in a
systemd
file at/etc/systemd/system/couch2pg.service
be sure that environment variables are updated (Environment=".."
):[Unit] Description=couch2pg Documentation=https://docs.communityhealthtoolkit.org/hosting/couch2pg/setup-and-devlopment/ After=network.target [Service] Environment="POSTGRESQL_URL=postgres://cht_couch2pg:postgres_password@192.168.68.26:5432/cht" Environment="COUCHDB_URL=https://medic:password@192-168-68-23.local-ip.medicmobile.org:10443/medic" Environment="COUCH2PG_SLEEP_MINS=360" Environment="COUCH2PG_DOC_LIMIT=100" Environment="COUCH2PG_CHANGES_LIMIT=5000" Environment="COUCH2PG_RETRY_COUNT=5" Environment="COUCH2PG_USERS_META_DOC_LIMIT=50" Type=simple User=couch2pg ExecStart=/usr/bin/node . WorkingDirectory=/home/couch2pg/cht-couch2pg Restart=on-failure [Install] WantedBy=multi-user.target
- Ensure couch2pg runs at boot:
systemctl enable couch2pg
- Reload systemd:
systemctl daemon-reload
- Reboot VM:
reboot
- Check for errors after reboot:
systemctl status couch2pg
- Monitor couch2pg logs for errors. If errors are found, re-run them and update this list to ensure accuracy. Add any new requirements above as well, as needed:
journalctl --follow --unit=couch2pg --lines=100
Last updated on
Did this documentation help you ?