Permalink
Browse files

adding ami initialization script

Signed-off-by: Jim Klo <jim.klo@sri.com>
  • Loading branch information...
jimklo committed Jul 18, 2011
1 parent 21f5a0a commit 6b89fbe166fd40fd3d4029b74cd023b6e36f67f9
View
@@ -0,0 +1,94 @@
+#!/bin/bash
+
+LR_COUCHDB_DIR=/mnt/couchdb/1.0.2
+LR_COUCHDB_VIEW_DIR=/mnt/couchdb/1.0.2
+
+LR_COUCHDB_DATA_DIR=/mnt/couchdb
+LR_COUCHDB_OWNER=couchbase
+LR_COUCHDB_GROUP=couchbase
+
+LR_NGINX_CONF=/etc/nginx/sites-available/learningregistry
+
+LR_HOME=/home/learningregistry
+LR_ROOT=$LR_HOME/gitrepos/LearningRegistry
+LR_ENV=$LR_HOME/virtualenv/lr
+
+function create_couch_data_dir () {
+ local d=$1
+ if [ ! -e $d ]
+ then
+ sudo mkdir -p $d
+ sudo chown $LR_COUCHDB_OWNER:$LR_COUCHDB_GROUP $d
+ sudo chmod 0770 $d
+ fi
+}
+
+echo
+echo "========================================================================="
+echo "Stopping Learning Registry, CouchDB, NGINX"
+echo "========================================================================="
+echo
+sudo service learningregistry stop
+sudo service couchbase-server stop
+sudo service nginx stop
+
+
+echo
+echo "========================================================================="
+echo "Deleting existing log files"
+echo "========================================================================="
+echo
+sudo rm -f /var/log/learningregistry/*
+sudo rm -f /var/log/nginx/*
+sudo rm -f /opt/couchbase-server/var/log/couchdb/*
+
+echo
+echo "========================================================================="
+echo "Creating CouchDB data directories"
+echo "========================================================================="
+echo
+create_couch_data_dir $LR_COUCHDB_DIR
+create_couch_data_dir $LR_COUCHDB_VIEW_DIR
+
+sudo chown $LR_COUCHDB_OWNER:$LR_COUCHDB_GROUP $LR_COUCHDB_DIR
+
+
+echo
+echo "========================================================================="
+echo "FIXUP NGINX configuration"
+echo "========================================================================="
+echo
+
+HOSTNAME=`hostname`
+INT_DNS=`ping -c 1 $HOSTNAME | awk '/^PING/ {print $2}'`
+
+cat $LR_NGINX_CONF | awk '{sub(/listen +[^:]+:5984/, "'"listen ${INT_DNS}:5984"'"); print}' > /tmp/learningregistry.nginx
+sudo cp -f $LR_NGINX_CONF $LR_NGINX_CONF.bak
+sudo cp -f /tmp/learningregistry.nginx $LR_NGINX_CONF
+sudo chmod 0644 $LR_NGINX_CONF
+
+echo
+echo "========================================================================="
+echo "Start NGINX CouchDB"
+echo "========================================================================="
+echo
+
+sudo service nginx start
+sudo service couchbase-server start
+
+
+echo
+echo "========================================================================="
+echo "Run LR Node Configuration"
+echo "========================================================================="
+echo
+
+sudo su $LR_USER -c "cd $LR_ROOT/config; source $LR_ENV/bin/activate; $LR_ENV/bin/python ./setup_node.py -d"
+
+echo
+echo "========================================================================="
+echo "Start Learning Registry"
+echo "========================================================================="
+echo
+
+sudo service learningregistry start
@@ -0,0 +1,78 @@
+#! /bin/bash
+# /etc/init.d/learningregistry
+#
+
+LR_HOME=/home/learningregistry/gitrepos/LearningRegistry/LR
+LR_USER=learningregistry
+LR_GRP=learningregistry
+LR_VIRTUALENV=/home/learningregistry/virtualenv/lr
+LR_PID_DIR=/var/run/learningregistry
+LR_LOG_DIR=/var/log/learningregistry
+
+LR_PID=$LR_PID_DIR/paster.pid
+LR_LOG=$LR_LOG_DIR/paster.log
+
+# Some things that run always
+if [ ! -e $LR_PID_DIR ]
+then
+ mkdir -p $LR_PID_DIR
+ chown $LR_USER:$LR_GRP $LR_PID_DIR
+fi
+
+if [ ! -e $LR_LOG_DIR ]
+then
+ mkdir -p $LR_LOG_DIR
+ chown $LR_USER:$LR_GRP $LR_LOG_DIR
+fi
+
+lr_start () {
+ if [ -e $LR_PID ]
+ then
+ echo "LR Node is already running"
+ exit 1
+ fi
+
+ su $LR_USER -c "$LR_VIRTUALENV/bin/paster serve --daemon $LR_HOME/development.ini start --pid-file=$LR_PID --log-file=$LR_LOG"
+ echo "LR Node is starting. Log: $LR_LOG PID: $LR_PID"
+}
+
+lr_stop () {
+ if [ -e $LR_PID ]
+ then
+ su $LR_USER -c "$LR_VIRTUALENV/bin/paster serve --daemon $LR_HOME/development.ini stop --pid-file=$LR_PID --log-file=$LR_LOG"
+ echo "LR Node is stopping. Log: $LR_LOG PID: $LR_PID"
+ fi
+
+}
+
+lr_restart () {
+ if [ -e $LR_PID ]
+ then
+ su $LR_USER -c "$LR_VIRTUALENV/bin/paster serve --daemon $LR_HOME/development.ini restart --pid-file=$LR_PID --log-file=$LR_LOG"
+ echo "LR Node is restarting. Log: $LR_LOG PID: $LR_PID"
+ fi
+
+}
+
+
+# Carry out specific functions when asked to by the system
+case "$1" in
+ start)
+ echo "Starting script learningregistry "
+ lr_start
+ ;;
+ stop)
+ echo "Stopping script learningregistry"
+ lr_stop
+ ;;
+ restart)
+ echo "Restarting script learningregistry"
+ lr_restart
+ ;;
+ *)
+ echo "Usage: $0 {start|stop|restart}"
+ exit 1
+ ;;
+esac
+
+exit 0
@@ -0,0 +1,15 @@
+/var/log/learningregistry/paster.log {
+ daily
+ missingok
+ rotate 31
+ compress
+ delaycompress
+ notifempty
+ create 640 learningregistry learningregistry
+ sharedscripts
+ postrotate
+ if [ -f /var/run/learningregistry/paster.pid]; then
+ /etc/init.d/learningregistry restart > /dev/null
+ fi
+ endscript
+}
View
@@ -0,0 +1,52 @@
+user www-data;
+worker_processes 2;
+
+error_log /var/log/nginx/error.log;
+pid /var/run/nginx.pid;
+
+events {
+ worker_connections 1024;
+ use epoll;
+ # multi_accept on;
+}
+
+http {
+ include /etc/nginx/mime.types;
+ default_type application/octet-stream;
+
+ access_log /var/log/nginx/access.log;
+
+ sendfile on;
+ #tcp_nopush on;
+
+ #keepalive_timeout 0;
+ keepalive_timeout 65;
+ tcp_nodelay on;
+
+ gzip on;
+ gzip_disable "MSIE [1-6]\.(?!.*SV1)";
+
+ include /etc/nginx/conf.d/*.conf;
+ include /etc/nginx/sites-enabled/*;
+}
+
+# mail {
+# # See sample authentication script at:
+# # http://wiki.nginx.org/NginxImapAuthenticateWithApachePhpScript
+#
+# # auth_http localhost/auth.php;
+# # pop3_capabilities "TOP" "USER";
+# # imap_capabilities "IMAP4rev1" "UIDPLUS";
+#
+# server {
+# listen localhost:110;
+# protocol pop3;
+# proxy on;
+# }
+#
+# server {
+# listen localhost:143;
+# protocol imap;
+# proxy on;
+# }
+# }
Oops, something went wrong.

0 comments on commit 6b89fbe

Please sign in to comment.