diff --git a/defaults/main.yml b/defaults/main.yml index b3ff59f..81230ee 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -3,8 +3,8 @@ # Install 1 or more versions of ruby # The last ruby listed will be set as the default ruby rvm1_rubies: - - 'ruby-2.1.0' - - 'ruby-2.3.1' + - '2.1.0' + - '2.3.1' # Install bundler rvm1_bundler_install: True @@ -45,7 +45,7 @@ rvm1_gpg_keys: '409B6B1796C275462A1703113804BB82D39DC0E3' rvm1_gpg_key_server: 'hkp://keys.gnupg.net' # autolib mode, see https://rvm.io/rvm/autolibs -rvm1_autolib_mode: 3 +rvm1_autolib_mode: read-only # Name of UID 0 user root_user: 'root' @@ -60,4 +60,26 @@ ruby_req_packages: - curl - gzip - bzip2 - - default-libmysqlclient-dev \ No newline at end of file + - default-libmysqlclient-dev + - gawk + - g++ + - gcc + - libc6-dev + - libreadline6-dev + - zlib1g-dev + - libyaml-dev + - libsqlite3-dev + - sqlite3 + - autoconf + - libgmp-dev + - libgdbm-dev + - libmagickwand-dev + - imagemagick + - libncurses5-dev + - bison + - libffi-dev + - libssl1.0-dev +ruby_sites: [] + + +#- libssl-dev diff --git a/defaults/rubysite.yml b/defaults/rubysite.yml index 7635fcc..8b13789 100644 --- a/defaults/rubysite.yml +++ b/defaults/rubysite.yml @@ -1,15 +1 @@ -ruby_sites: - - name: "Seite 1" - become_user: "ruby" - git: - repo: "/mnt/intern" - dest: "/srv/intern/intern" - - name: "Fetsite" - become_user: "ruby" - git: - repo: "/mnt/fetsite" - dest: "/srv/fetsite/fetsite" - ruby_init: true - -# repo: "https://github.com/kbroman/simple_site" \ No newline at end of file diff --git a/tasks/fetsite.yml b/tasks/fetsite.yml new file mode 100644 index 0000000..744e753 --- /dev/null +++ b/tasks/fetsite.yml @@ -0,0 +1,6 @@ +--- + + + + + diff --git a/tasks/main.yml b/tasks/main.yml index f2738aa..722c7f2 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -18,6 +18,12 @@ - name: Install RVM include: 'rvm.yml' become: yes + become_user: "{{ rvm1_user }}" + +- name: Install ruby requirements + command: '{{ rvm1_rvm }} requirements' + changed_when: False + when: rvm1_rubies - name: Install Ruby and Gems @@ -25,7 +31,47 @@ become: yes become_user: "{{ rvm1_user }}" -- name: "deploying ruby sites" - include_tasks: site.yml + + +- name: "create directory for {{item.name}}" + file: + path: "{{item.dest}}" + state: directory + owner: "{{ rvm1_user }}" + group: "{{ rvm1_user }}" with_items: "{{ruby_sites}}" - \ No newline at end of file + + +- name: Template for InitScript + template: + src: ruby_fetsite.j2 + dest: "{{site.dest}}/../{{site.script}}" + owner: "{{ rvm1_user }}" + group: "{{ rvm1_user }}" + mode: "u=rwx,g=rwx,o=r" + when: not(site.script is undefined) + with_items: "{{ruby_sites}}" + loop_control: + loop_var: site + + +- name: Deploying sites + include: site.yml + become: yes + become_user: "{{ rvm1_user }}" + with_items: "{{ruby_sites}}" + loop_control: + loop_var: site + + + + + + + + + + + + + diff --git a/tasks/rubies.yml b/tasks/rubies.yml index 212dc22..b9fb331 100644 --- a/tasks/rubies.yml +++ b/tasks/rubies.yml @@ -8,6 +8,7 @@ with_items: '{{ rvm1_rubies }}' when: rvm1_rubies + - name: Install rubies command: '{{ rvm1_rvm }} install {{ item.item }} {{ rvm1_ruby_install_flags }}' when: rvm1_rubies and item.rc|default(0) != 0 diff --git a/tasks/site.yml b/tasks/site.yml index ef3f298..21ebce9 100644 --- a/tasks/site.yml +++ b/tasks/site.yml @@ -1,66 +1,45 @@ +# Deploy a ruby site +# item: +# name: Seite +# git: +# repo: https://git_repository +# dest: destination on server --- + - debug: - msg: "Seite: {{item.name}}" + msg: "deploy ruby site: {{site.name}}" -- command: whoami - register: whoami +- command: echo "$PATH" + register: out changed_when: false +- debug: msg="{{ out.stdout }}" -- debug: msg="{{ whoami.stdout }}" - - -- name: "DIR" - file: - path: "{{item.git.dest}}" - state: directory - owner: "ruby" - group: "ruby" - - -- name: Clone GIT - become_user: "ruby" +- name: "cloning git repository from {{site.git.repo}}" git: - repo: "{{item.git.repo}}" - dest: "{{item.git.dest}}" + repo: "{{site.git.repo}}" + dest: "{{site.dest}}" + - name: ruby init command: 'echo "$PATH"' - become_user: "ruby" + changed_when: false args: - chdir: "{{item.git.dest}}" + chdir: "{{site.dest}}" + environment: + PATH: "{{ rvm1_install_path }}/wrappers/default:{{ ansible_env.PATH }}" register: out + +- name: run_initscript + command: '../{{site.script}}' + args: + chdir: "{{site.dest}}" + register: out + environment: + PATH: "{{ rvm1_install_path }}/bin:{{ rvm1_install_path }}/wrappers/ruby-{{site.ruby}}@{{site.gemset}}:{{ ansible_env.PATH }}" + - debug: msg="{{ out.stdout_lines }}" -- name: ls - command: ls . - become_user: "ruby" - args: - chdir: "{{item.git.dest}}" - register: out - -- debug: msg="{{ out.stdout_lines }}" - -- shell: ./initscript.sh - become_user: "ruby" - args: - chdir: "{{item.git.dest}}" - register: output - when: not(item.ruby_init is undefined) and item.ruby_init - -- debug: - msg:"{{output}}" - -- name: ruby init - command: 'echo initscript.sh | /bin/bash --login' - become_user: "ruby" - args: - chdir: "{{item.git.dest}}" - register: output - when: not(item.ruby_init is undefined) and item.ruby_init - - - -- debug: - msg:"{{output}}" \ No newline at end of file +- include_tasks: fetsite.yml + when: not(site.ruby_init is undefined) and site.ruby_init diff --git a/templates/fetsite/etherpad-lite.j2 b/templates/fetsite/etherpad-lite.j2 new file mode 100755 index 0000000..10805ac --- /dev/null +++ b/templates/fetsite/etherpad-lite.j2 @@ -0,0 +1,78 @@ +#!/bin/sh +### BEGIN INIT INFO +# Provides: etherpad-lite +# Required-Start: $local_fs $remote_fs $network $syslog +# Required-Stop: $local_fs $remote_fs $network $syslog +# Default-Start: 2 3 4 5 +# Default-Stop: 0 1 6 +# Short-Description: starts etherpad lite +# Description: starts etherpad lite using start-stop-daemon +### END INIT INFO + +PATH="/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/opt/node/bin" +LOGFILE="/var/log/etherpad-lite/etherpad-lite.log" +EPLITE_DIR="/opt/etherpad/etherpad-lite" +EPLITE_BIN="bin/run.sh" +USER="fetsite" +GROUP="fetsite" +DESC="Etherpad Lite" +NAME="etherpad-lite" + +set -e + +. /lib/lsb/init-functions + +start() { + echo "Starting $DESC... " + + start-stop-daemon --start --chuid "$USER:$GROUP" --background --make-pidfile --pidfile /var/run/$NAME.pid --exec $EPLITE_DIR/$EPLITE_BIN -- $LOGFILE || true + echo "done" +} + +#We need this function to ensure the whole process tree will be killed +killtree() { + local _pid=$1 + local _sig=${2-TERM} + for _child in $(ps -o pid --no-headers --ppid ${_pid}); do + killtree ${_child} ${_sig} + done + kill -${_sig} ${_pid} +} + +stop() { + echo "Stopping $DESC... " + if test -f /var/run/$NAME.pid; then + while test -d /proc/$(cat /var/run/$NAME.pid); do + killtree $(cat /var/run/$NAME.pid) 15 + sleep 0.5 + done + rm /var/run/$NAME.pid + fi + echo "done" +} + +status() { + status_of_proc -p /var/run/$NAME.pid "" "etherpad-lite" && exit 0 || exit $? +} + +case "$1" in + start) + start + ;; + stop) + stop + ;; + restart) + stop + start + ;; + status) + status + ;; + *) + echo "Usage: $NAME {start|stop|restart|status}" >&2 + exit 1 + ;; +esac + +exit 0 diff --git a/templates/fetsite/unicorn.j2 b/templates/fetsite/unicorn.j2 new file mode 100755 index 0000000..880d319 --- /dev/null +++ b/templates/fetsite/unicorn.j2 @@ -0,0 +1,119 @@ +#!/bin/sh +# +# init.d script for single or multiple unicorn installations. Expects at least one .conf +# file in /etc/unicorn +# +# Modified by jay@gooby.org http://github.com/jaygooby +# based on http://gist.github.com/308216 by http://github.com/mguterl +# +## A sample /etc/unicorn/my_app.conf +## +## RAILS_ENV=production +## RAILS_ROOT=/var/apps/www/my_app/current +# +# This configures a unicorn master for your app at /var/apps/www/my_app/current running in +# production mode. It will read config/unicorn.rb for further set up. +# +# You should ensure different ports or sockets are set in each config/unicorn.rb if +# you are running more than one master concurrently. +# +# If you call this script without any config parameters, it will attempt to run the +# init command for all your unicorn configurations listed in /etc/unicorn/*.conf +# +# /etc/init.d/unicorn start # starts all unicorns +# +# If you specify a particular config, it will only operate on that one +# +# /etc/init.d/unicorn start /etc/unicorn/my_app.conf + +set -e + +sig () { + test -s "$PID" && kill -$1 `cat "$PID"` +} + +oldsig () { + test -s "$OLD_PID" && kill -$1 `cat "$OLD_PID"` +} + +cmd () { + + case $1 in + start) + sig 0 && echo >&2 "Already running" && exit 0 + echo "Starting" + $CMD + ;; + stop) + sig QUIT && echo "Stopping" && exit 0 + echo >&2 "Not running" + ;; + force-stop) + sig TERM && echo "Forcing a stop" && exit 0 + echo >&2 "Not running" + ;; + restart) + sig USR2 && echo "Starting new process" && sleep 5 && oldsig QUIT && echo "Killing old master" `cat $OLD_PID` && exit 0 + echo >&2 "Couldn't reload, starting '$CMD' instead" + $CMD + ;; + reload) + sig HUP && echo "Reloading Config" && exit 0 + echo >&2 "Couldn't reload, starting '$CMD' instead" + $CMD + ;; + upgrade) + sig USR2 && echo Upgraded && exit 0 + echo >&2 "Couldn't upgrade, starting '$CMD' instead" + $CMD + ;; + rotate) + sig USR1 && echo rotated logs OK && exit 0 + echo >&2 "Couldn't rotate logs" && exit 1 + ;; + *) + echo >&2 "Usage: $0 " + exit 1 + ;; + esac +} + +setup () { + + echo -n "$RAILS_ROOT: " + cd $RAILS_ROOT || exit 1 + export PID=$RAILS_ROOT/tmp/pids/unicorn.pid + export OLD_PID="$PID.oldbin" + export HOME=$RAILS_ROOT + export RAILS_ENV=$RAILS_ENV + CMD="{{ rvm1_install_path }}/wrappers/{{site.ruby}}@{{site.gemset}}/unicorn_rails -c config/unicorn.rb -E $RAILS_ENV -D" + CMD="{{ rvm1_install_path }}/wrappers/{{site.ruby}}@{{site.gemset}}/bundle exec unicorn_rails -c config/unicorn.rb -E $RAILS_ENV -D" + + +} + +start_stop () { + + # either run the start/stop/reload/etc command for every config under /etc/unicorn + # or just do it for a specific one + + # $1 contains the start/stop/etc command + # $2 if it exists, should be the specific config we want to act on + if [ $2 ]; then + . $2 + setup + cmd $1 + else + for CONFIG in /etc/unicorn/*.conf; do + # import the variables + . $CONFIG + setup + + # run the start/stop/etc command + cmd $1 + done + fi +} + +ARGS="$1 $2" +start_stop $ARGS diff --git a/templates/ruby_fetsite.j2 b/templates/ruby_fetsite.j2 new file mode 100644 index 0000000..3672275 --- /dev/null +++ b/templates/ruby_fetsite.j2 @@ -0,0 +1,14 @@ +#!/bin/bash +echo "sdf" +echo "{{site}}" +source ~/.rvm/scripts/rvm +source $({{rvm1_rvm}} {{site.ruby}} do rvm gemset create {{site.gemset}}) + +source $({{rvm1_rvm}} {{site.ruby}}@{{site.gemset}} do rvm env --path) +which ruby +gem install bundler +bundle install +rvm gemset list +ruby -v + +#ruby -v diff --git a/vars/main.yml b/vars/main.yml index dd8841d..0be426e 100644 --- a/vars/main.yml +++ b/vars/main.yml @@ -21,3 +21,4 @@ rvm1_symlink_bundler_binaries: - 'bundler' rvm1_symlink_to: '/usr/local/bin' +rvm1_ruby_install_flags: "--autolibs={{rvm1_autolib_mode}}" \ No newline at end of file