Commit 5657ffd5 by e0d

initial commit of forum related roles

works from scratch on gce and better generalization

missed file

changing user for checkout task

reverting path change

fix typo

fully working on debian

working upstart

moving env from bashrc

removing unused template

adding template for ruby env setting

removing unused template

removing forum and ruby env from bashrc, general cleanup
parent b53aeee4
......@@ -2,3 +2,6 @@
*.pyc
.idea/
.vagrant
\#*\#
*~
.#*
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
\ No newline at end of file
- name: check for elasticsearch
command: test -f /var/tmp/elasticsearch-${elastic_search_version}.deb
ignore_errors: true
register: es_present
- name: download elasticsearch
get_url: url={{ elastic_search_url }} dest=/var/tmp/{{ elastic_search_file }}
when_failed: $es_present
tags:
- elasticsearch
- install
- name: install elasticsearch from local package
shell: executable=/bin/bash dpkg -i /var/tmp/elasticsearch-${elastic_search_version}.deb
when_failed: $es_present
tags:
- elasticsearch
- install
---
elastic_search_version: "0.90.2"
elastic_search_sha: "397227ce37f616734f39f6e93539c9eaa82bec9"
elastic_search_file: "elasticsearch-${elastic_search_version}.deb"
elastic_search_url: "https://download.elasticsearch.org/elasticsearch/elasticsearch/{{ elastic_search_file }}"
\ No newline at end of file
- name: forum | restart the forum service
service: name=cs_comments_service state=restarted
\ No newline at end of file
- name: forum | git checkout forum repo into {{forum_code_dir}}
git: dest={{forum_code_dir}} repo={{forum_source_repo}} version={{forum_version}}
sudo: yes
sudo_user: ${forum_user}
notify:
- forum | restart the forum service
tags:
- forum
- deploy
- name: forum | install comments service bundle
shell: executable=/bin/bash {{ rbenv_root }}/shims/bundle install chdir={{ forum_code_dir }}
sudo: yes
sudo_user: ${forum_user}
notify:
- forum | restart the forum service
tags:
- forum
- deploy
\ No newline at end of file
---
- name: forum | create $forum_user user
user: name=$forum_user state=present shell=/bin/bash home=$forum_home
tags:
- ruby
- update
- include: ../../rbenv/tasks/main.yml
- name: forum | setup the forum env
template: src=forum_env.j2 dest={{ ruby_base }}/forum_env owner={{ rbenv_user }} group={{ rbenv_user }}
tags:
- forum
- update
- name: rbenv | ensure .bashrc exists
shell: touch $ruby_base/.bashrc
sudo: true
sudo_user: $rbenv_user
tags:
- ruby
- update
- name: rebenv | add source of ruby_env to .bashrc
lineinfile:
dest=$ruby_base/.bashrc
regexp='. {{ruby_base}}/forum_env'
line='. {{ruby_base}}/forum_env'
- name: forum | copy cs_comments_service SysVunit script
template: src=cs_comments_service.j2 dest=/etc/init.d/cs_comments_service owner=root group=root mode=750
tags:
- forum
- install
only_if: "'${ansible_distribution}' == 'Debian'"
- name: forum | copy cs_comments_service upstart script
template: src=cs_comments_service.conf.j2 dest=/etc/init/cs_comments_service.conf owner=root group=root mode=750
tags:
- forum
- install
only_if: "'${ansible_distribution}' == 'Ubuntu'"
- include: deploy.yml
#!/bin/sh
### BEGIN INIT INFO
# Provides: seismic_web
# Required-Start: $local_fs $syslog
# Required-Stop: $local_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Gunicorn processes for seismic_web
### END INIT INFO
# www-data is the default www user on debian
USER=forums
NAME="cs_comments_service"
RETVAL=0
DAEMON=/opt/forum/.rbenv/shims/ruby
PID=/var/tmp/cs_comments_service.pid
OPTIONS="app.rb"
# source function library
. /lib/lsb/init-functions
start()
{
echo "Starting $NAME."
cd /opt/wwc/cs_comments_service
start-stop-daemon -b --start --pidfile $PID -m -c $USER --exec $DAEMON -- $OPTIONS
}
stop()
{
if [ -f $PID ]; then
echo "Stopping $NAME"
kill $(cat $PID)
fi
}
reload()
{
echo "Reloading $NAME:"
if [ -f $PID ]
then kill -HUP `cat $PID` && echo "OK" || echo "failed";
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
reload
;;
reload)
reload
;;
force-reload)
stop && start
;;
*)
echo "Usage: $0 {start|stop|restart}"
RETVAL=1
esac
exit $RETVAL
#!/bin/sh
### BEGIN INIT INFO
# Provides: seismic_web
# Required-Start: $local_fs $syslog
# Required-Stop: $local_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Gunicorn processes for seismic_web
### END INIT INFO
# www-data is the default www user on debian
USER=forums
NAME="cs_comments_service"
RETVAL=0
DAEMON=/opt/www/.rbenv/versions/1.9.3-p374/bin/ruby
PID=/var/tmp/cs_comments_service.pid
OPTIONS="app.rb"
# source function library
. /lib/lsb/init-functions
start()
{
echo "Starting $NAME."
cd /opt/wwc/cs_comments_service
start-stop-daemon -b --start --pidfile $PID -m -c $USER --exec $DAEMON -- $OPTIONS
}
stop()
{
if [ -f $PID ]; then
echo "Stopping $NAME"
kill $(cat $PID)
fi
}
reload()
{
echo "Reloading $NAME:"
if [ -f $PID ]
then kill -HUP `cat $PID` && echo "OK" || echo "failed";
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
reload
;;
reload)
reload
;;
force-reload)
stop && start
;;
*)
echo "Usage: $0 {start|stop|restart}"
RETVAL=1
esac
exit $RETVAL
description "Comments Service"
start on runlevel [2345]
stop on runlevel [!2345]
env PID=/var/tmp/comments_service.pid
chdir {{ forum_code_dir }}
exec {{rbenv_root}}/shims/ruby app.rb
\ No newline at end of file
#!/bin/sh
### BEGIN INIT INFO
# Provides: seismic_web
# Required-Start: $local_fs $syslog
# Required-Stop: $local_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Gunicorn processes for seismic_web
### END INIT INFO
# www-data is the default www user on debian
USER={{ forum_user }}
NAME="cs_comments_service"
RETVAL=0
APP_ROOT={{ forum_code_dir }}
DAEMON={{ rbenv_root }}/shims/ruby
PID=/var/tmp/cs_comments_service.pid
OPTIONS="app.rb"
# source function library
. /lib/lsb/init-functions
start()
{
echo "Starting $NAME."
start-stop-daemon -b --start --pidfile ${PID} -m -c ${USER} -d ${APP_ROOT}--exec ${DAEMON} -- ${OPTIONS}
}
stop()
{
if [ -f ${PID} ]; then
echo "Stopping $NAME"
kill $(cat ${PID})
fi
}
reload()
{
echo "Reloading $NAME:"
if [ -f ${PID} ]
then kill -HUP `cat ${PID}` && echo "OK" || echo "failed";
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
reload
;;
reload)
reload
;;
force-reload)
stop && start
;;
*)
echo "Usage: $0 {start|stop|restart}"
RETVAL=1
esac
exit $RETVAL
export MONGOHQ_USER=cs_comments_service
export MONGOHQ_PASS=password
export RACK_ENV=development
export SINATRA_ENV=development
export API_KEY=tX5Dslg1y3OsCpFzRq
export SEARCH_SERVER=http://localhost:9200
export MONGOHQ_URL=mongodb://cs_comments_service:password@localhost:27017/cs_comments_service
\ No newline at end of file
##
## Managed by Ansible, do not edit.
##
## This file is sourced in .bashrc.
## The environment variables are used by the cs_comments_service
## to configure itself at start-time.
##
export MONGOHQ_USER=cs_comments_service
export MONGOHQ_PASS=password
export RACK_ENV=development
export SINATRA_ENV=development
export API_KEY=tX5Dslg1y3OsCpFzRq
export SEARCH_SERVER=http://localhost:9200
export MONGOHQ_URL=mongodb://cs_comments_service:password@localhost:27017/cs_comments_service
\ No newline at end of file
export JAVA_HOME="{{ java_home }}"
export PATH=$JAVA_HOME/bin:$PATH
\ No newline at end of file
---
forum_user: "forum"
forum_home: "/opt/forum"
rbenv_root: "{{ forum_home }}/.rbenv"
rbenv_user: "forum"
ruby_version: "1.9.3-p448"
ruby_base: "/opt/forum"
gem_home: "{{ ruby_base }}/.gem"
forum_code_dir: "{{ forum_home }}/cs_comments_service"
forum_source_repo: https://github.com/edx/cs_comments_service.git
forum_version: 'HEAD'
\ No newline at end of file
---
- name: install python-pymongo (req for ansible)
pip: name=pymongo
- name: install mongo server and recommends
apt: pkg=mongodb-server state=present install_recommends=yes
- name: stop mongo service
service: name=mongodb state=stopped
- name: move mongodb to /mnt
command: mv /var/lib/mongodb /mnt/. creates=/mnt/mongodb
- name: create mongodb symlink
file: src=/mnt/mongodb dest=/var/lib/mongodb state=link
- name: start mongo service
service: name=mongodb state=started
- name: wait for mongo server to start
wait_for: port=27017 delay=2
- name: create a mongodb user
mongodb_user: >
database=cs_comments_service
name=cs_comments_service
password=password
state=present
\ No newline at end of file
- name: oraclejdk | check for Oracle Java version {{ java_base }}
command: test -d /usr/lib/jvm/{{ java_base }}
ignore_errors: true
register: java_present
- name: oraclejdk | download Oracle Java
shell: executable=/bin/bash curl -b gpw_e24=http%3A%2F%2Fwww.oracle.com -O -L {{ java_url }} chdir=/var/tmp
when_failed: $java_present
- name: oraclejdk | install Oracle Java
shell: exectuable=/bin/bash mkdir -p /usr/lib/jvm && tar -C /usr/lib/jvm -zxvf /var/tmp/{{ java_file }}
sudo: true
when_failed: $java_present
tags:
- forum
- install
#
# TODO: relocate, maybe?
#
- name: oraclejdk | create symlink expected by elasticsearch
file: src=/usr/lib/jvm/{{ java_base }} dest={{ java_link }} state=link
when_failed: $java_present
tags:
- forum
- install
- name: oraclejdk | add JAVA_HOME for Oracle Java
template: src=java.sh.j2 dest=/etc/profile.d/java.sh owner=root group=root mode=0755
when_failed: $java_present
tags:
- forum
- update
export JAVA_HOME="{{ java_link }}"
export PATH=$JAVA_HOME/bin:$PATH
---
java_version: "7u25"
# what the archive unpacks to
java_base: "jdk1.7.0_25"
java_build: "b15"
java_platform: "linux"
java_arch: "x64"
java_file: "jdk-{{ java_version }}-{{ java_platform }}-{{ java_arch }}.tar.gz"
java_url: "http://download.oracle.com/otn-pub/java/jdk/{{ java_version }}-{{ java_build }}/{{ java_file }}"
java_link: "/usr/lib/jvm/java-7-oracle"
#
# cribbed from https://github.com/mmoya/ansible-playbooks/blob/master/rbenv/main.yml
# with a number of changes.
#
- name: Create ruby base
file: path=$ruby_base state=directory owner=$rbenv_user group=$rbenv_user
tags:
- ruby
- update
- name: rbenv | install build depends
apt: pkg=$item state=present install_recommends=no
with_items:
- build-essential
- git
- libcurl4-openssl-dev
- libmysqlclient-dev
- libreadline-dev
- libssl-dev
- libxml2-dev
- libxslt1-dev
- zlib1g-dev
tags:
- ruby
- install
- name: rbenv | update rbenv repo
git: repo=https://github.com/sstephenson/rbenv.git dest=$rbenv_root version=v0.4.0
sudo: true
sudo_user: $rbenv_user
tags:
- ruby
- install
- name: rbenv | ensure .bashrc exists
shell: touch $ruby_base/.bashrc
sudo: true
sudo_user: $rbenv_user
tags:
- ruby
- update
- name: rbenv | drop a bash_profile
copy: src=../../common/files/bash_profile dest=$ruby_base/.bash_profile owner=$rbenv_user group=$rbenv_user
- name: rbenv | ensure ruby_env exists
template: src=ruby_env.j2 dest={{ ruby_base }}/ruby_env owner={{ rbenv_user }} group={{ rbenv_user }}
tags:
- ruby
- update
- name: rebenv | add source of ruby_env to .bashrc
lineinfile:
dest=$ruby_base/.bashrc
regexp='. {{ruby_base}}/ruby_env'
line='. {{ruby_base}}/ruby_env'
- name: rbenv | drop a bash_profile
copy: src=../../common/files/bash_profile dest=$ruby_base/.bash_profile owner=$rbenv_user group=$rbenv_user
- name: rbenv | check ruby-build installed
command: test -x /usr/local/bin/ruby-build
register: rbuild_present
ignore_errors: yes
tags:
- ruby
- install
- name: rbenv | create temporary directory
command: mktemp -d
register: tempdir
sudo: true
sudo_user: $rbenv_user
when_failed: $rbuild_present
tags:
- ruby
- install
- name: rbenv | clone ruby-build repo
git: repo=https://github.com/sstephenson/ruby-build.git dest=${tempdir.stdout}/ruby-build
when_failed: $rbuild_present
sudo: true
sudo_user: $rbenv_user
tags:
- ruby
- install
- name: rbenv | install ruby-build
command: ./install.sh chdir=${tempdir.stdout}/ruby-build
when_failed: $rbuild_present
tags:
- ruby
- install
- name: rbenv | remove temporary directory
file: path=${tempdir.stdout} state=absent
when_failed: $rbuild_present
tags:
- ruby
- install
- name: rbenv | check ruby $ruby_version installed
shell: RBENV_ROOT=${rbenv_root} ${rbenv_root}/bin/rbenv versions | grep $ruby_version
register: ruby_installed
sudo: true
sudo_user: $rbenv_user
ignore_errors: yes
tags:
- ruby
- install
- name: rbenv | install ruby $ruby_version
shell: RBENV_ROOT=${rbenv_root} ${rbenv_root}/bin/rbenv install $ruby_version
when_failed: $ruby_installed
sudo: true
sudo_user: $rbenv_user
tags:
- ruby
- install
- name: rbenv | set global ruby $ruby_version
shell: RBENV_ROOT=${rbenv_root} ${rbenv_root}/bin/rbenv global $ruby_version
sudo: true
sudo_user: $rbenv_user
when_failed: $ruby_installed
tags:
- ruby
- install
- name: rbenv | install bundler
shell: RBENV_ROOT=${rbenv_root} ${rbenv_root}/shims/gem install bundler -v 1.3.2
sudo: true
sudo_user: $rbenv_user
tags:
- ruby
- install
- name: rbenv | rehash
shell: RBENV_ROOT=${rbenv_root} ${rbenv_root}/bin/rbenv rehash
sudo: true
sudo_user: $rbenv_user
when_failed: $ruby_installed
tags:
- ruby
- install
\ No newline at end of file
##
## Managed by Ansible, do not edit.
##
export RBENV_ROOT="{{ rbenv_root }}"
export PATH=$RBENV_ROOT/bin/:$PATH
eval "$(rbenv init -)"
---
#forum_user: forum
# Ruby Specific Vars
#ruby_base: /opt/forum
#rbenv_root: "{{ ruby_base }}/.rbenv"
#ruby_version: "1.9.3-p448"
#gem_home: "{{ ruby_base }}/.gem"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment