------------------------------------------------------------ revno: 8323 committer: Jason P. Pickering <[email protected]> branch nick: dhis2 timestamp: Mon 2012-10-01 16:08:57 +0200 message: Modified Ubuntu scripts. More to come. added: resources/util/dhis2_serveropt.sh renamed: resources/util/create_ubuntu_instance.sh => resources/util/dhis2_create_ubuntu_instance.sh modified: resources/util/dhis2_create_ubuntu_instance.sh
-- lp:dhis2 https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk Your team DHIS 2 developers is subscribed to branch lp:dhis2. To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== renamed file 'resources/util/create_ubuntu_instance.sh' => 'resources/util/dhis2_create_ubuntu_instance.sh' --- resources/util/create_ubuntu_instance.sh 2012-09-25 15:43:58 +0000 +++ resources/util/dhis2_create_ubuntu_instance.sh 2012-10-01 14:08:57 +0000 @@ -1,72 +1,72 @@ #!/bin/bash -#A basic script to stand-up a basic DHIS2 instance on AWS. -#Some variables. Change as needed. -USERNAME=dhis -PASSWORD=dhis -DBNAME=dhis2 -#Update first -sudo apt-get -y update -#Install postgres -sudo apt-get -y install postgresql-9.1 +#A basic script to stand-up a basic DHIS2 on Ubuntu. +#The name of the instance. Change as needed. +if [[ $# -lt 1 ]]; then + echo "Usage: $0 Username" + exit 1 +fi +USERNAME=$1 + +#Paramaters for specific install +DB_HOSTNAME="localhost" +DB_PORT="5432" +DUMP_FILE="/tmp/dhis.dump" +VERSION="2.9" +HTTP_PORT=8080 +TOMCAT_CONTROL_PORT=8005 +DBNAME=$USERNAME +BASE=/home/$USERNAME + + +while getopts ":dpfchc:" opt; do + case $opt in + d) DB_HOSTNAME=$OPTARG;; + p) DB_PORT=$OPTARG;; + f) DUMP_FILE=$OPTARG;; + v) VERSION=$OPTARG;; + h) HTTP_PORT=$OPTARG;; + c) TOMCAT_CONTROL_PORT=$OPTARG;; + \?) print >&2 "Usage: $0 [-d Database name] directory ..." + exit 1;; + esac +done +shift $(($OPTIND-1)) + +#USER STUFF #Set the username and password +#Add a user and create some necessary directories +sudo useradd -m -s '/bin/false' $USERNAME +sudo -u $USERNAME tomcat7-instance-create -p $HTTP_PORT -c $TOMCAT_CONTROL_PORT $BASE/tomcat +sudo -u $USERNAME mkdir $BASE/dhis_home +sudo -u $USERNAME sh -c "echo '@reboot $BASE/tomcat/bin/startup.sh' |crontab -u $USERNAME -" +# sudo -u $USERNAME sh -c "echo '03 03 * * * $BASE/backup.sh' |crontab -u $USERNAME -" +#Create a new postgres config and restart the server sudo -u postgres createuser -SDRw $USERNAME +PASSWORD=$(makepasswd) sudo -u postgres psql -c "ALTER USER $USERNAME WITH PASSWORD '$PASSWORD';" +#Create the database sudo -u postgres createdb -O $USERNAME $DBNAME -#Install Java and set as the default -sudo apt-get -y install openjdk-7-jdk -sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-7-openjdk-amd64/bin/java 1 -sudo update-alternatives --set java /usr/lib/jvm/java-7-openjdk-amd64/bin/java -#Download and install Tomcat -wget -O /home/ubuntu/apache-tomcat-7.0.30.tar.gz http://apache.osuosl.org/tomcat/tomcat-7/v7.0.30/bin/apache-tomcat-7.0.30.tar.gz -tar zxvf /home/ubuntu/apache-tomcat-7.0.30.tar.gz -#Download and install DHIS2 -wget -O /home/ubuntu/apache-tomcat-7.0.30/webapps/dhis.war http://dhis2.org/download/releases/2.9/dhis.war +#TODO +#sudo -u dhis psql -f $DUMP_FILE $DBNAME + +#Download and install DHIS2 +sudo sh -c "sudo -u $USERNAME wget -O $BASE/tomcat/webapps/$USERNAME.war http://dhis2.org/download/releases/$VERSION/dhis.war" #Create a hibernate.properties file -echo -e "hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect +sudo -u $USERNAME sh -c "echo 'hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect hibernate.connection.driver_class = org.postgresql.Driver -hibernate.connection.url = jdbc:postgresql://localhost/$DBNAME +hibernate.connection.url = jdbc:postgresql://DB_HOSTNAME:$DB_PORT/$DBNAME hibernate.connection.username = $USERNAME hibernate.connection.password = $PASSWORD -hibernate.hbm2ddl.auto = update" > /home/ubuntu/hibernate.properties +hibernate.hbm2ddl.auto = update' > $BASE/dhis_home/hibernate.properties" +sudo -u $USERNAME chmod 600 $BASE/dhis_home/hibernate.properties + + #Create the JAVA_OPTS -sudo echo -e "export JAVA_OPTS='-Xmx6000m -Xms3000m -XX:MaxPermSize=800m -XX:PermSize=400m' -export DHIS2_HOME='/home/ubuntu/'" > /home/ubuntu/apache-tomcat-7.0.30/bin/setenv.sh - - -#Make some changes to the kernel params -sudo sh -c "echo ' -kernel.shmmax = 1073741824 -net.core.rmem_max = 8388608 -net.core.wmem_max = 8388608' >> /etc/sysctl.conf" -sudo sysctl -p -#Backup the Postgguration file -sudo cp /etc/postgresql/9.1/main/postgresql.conf /etc/postgresql/9.1/main/postgresql.conf.bak -#Create a new postgres config and restart the server -echo -e "data_directory = '/var/lib/postgresql/9.1/main'\n -hba_file = '/etc/postgresql/9.1/main/pg_hba.conf'\n -ident_file = '/etc/postgresql/9.1/main/pg_ident.conf'\n -external_pid_file = '/var/run/postgresql/9.1-main.pid'\n -port = 5432\n -max_connections = 100\n -unix_socket_directory = '/var/run/postgresql'\n -ssl = true\n -shared_buffers = 512MB\n -log_line_prefix = '%t '\n -datestyle = 'iso, mdy'\n -lc_messages = 'en_US.UTF-8'\n -lc_monetary = 'en_US.UTF-8'\n -lc_numeric = 'en_US.UTF-8'\n -lc_time = 'en_US.UTF-8'\n -default_text_search_config = 'pg_catalog.english'\n -effective_cache_size = 3500MB\n -checkpoint_segments = 32\n -checkpoint_completion_target = 0.8\n -wal_buffers = 4MB\n -synchronous_commit = off\n -wal_writer_delay = 10000ms\n" > /home/ubuntu/postgres.conf -sudo cp /home/ubuntu/postgres.conf /etc/postgresql/9.1/main/postgresql.conf -#Restart postgres -sudo /etc/init.d/postgresql restart +#TODO calculate this based on the free memory +sudo sh -c "sudo -u $USERNAME echo -e \"export JAVA_OPTS='-Xmx1024m -Xms512m -XX:MaxPermSize=500m -XX:PermSize=400m' +export DHIS2_HOME='$BASE/dhis_home'\" > $BASE/tomcat/bin/setenv.sh" + #Start Tomcat -/home/ubuntu/apache-tomcat-7.0.30/bin/startup.sh -#Enjoy \ No newline at end of file +sudo -u $USERNAME $BASE/tomcat/bin/startup.sh ; +#ToDo Echo where the +echo "You have successfully installed DHIS2 and it is running at http://localhost:$HTTP_PORT/$USERNAME" === added file 'resources/util/dhis2_serveropt.sh' --- resources/util/dhis2_serveropt.sh 1970-01-01 00:00:00 +0000 +++ resources/util/dhis2_serveropt.sh 2012-10-01 14:08:57 +0000 @@ -0,0 +1,50 @@ +#!/bin/bash +#SERVER STUFF +#Update first +sudo apt-get -y update +sudo apt-get -y upgrade +#Upgrade system as an option +#Install postgres +sudo apt-get -y install postgresql tomcat7-user libtcnative-1 makepasswd + +#KERNEL STUFF +#Make some changes to the kernel params +#TODO This needs to be based on free memory. +sudo sh -c "echo ' +kernel.shmmax = 1073741824 +net.core.rmem_max = 8388608 +net.core.wmem_max = 8388608' >> /etc/sysctl.conf" +sudo sysctl -p + +#POSTGRES STUFF +#Backup the Postgres configuration file +sudo cp /etc/postgresql/9.1/main/postgresql.conf /etc/postgresql/9.1/main/postgresql.conf.bak + +#TODO This needs to be based on memory allocated to Postgres +sudo sh -c "sudo -u postgres echo -e \"data_directory = '/var/lib/postgresql/9.1/main'\n +hba_file = '/etc/postgresql/9.1/main/pg_hba.conf'\n +ident_file = '/etc/postgresql/9.1/main/pg_ident.conf'\n +external_pid_file = '/var/run/postgresql/9.1-main.pid'\n +port = 5432\n +max_connections = 100\n +unix_socket_directory = '/var/run/postgresql'\n +ssl = true\n +shared_buffers = 512MB\n +log_line_prefix = '%t '\n +datestyle = 'iso, mdy'\n +lc_messages = 'en_US.UTF-8'\n +lc_monetary = 'en_US.UTF-8'\n +lc_numeric = 'en_US.UTF-8'\n +lc_time = 'en_US.UTF-8'\n +default_text_search_config = 'pg_catalog.english'\n +effective_cache_size = 3500MB\n +checkpoint_segments = 32\n +checkpoint_completion_target = 0.8\n +wal_buffers = 4MB\n +synchronous_commit = off\n +wal_writer_delay = 10000ms\n\" > /etc/postgresql/9.1/main/postgresql.conf" + +#Restart postgres +sudo /etc/init.d/postgresql restart +sudo ufw status +echo "Please remember to configure your firewall!" \ No newline at end of file
_______________________________________________ Mailing list: https://launchpad.net/~dhis2-devs Post to : [email protected] Unsubscribe : https://launchpad.net/~dhis2-devs More help : https://help.launchpad.net/ListHelp

