=== modified file 'resources/util/dhis2_create_ubuntu_instance.sh' --- resources/util/dhis2_create_ubuntu_instance.sh 2012-10-01 17:07:38 +0000 +++ resources/util/dhis2_create_ubuntu_instance.sh 2012-12-27 07:54:41 +0000 @@ -8,11 +8,17 @@ USERNAME=$1 #Paramaters for specific install +#Name of the database DB_HOSTNAME="localhost" +#Database port DB_PORT="5432" +#Path to a database dump in custom format DUMP_FILE="/tmp/dhis.dump" -VERSION="2.9" +#Desired DHIS2 version +VERSION="2.10" +#Desired Tomcat HTTP port HTTP_PORT=8080 +#Desired Tomcat control port TOMCAT_CONTROL_PORT=8005 DBNAME=$USERNAME BASE=/home/$USERNAME @@ -41,13 +47,13 @@ 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';" +sudo -u postgres psql -c "CREATE ROLE $USERNAME PASSWORD '$PASSWORD' NOSUPERUSER CREATEDB NOCREATEROLE INHERIT LOGIN;" #Create the database -sudo -u postgres createdb -O $USERNAME $DBNAME -#TODO -#sudo -u dhis psql -f $DUMP_FILE $DBNAME +sudo -u postgres psql -c "CREATE DATABASE $DBNAME OWNER $USERNAME ENCODING 'UTF-8' TEMPLATE template0;" +sudo -u postgres psql -c "GRANT ALL ON DATABASE $DBNAME TO $USERNAME;" +#Uncomment this if you want to restore from a custom dump +#sudo -u $USERNAME pg_restore --format=custom --ignore-version --no-owner --no-privileges --verbose -U $USERNAME -d $DBNAME $DUMP_FILE #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" === modified file 'resources/util/dhis2_serveropt.sh' --- resources/util/dhis2_serveropt.sh 2012-10-02 10:13:17 +0000 +++ resources/util/dhis2_serveropt.sh 2012-12-27 07:54:41 +0000 @@ -1,11 +1,24 @@ #!/bin/bash +#These two variables must be modified to suit your purposes +if [[ $# -lt 1 ]]; then + echo "Usage: $0 Username" + exit 1 +fi +USERNAME=$1 +#TODO paramaterize this +PG_VERSION="9.2" +VHOST="foo.com" #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 bc ufw +#Installs Postgres 9.2 from a custom repository. Adjust as needed +sudo apt-get -u python-software-properties +sudo add-apt-repository -y ppa:pitti/postgresql +sudo apt-get -y update +sudo apt-get -y install postgresql-$PG_VERSION tomcat7-user libtcnative-1 nginx makepasswd bc ufw #KERNEL STUFF #Make some changes to the kernel params @@ -14,6 +27,7 @@ MEMFREE=$(grep MemFree /proc/meminfo | awk '{print $2}') SHMAX=$(bc -l <<< "scale = 0;($MEMTOTAL*1024/12)") RMEM_MAX=$(bc -l <<< "scale = 0;$SHMAX/128") +PG_VERSION=$(sudo -u postgres psql -t -c "SELECT substring(version() from '[8-9]\.[0-9]');" | sed 's/^\s//g') sudo sh -c "echo ' @@ -22,20 +36,20 @@ net.core.wmem_max = $RMEM_MAX' >> /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 +sudo cp /etc/postgresql/$PG_VERSION/main/postgresql.conf /etc/postgresql/$PG_VERSION/main/postgresql.conf.bak #Basic Postgres Optimization #TODO.Need to ask for user input here whether they really want to do this. -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 +sudo sh -c "sudo -u postgres echo -e \"data_directory = '/var/lib/postgresql/$PG_VERSION/main'\n +hba_file = '/etc/postgresql/$PG_VERSION/main/pg_hba.conf'\n +ident_file = '/etc/postgresql/$PG_VERSION/main/pg_ident.conf'\n +external_pid_file = '/var/run/postgresql/$PG_VERSION-main.pid'\n port = 5432\n max_connections = 100\n unix_socket_directory = '/var/run/postgresql'\n -ssl = true\n +ssl = false\n shared_buffers = $(bc -l <<< "scale = 0;($MEMTOTAL/24576)")MB\n log_line_prefix = '%t '\n datestyle = 'iso, mdy'\n @@ -49,9 +63,73 @@ 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" +wal_writer_delay = 10000ms\n\" > /etc/postgresql/$PG_VERSION/main/postgresql.conf" +#Nginx configuration +sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.bak +#Main ngnix config +sudo sh -c "sudo -u root echo -e \"user www-data; +worker_processes 4; +error_log /var/log/nginx/error.log; +pid /var/run/nginx.pid; +events { + worker_connections 1024; + use epoll; + } + + http { + include /etc/nginx/mime.types; + access_log /var/log/nginx/access.log; + sendfile on; + keepalive_timeout 65; + tcp_nodelay on; + server_names_hash_bucket_size 64; + gzip on; + gzip_comp_level 1; + gzip_disable msie6; + gzip_proxied any; + gzip_types text/plain text/css application/x-javascript text/xml application/xml application/rss+xml text/javascript; + proxy_cache_path /var/cache/nginx keys_zone=dhis:250m inactive=1d; + proxy_redirect off; + # Cache different return codes for different lengths of time + proxy_cache_valid 200 302 6h; + proxy_cache_valid 404 1m; + include /etc/nginx/conf.d/*.conf; + include /etc/nginx/sites-enabled/*; + }\n\" > /etc/nginx/nginx.conf" + +sudo sh -c "sudo -u root echo -e \"server { +listen *:80; +server_name _; +client_max_body_size 15M; +client_body_buffer_size 128k; +access_log /var/log/nginx/$USERNAME.access.log; +location / { + root /var/www/nginx-default; + index index.html index.htm; + } + # Serve static content + location ~ ^/$USERNAME/.*(\.js$|\.css$|\.gif$|\.woff$|\.ttf$|\.eot$|\.html$|images/|icons/|dhis-web-commons/.*\.png$) { + root /home/$USERNAME/tomcat/webapps/; + add_header Cache-Control public; + expires 7d; + } + +location /dhis/ { + proxy_pass http://localhost:8080/dhis/; + proxy_redirect off; + proxy_set_header Host \044http_host; + proxy_set_header X-Real-IP \044remote_addr; + proxy_set_header X-Forwarded-For \044proxy_add_x_forwarded_for; + proxy_cache $USERNAME; + expires +24h; + } +rewrite ^/$ /$USERNAME/ permanent; +}\" > /etc/nginx/sites-available/$USERNAME" +sudo /etc/init.d/nginx restart #Restart postgres -sudo /etc/init.d/postgresql restart -sudo ufw status +sudo /etc/init.d/postgresql restart $PG_VERSION +sudo -u $USERNAME /home/$USERNAME/tomcat/bin/shutdown.sh +sudo -u $USERNAME /home/$USERNAME/tomcat/bin/startup.sh + echo "Please remember to configure your firewall!" \ No newline at end of file