challenger 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/challenger.gemspec CHANGED
@@ -14,4 +14,6 @@ Gem::Specification.new do |gem|
14
14
  gem.name = "challenger"
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = Challenger::VERSION
17
+
18
+ gem.add_dependency "capistrano"
17
19
  end
@@ -0,0 +1,45 @@
1
+ def template(from, to)
2
+ erb = File.read(File.expand_path("../../templates/#{from}", __FILE__))
3
+ put ERB.new(erb).result(binding), to
4
+ end
5
+
6
+ def set_default(name, *args, &block)
7
+ set(name, *args, &block) unless exists?(name)
8
+ end
9
+
10
+ set_default :user, "deployer"
11
+ set_default(:deploy_to) { "/var/apps/#{application}" }
12
+ set_default :deploy_via, :remote_cache
13
+ set_default :use_sudo, false
14
+
15
+ set_default :scm, "git"
16
+ set_default :branch, "master"
17
+
18
+ default_run_options[:pty] = true
19
+ default_run_options[:shell] = "/bin/bash"
20
+ ssh_options[:forward_agent] = true
21
+
22
+ namespace :deploy do
23
+ desc "Setup deployer user with root account\nSet ENV variable PUBLIC_KEY=path/to/file to use public key other than ~/.ssh/id_rsa.pub"
24
+ task :root do
25
+ set :user, "root"
26
+ run "useradd deployer --home /var/apps --create-home --shell /bin/bash"
27
+ run 'if [[ $(cat /etc/sudoers) != *deployer* ]]; then sed -i "/root.*ALL=(ALL) ALL/ a\\\\deployer ALL\\=\\(ALL\\) NOPASSWD\\: ALL" /etc/sudoers; fi'
28
+ run "mkdir -p /var/apps/.ssh"
29
+ public_key = File.read(ENV["PUBLIC_KEY"] || File.expand_path("~/.ssh/id_rsa.pub"))
30
+ put public_key, "/tmp/public_key"
31
+ run "cat /tmp/public_key >> /var/apps/.ssh/authorized_keys"
32
+ run "rm /tmp/public_key"
33
+ end
34
+
35
+ desc "Install everything onto the server"
36
+ task :install do
37
+ run "#{sudo} apt-get -y update"
38
+ run "#{sudo} apt-get -y install python-software-properties"
39
+ end
40
+ after "deploy:install", "postgresql:install"
41
+ after "deploy:install", "nodejs:install"
42
+ after "deploy:install", "rbenv:install"
43
+ after "deploy:install", "passenger:install"
44
+ after "deploy:install", "nginx:install"
45
+ end
@@ -0,0 +1,28 @@
1
+ set_default(:nginx_server_name) { Capistrano::CLI.ui.ask("Server Hostname (separate multiple hosts with space)") }
2
+ namespace :nginx do
3
+ desc "Configures nginx (after Passenger has installed Nginx)"
4
+ task :install do
5
+ template "nginx", "/tmp/nginx"
6
+ run "#{sudo} mv /tmp/nginx /etc/init.d/nginx"
7
+ run "#{sudo} chmod +x /etc/init.d/nginx"
8
+ run "#{sudo} update-rc.d -f nginx defaults"
9
+ template "nginx.conf.erb", "/tmp/nginx.conf"
10
+ run "#{sudo} mv /tmp/nginx.conf /etc/nginx/conf/nginx.conf"
11
+ run "#{sudo} mkdir /etc/nginx/conf/sites-enabled/"
12
+ end
13
+
14
+ desc "Setup nginx configuration for this application"
15
+ task :setup, roles: :web do
16
+ template "nginx_passenger.erb", "/tmp/nginx.conf"
17
+ run "#{sudo} mv /tmp/nginx.conf /etc/nginx/conf/sites-enabled/#{application}"
18
+ restart
19
+ end
20
+ after "deploy:setup", "nginx:setup"
21
+
22
+ %w[start stop restart].each do |command|
23
+ desc "#{command} nginx"
24
+ task command, roles: :web do
25
+ run "#{sudo} service nginx #{command}"
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,8 @@
1
+ namespace :nodejs do
2
+ desc "Install the latest relase of Node.js"
3
+ task :install, roles: :app do
4
+ run "#{sudo} add-apt-repository ppa:chris-lea/node.js"
5
+ run "#{sudo} apt-get -y update"
6
+ run "#{sudo} apt-get -y install nodejs"
7
+ end
8
+ end
@@ -0,0 +1,9 @@
1
+ set_default :passenger_version, "3.0.11"
2
+ namespace :passenger do
3
+ desc "Install Passenger with Nginx"
4
+ task :install, roles: :web do
5
+ run "gem install passenger --version #{passenger_version}"
6
+ run "#{sudo} apt-get install -y libcurl4-openssl-dev"
7
+ run "sudo -u root `rbenv which passenger-install-nginx-module` --auto --auto-download --prefix=/etc/nginx"
8
+ end
9
+ end
@@ -0,0 +1,33 @@
1
+ set_default(:postgresql_host, "localhost")
2
+ set_default(:postgresql_user) { application }
3
+ set_default(:postgresql_password) { Capistrano::CLI.password_prompt "PostgreSQL Password: " }
4
+ set_default(:postgresql_database) { "#{application}_production" }
5
+
6
+ namespace :postgresql do
7
+ desc "Install the latest stable release of PostgreSQL."
8
+ task :install, roles: :db, only: {primary: true} do
9
+ run "#{sudo} add-apt-repository ppa:pitti/postgresql"
10
+ run "#{sudo} apt-get -y update"
11
+ run "#{sudo} apt-get -y install postgresql libpq-dev"
12
+ end
13
+
14
+ desc "Create a database for this application."
15
+ task :create_database, roles: :db, only: {primary: true} do
16
+ run %Q{#{sudo} -u postgres psql -c "create user #{postgresql_user} with password '#{postgresql_password}';"}
17
+ run %Q{#{sudo} -u postgres psql -c "create database #{postgresql_database} owner #{postgresql_user};"}
18
+ end
19
+ after "deploy:setup", "postgresql:create_database"
20
+
21
+ desc "Generate the database.yml configuration file."
22
+ task :setup, roles: :app do
23
+ run "mkdir -p #{shared_path}/config"
24
+ template "postgresql.yml.erb", "#{shared_path}/config/database.yml"
25
+ end
26
+ after "deploy:setup", "postgresql:setup"
27
+
28
+ desc "Symlink the database.yml file into latest release"
29
+ task :symlink, roles: :app do
30
+ run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/database.yml"
31
+ end
32
+ after "deploy:finalize_update", "postgresql:symlink"
33
+ end
@@ -0,0 +1,38 @@
1
+ set_default :ruby_version, "1.9.3-p125"
2
+ set_default :rbenv_bootstrap, "bootstrap-ubuntu-10-04"
3
+
4
+ namespace :rbenv do
5
+ desc "Install rbenv, Ruby, and the Bundler gem"
6
+ task :install, roles: :app do
7
+ run "#{sudo} apt-get -y install curl git-core"
8
+ run "curl -L https://raw.github.com/fesplugas/rbenv-installer/master/bin/rbenv-installer | bash"
9
+ bashrc = <<-BASHRC
10
+ if [ -d $HOME/.rbenv ]; then
11
+ export PATH="$HOME/.rbenv/bin:$PATH"
12
+ eval "$(rbenv init -)"
13
+ fi
14
+ BASHRC
15
+ put bashrc, "/tmp/rbenvrc"
16
+ run "cat /tmp/rbenvrc ~/.bashrc > ~/.bashrc.tmp"
17
+ run "mv ~/.bashrc.tmp ~/.bashrc"
18
+ run %q{export PATH="$HOME/.rbenv/bin:$PATH"}
19
+ run %q{eval "$(rbenv init -)"}
20
+ run "rbenv #{rbenv_bootstrap}"
21
+ run "rbenv install #{ruby_version}"
22
+ run "rbenv global #{ruby_version}"
23
+
24
+ gemrc = <<-GEMRC
25
+ ---
26
+ verbose: true
27
+ gem: --no-ri --no-rdoc
28
+ update_sources: false
29
+ sources:
30
+ - http://rubygems.org
31
+ GEMRC
32
+ put gemrc, "/tmp/gemrc"
33
+ run "mv /tmp/gemrc ~/.gemrc"
34
+
35
+ run "gem install bundler"
36
+ run "rbenv rehash"
37
+ end
38
+ end
@@ -0,0 +1,202 @@
1
+ #! /bin/sh
2
+
3
+ #------------------------------------------------------------------------------
4
+ # Functions
5
+ #------------------------------------------------------------------------------
6
+ . /lib/lsb/init-functions
7
+
8
+ #------------------------------------------------------------------------------
9
+ # Consts
10
+ #------------------------------------------------------------------------------
11
+ PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
12
+ DAEMON=/etc/nginx/sbin/nginx
13
+
14
+ PS="nginx"
15
+ PIDNAME="nginx" #Lets you do $PS-Master or $PS-Slave
16
+ PIDFILE=$PIDNAME.pid #pid file
17
+ PIDSPATH=/etc/nginx/logs
18
+ DESCRIPTION="Nginx Server..."
19
+
20
+ RUNAS=root #user to run as
21
+
22
+ SCRIPT_OK=0 #ala error codes
23
+ SCRIPT_ERROR=1 #ala error codes
24
+ TRUE=1 #boolean
25
+ FALSE=0 #boolean
26
+
27
+ lockfile=/var/lock/subsys/nginx
28
+ NGINX_CONF_FILE="/etc/nginx/conf/nginx.conf"
29
+
30
+ #------------------------------------------------------------------------------
31
+ # Simple Tests
32
+ #------------------------------------------------------------------------------
33
+
34
+ #test if nginx is a file and executable
35
+ test -x $DAEMON || exit 0
36
+
37
+ # Include nginx defaults if available
38
+ if [ -f /etc/default/nginx ] ; then
39
+ . /etc/default/nginx
40
+ fi
41
+
42
+ #set exit condition
43
+ #set -e
44
+
45
+ #------------------------------------------------------------------------------
46
+ # Functions
47
+ #------------------------------------------------------------------------------
48
+
49
+ setFilePerms(){
50
+
51
+ if [ -f $PIDSPATH/$PIDFILE ]; then
52
+ chmod -f 400 $PIDSPATH/$PIDFILE
53
+ fi
54
+ }
55
+
56
+ configtest() {
57
+ $DAEMON -t -c $NGINX_CONF_FILE
58
+ }
59
+
60
+ getPSCount() {
61
+ return `pgrep -f $PS | wc -l`
62
+ }
63
+
64
+ isRunning(){
65
+ pidof_daemon
66
+ PID=$?
67
+
68
+ if [ $PID -gt 0 ]; then
69
+ return 1
70
+ else
71
+ return 0
72
+ fi
73
+ }
74
+
75
+ status(){
76
+ isRunning
77
+ isAlive=$?
78
+
79
+ if [ "${isAlive}" -eq $TRUE ]; then
80
+ echo "$PIDNAME found running with processes: `pidof $PS`"
81
+ else
82
+ echo "$PIDNAME is NOT running."
83
+ fi
84
+
85
+
86
+ }
87
+
88
+ removePIDFile(){
89
+ if [ -f $PIDSPATH/PIDFILE ]; then
90
+ rm -f $PIDSPATH/$PIDFILE
91
+ fi
92
+ }
93
+
94
+ start() {
95
+ log_daemon_msg "Starting $DESCRIPTION"
96
+
97
+ isRunning
98
+ isAlive=$?
99
+
100
+ if [ "${isAlive}" -eq $TRUE ]; then
101
+ log_end_msg $SCRIPT_ERROR
102
+ else
103
+ start-stop-daemon --start --quiet --chuid $RUNAS --pidfile $PIDSPATH/$PIDFILE --exec $DAEMON
104
+ setFilePerms
105
+ log_end_msg $SCRIPT_OK
106
+ fi
107
+ }
108
+
109
+ stop() {
110
+ log_daemon_msg "Stopping $DESCRIPTION"
111
+
112
+ isRunning
113
+ isAlive=$?
114
+ if [ "${isAlive}" -eq $TRUE ]; then
115
+ start-stop-daemon --stop --quiet --pidfile $PIDSPATH/$PIDFILE
116
+
117
+ removePIDFile
118
+
119
+ log_end_msg $SCRIPT_OK
120
+ else
121
+ log_end_msg $SCRIPT_ERROR
122
+ fi
123
+ }
124
+
125
+ reload() {
126
+ configtest || return $?
127
+
128
+ log_daemon_msg "Reloading (via HUP) $DESCRIPTION"
129
+
130
+ isRunning
131
+ if [ $? -eq $TRUE ]; then
132
+ `killall -HUP $PS` #to be safe
133
+
134
+ log_end_msg $SCRIPT_OK
135
+ else
136
+ log_end_msg $SCRIPT_ERROR
137
+ fi
138
+ }
139
+
140
+ terminate() {
141
+ log_daemon_msg "Force terminating (via KILL) $DESCRIPTION"
142
+
143
+ PIDS=`pidof $PS` || true
144
+
145
+ [ -e $PIDSPATH/$PIDFILE ] && PIDS2=`cat $PIDSPATH/$PIDFILE`
146
+
147
+ for i in $PIDS; do
148
+ if [ "$i" = "$PIDS2" ]; then
149
+ kill $i
150
+ removePIDFile
151
+ fi
152
+ done
153
+
154
+ log_end_msg $SCRIPT_OK
155
+
156
+ }
157
+
158
+ pidof_daemon() {
159
+ PIDS=`pidof $PS` || true
160
+
161
+ [ -e $PIDSPATH/$PIDFILE ] && PIDS2=`cat $PIDSPATH/$PIDFILE`
162
+
163
+ for i in $PIDS; do
164
+ if [ "$i" = "$PIDS2" ]; then
165
+ return 1
166
+ fi
167
+ done
168
+ return 0
169
+ }
170
+
171
+ case "$1" in
172
+ start)
173
+ start
174
+ ;;
175
+ stop)
176
+ stop
177
+ ;;
178
+ restart|force-reload)
179
+ stop
180
+ start
181
+ ;;
182
+ reload)
183
+ $1
184
+ ;;
185
+ status)
186
+ status
187
+ ;;
188
+ configtest)
189
+ $1
190
+ ;;
191
+ terminate)
192
+ $1
193
+ ;;
194
+ *)
195
+ FULLPATH=/etc/init.d/$PIDNAME
196
+ echo "Usage: $FULLPATH {start|stop|restart|force-reload|status|configtest|terminate}"
197
+ exit 1
198
+ ;;
199
+ esac
200
+
201
+ exit 0
202
+
@@ -0,0 +1,28 @@
1
+ worker_processes 4;
2
+
3
+ error_log logs/error.log;
4
+
5
+ pid logs/nginx.pid;
6
+
7
+ events {
8
+ worker_connections 1024;
9
+ }
10
+
11
+ http {
12
+ passenger_root /var/apps/.rbenv/versions/<%= ruby_version %>/lib/ruby/gems/1.9.1/gems/passenger-<%= passenger_version %>;
13
+ passenger_ruby /var/apps/.rbenv/versions/<%= ruby_version %>/bin/ruby;
14
+
15
+ include mime.types;
16
+ default_type application/octet-stream;
17
+
18
+ log_format main '$remote_addr - $remote_user [$time_local] "$request" '
19
+ '$status $body_bytes_sent "$http_referer" '
20
+ '"$http_user_agent" "$http_x_forwarded_for"';
21
+
22
+ access_log logs/access.log main;
23
+
24
+ sendfile on;
25
+ keepalive_timeout 10;
26
+
27
+ include sites-enabled/*;
28
+ }
@@ -0,0 +1,6 @@
1
+ server {
2
+ server_name <%= nginx_server_name %>;
3
+ root <%= current_path %>/public/;
4
+ passenger_enabled on;
5
+ rails_env production;
6
+ }
@@ -0,0 +1,8 @@
1
+ production:
2
+ adapter: postgresql
3
+ encoding: unicode
4
+ database: <%= postgresql_database %>
5
+ pool: 5
6
+ username: <%= postgresql_user %>
7
+ password: <%= postgresql_password %>
8
+ host: <%= postgresql_host %>
@@ -1,3 +1,3 @@
1
1
  module Challenger
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/challenger.rb CHANGED
@@ -1,5 +1,9 @@
1
+ require "capistrano"
2
+ require "capistrano/cli"
3
+ require "bundler/capistrano"
4
+
1
5
  require "challenger/version"
2
6
 
3
- module Challenger
4
- # Your code goes here...
7
+ Capistrano::Configuration.instance.load do
8
+ Dir.glob(File.join(File.dirname(__FILE__), '/challenger/recipes/*.rb')).each { |f| load f }
5
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: challenger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,8 +9,19 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-28 00:00:00.000000000 Z
13
- dependencies: []
12
+ date: 2012-03-29 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: capistrano
16
+ requirement: &70353821556040 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70353821556040
14
25
  description: Capistrano recipes to launch your server.
15
26
  email:
16
27
  - utkarshkukreti@gmail.com
@@ -25,6 +36,16 @@ files:
25
36
  - Rakefile
26
37
  - challenger.gemspec
27
38
  - lib/challenger.rb
39
+ - lib/challenger/recipes/base.rb
40
+ - lib/challenger/recipes/nginx.rb
41
+ - lib/challenger/recipes/nodejs.rb
42
+ - lib/challenger/recipes/passenger.rb
43
+ - lib/challenger/recipes/postgresql.rb
44
+ - lib/challenger/recipes/rbenv.rb
45
+ - lib/challenger/templates/nginx
46
+ - lib/challenger/templates/nginx.conf.erb
47
+ - lib/challenger/templates/nginx_passenger.erb
48
+ - lib/challenger/templates/postgresql.yml.erb
28
49
  - lib/challenger/version.rb
29
50
  homepage: https://github.com/utkarshkukreti/challenger
30
51
  licenses: []