This file documents how to upgrade an existing BHIMA installation to a new release. To learn about the releases process, see RELEASES.
Upgrading an existing installation takes three steps:
- Preparing the BHIMA software
- Preparing the database
- Running the upgrade
Steps 1 and 2 can happen in parallel and can be done at a leasurely pace. The third step is destructive and will commit the changes, deploying the new version at the location.
These steps describe the typical deployment setup. We assume that the BHIMA software is deployed in $HOME/apps/
, $VERSION
will be the next version name, and will refer to $DATABASE
as the database name.
- Go to https://github.com/ima-worldhealth/bhima/releases/latest in your web browser.
- Copy the link to the
$VERSION.tar.gz
file. - Connect to the server with SSH.
- Start a
screen
session in case the connection drops during the upgrade. - Change directory into
$HOME/apps/
. - Download the latest release with
wget -c "$URL"
where $URL is the url you copied in step 2. This will create$VERSION.tar.gz
in the$HOME/apps/
directory. - Unzip the release file with
tar xf $VERSION.tar.gz
. This will create the folderbhima-$RELEASE/
in the$HOME/apps/
directory. - Copy the
.env
file from the current application into thebhima-$RELEASE/bin/
folder and make any changes necessary to.env
. - Copy the contents (but not sub-directories) from the
bhima-$RELEASE/bin/
folder into thebhima-$RELEASE/
folder. This can be done withcp $HOME/apps/bhima-$RELEASE/bin/* $HOME/apps/bhima-$RELEASE/bin/
- Change directory into the release directory with
cd $HOME/apps/bhima-$RELEASE/
- Install the
node_modules/
in thebhima-$RELEASE/
folder with the command:NODE_ENV=production yarn
The BHIMA upgrade is not prepared.
Locally:
- Download the latest production database from the BHIMA backups server for the site you are upgrading.
- Build it locally.
- Change the environmental variable
$DB_NAME
in the.env
file in the bhima repository to the name of the site you are upgrading. - Run
yarn migrate
to create a migration scriptmigration-$DATABASE.sql
. - Copy in the migration files from up to the present version from the
server/models/migrations/
folder(s). You can usecat
for this. - Test the database migration script:
mysql $DATABASE < migration-$DATABASE.sql
- If it works, copy the database over to the remote server with
scp
:scp migration-$DATABASE.sql bhima@target.bhi.ma:~/
The database is now prepared.
- SSH into the production server.
- Create a backup of the production database using
mysqldump
. Typically, there is adump
routine available for you in$HOME/tasks/dump.sh
. - Run the database migration file in the production:
mysql $DATABASE < migration-$DATABASE.sql
- Remove the
$HOME/apps/bhima
soft link (rm $HOME/apps/bhima/
). - Create a new soft link pointing towards the new server:
ln -s $HOME/apps/bhima-$VERSION/ $HOME/apps/bhima
- Restart the BHIMA server:
systemctl restart bhima
- Check the journal logs:
journalctl -u bhima
- Reboot the server:
sudo reboot now
- Reconnect via SSH and check the journal logs again.