Ad_Feed

Wednesday, May 2, 2018

Guide for installing DHIS2 on Ubuntu 16.04 LTS 

Thanks to https://dhis-2.blogspot.com.ng/

Works up to DHIS 2.28

This guide assumes Ubuntu 16.04 LTS is installed on a local machine/VPS with 4GB of RAM and DHIS2 is used for testing purposes. This is based on the official DHIS2 documentation, correcting some of it's mistakes in the commands.

Login with the Ubuntu 'root' account or any account in the Ubuntu sudoers list.

  1. Setting server time zone
    sudo dpkg-reconfigure tzdata
  2. Creating an Ubuntu user to run DHIS2
    Create a new user called 'dhis' by invoking:
    sudo useradd -d /home/dhis -m dhis -s /bin/false

    Then set the password for the account by invoking:
    sudo passwd dhis
    Make sure you set a strong password
  3. Creating the configuration directory
    sudo mkdir /home/dhis/config

    Set ownership of the directory to 'dhis' user created above
    sudo chown dhis:dhis /home/dhis/config
  4. PostgreSQL installation
    sudo apt-get install postgresql-9.5 postgresql-contrib-9.5 postgresql-9.5-postgis-2.2
    Create a non-privileged PostgreSQL user called 'dhis' by invoking:
    sudo -u postgres createuser -SDRP dhis

    Create a database by invoking:
    sudo -u postgres createdb -O dhis dhis2

    Create the PostGIS extension
    sudo -u postgres psql -c "create extension postgis;" dhis2

  5. Creating DHIS2 configuration file
    sudo -u dhis nano /home/dhis/config/dhis.conf

    Insert following lines to the file (update PostgreSQL dhis user password according what you set above):

    # Hibernate SQL dialect
    connection.dialect = org.hibernate.dialect.PostgreSQLDialect

    # JDBC driver class
    connection.driver_class = org.postgresql.Driver

    # Database connection URL
    connection.url = jdbc:postgresql:dhis2

    # Database username
    connection.username = dhis

    # Database password
    connection.password =
    xxxx

    # Database schema behavior, can be validate, update, create, create-drop
    connection.schema = update

    # Encryption password (sensitive)
    encryption.password = xxxx

  6. Java installation
    Oracle Java will need to be installed manually because it no longer supports installation via apt-get.

    Create a directory to install Java

    mkdir /usr/java/

    cd /usr/java/

    wget -O java-linux-x64.tar.gz http://oracle-java-download-link
    (You need to replace http://oracle-java-download-link with "Linux x64" download link from this page: https://www.java.com/en/download/linux_manual.jsp
    It will be something like: http://javadl.oracle.com/webapps/download/AutoDL?BundleId=233162_512cd62ec5174c3487ac17c61aaa89e8)

    tar zxvf java-linux-x64.tar.gz



  7. Tomcat and DHIS2 installation
    sudo apt-get install tomcat7-user

    To create a Tomcat instance for DHIS2 move to the dhis folder created above:
    cd /home/dhis/

    Create Tomcat instance:
    sudo tomcat7-instance-create tomcat-dhis

    Set ownership of the created folder to dhis user
    sudo chown -R dhis:dhis /home/dhis/tomcat-dhis/

    Edit setenv.sh:
    sudo nano /home/dhis/tomcat-dhis/bin/setenv.sh

    Add the following lines to the bottom of the file:

    export JAVA_HOME='/usr/lib/jvm/java-8-oracle/'
    export JAVA_OPTS='-Xmx2000m -Xms1000m'
    export DHIS2_HOME='/home/dhis/config'


    The next step is to download the DHIS2 WAR file and place it into the webapps directory of Tomcat:
    wget https://www.dhis2.org/download/releases/2.28/dhis.war

    Move the WAR file into the Tomcat webapps directory. We want to call the WAR file ROOT.war in order to make it available at localhost directly without a context path:
    sudo mv dhis.war tomcat-dhis/webapps/ROOT.war

    DHIS2 should never be run as a privileged user, so edit the startup.sh:
    sudo nano /home/dhis/tomcat-dhis/bin/startup.sh

    Replace everything in the file with the following lines:

    #!/bin/sh
    set -e

    if [ "$(id -u)" -eq "0" ]; then
       echo "This script must NOT be run as root" 1>&2
       exit 1
    fi

    export CATALINA_BASE="/home/dhis/tomcat-dhis"
    /usr/share/tomcat7/bin/startup.sh
    echo "Tomcat started"
  8. Running DHIS2
    DHIS2 can now be started by invoking:
    sudo -u dhis tomcat-dhis/bin/startup.sh

    To monitor the behavior of Tomcat, the log is the primary source of information. The log can be viewed with the following command:
    tail -f tomcat-dhis/logs/catalina.out

    DHIS2 can be stopped by invoking:
    sudo -u dhis tomcat-dhis/bin/shutdown.sh
    Assuming that the WAR file is called ROOT.war, you can now access your DHIS2 instance at:

    http://localhost:8080 or
    http://your.server.ip.address:8080

    Default login details:
    Username: admin
    Password: district
  9. Starting DHIS2 at server startup
    Create init scripts:
    sudo nano tomcat

    Enter the following lines:

    #!/bin/sh
    #Tomcat init script

    HOME=/home/dhis/tomcat-dhis/bin

    case $1 in
    start)
       sudo -u dhis ${HOME}/startup.sh
       ;;
    stop)
       sudo -u dhis ${HOME}/shutdown.sh
       ;;
    restart)
       sudo -u dhis ${HOME}/shutdown.sh
       sleep 5
       sudo -u dhis ${HOME}/startup.sh
       ;;
    esac
    exit 0


    Move the script to the init script directory and make it executable by invoking:
    sudo mv tomcat /etc/init.d
    sudo chmod +x /etc/init.d/tomcat


    Next make sure the tomcat init script will be invoked during system startup and shutdown:
    sudo /usr/sbin/update-rc.d -f tomcat defaults 81

Friday, January 20, 2017

Warning Messages in "R" on Mac.

 When starting R (or using any IDE like RStudio), the following warning messages are displayed:
During startup - Warning messages:
1: Setting LC_CTYPE failed, using "C"
2: Setting LC_COLLATE failed, using "C"
3: Setting LC_TIME failed, using "C"
4: Setting LC_MESSAGES failed, using "C"
5: Setting LC_PAPER failed, using "C"
 To clear this error message, following the steps below:
  1. Open terminal and enter:
    defaults write org.R-project.R force.LANG en_US.UTF-8
  2. Restart R or R-studio.

Wednesday, December 30, 2015

How to backup multiple Mysql databases and automatically delete

The script below was adapted from iHRIS Backups (http://wiki.ihris.org/wiki/Backups) which was designed to backup one database. The script below will backup all databases in Mysql.

There is the option to remove database backup files older than 7days except from the first day of the month.


#!/bin/sh
MHOST=localhost
MUSER=db_username
MPASS=db_password
BACKUPDIR=/db/backup/dir

MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"

SUFFIX=`date +%F`
cd $BACKUPDIR

echo "Run MySQL backup"
DBS="$($MYSQL -u $MUSER -h $MHOST -p$MPASS -Bse 'show databases')"
for db in $DBS
do
    $MYSQLDUMP -u $MUSER -h $MHOST -p$MPASS $db > backup_${db}_${SUFFIX}.sql
    bzip2 -f backup_${db}_${SUFFIX}.sql
done
## Uncomment the following line to remove backup files older than 7 days except from the first day of the month.
#find $BACKUPDIR -name "backup_*.sql.bz2" -mtime +7 -not -name "backup_*-01.sql.bz2" -exec rm {} \;


Save the file, and ensure the script is executable using the command chmod a+x newfile.


Saturday, February 28, 2015

MySQL Databases - Commandline Backup and Restore

  • Backup A Single Database
    mysqldump -u root -p dbname > dbname.sql

    Where:
    dbname     = is the name of the database to backup
    dbname.sql = is the name of the backup file, can also be location of backup file

  • Restore A Single Database
    mysqldump -u root -p dbname < dbname.sql
  • Backup All Databases
    mysqldump -u root -p --all-databases > All-dbname.sql
  • Restore Single Database from All Database Backup
    mysql -u root -p --one-database dbname < All-dbname.sql

Tuesday, October 28, 2014

Perl warning Setting locale failed in Ubuntu

Perl Locale Warning.
The warnings could be irritating, especially when installing any application. The warnings are also visible when some commands are run

The warnings look like:
perl: warning: Falling back to the standard locale ("C").
locale: Cannot set LC_ALL to default locale: No such file or directory

 
and when you run Run locale from the commandline
bonkhi@sparda-coven:$ locale
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=en_US.UTF-8
LANGUAGE=
LC_CTYPE="en_US.UTF-8"
LC_NUMERIC=en_NG.UTF-8
LC_TIME=en_NG.UTF-8
LC_COLLATE="en_US.UTF-8"
LC_MONETARY=en_NG.UTF-8
LC_MESSAGES="en_US.UTF-8"
LC_PAPER=en_NG.UTF-8
LC_NAME=en_NG.UTF-8
LC_ADDRESS=en_NG.UTF-8
LC_TELEPHONE=en_NG.UTF-8
LC_MEASUREMENT=en_NG.UTF-8
LC_IDENTIFICATION=en_NG.UTF-8
LC_ALL=

To solve this, generate the missing locale
locale-gen en_US.UTF-8

Set the missing locale
export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
locale-gen en_US.UTF-8
dpkg-reconfigure locales

Friday, October 3, 2014

How do you reset the circuit protection on Yamaha RX-v373?

Yamaha RX-V373 AV receiver's protection circuity is activated when there is fluctuation in power three (3) consecutive times. This protection mode disables the capability to "turn on" the device.

To disable this:

Hold "Info + Tone Control + Straight" for at least five seconds, while still holding, press the "Power" button.

Manually reboot the AVR for normal operation.