bcalloway-slicehost 0.0.2.6 → 0.0.3.0

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.
Files changed (30) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README +99 -0
  3. data/lib/capistrano/ext/slicehost.rb +7 -0
  4. data/lib/capistrano/ext/slicehost/apache.rb +90 -0
  5. data/lib/capistrano/ext/slicehost/aptitude.rb +94 -0
  6. data/lib/capistrano/ext/slicehost/disk.rb +13 -0
  7. data/lib/capistrano/ext/slicehost/gems.rb +41 -0
  8. data/lib/capistrano/ext/slicehost/git.rb +6 -0
  9. data/lib/capistrano/ext/slicehost/iptables.rb +21 -0
  10. data/lib/capistrano/ext/slicehost/mysql.rb +36 -0
  11. data/lib/capistrano/ext/slicehost/nginx.rb +70 -0
  12. data/lib/capistrano/ext/slicehost/postgresql.rb +37 -0
  13. data/lib/capistrano/ext/slicehost/profile.rb +11 -0
  14. data/lib/capistrano/ext/slicehost/render.rb +6 -0
  15. data/lib/capistrano/ext/slicehost/ruby.rb +59 -0
  16. data/lib/capistrano/ext/slicehost/slice.rb +10 -0
  17. data/lib/capistrano/ext/slicehost/ssh.rb +59 -0
  18. data/lib/capistrano/ext/slicehost/templates/bashrc.erb +93 -0
  19. data/lib/capistrano/ext/slicehost/templates/iptables.erb +42 -0
  20. data/lib/capistrano/ext/slicehost/templates/mydircolors.erb +170 -0
  21. data/lib/capistrano/ext/slicehost/templates/nanorc.erb +260 -0
  22. data/lib/capistrano/ext/slicehost/templates/passenger.conf.erb +2 -0
  23. data/lib/capistrano/ext/slicehost/templates/passenger.load.erb +1 -0
  24. data/lib/capistrano/ext/slicehost/templates/sshd_config.erb +81 -0
  25. data/lib/capistrano/ext/slicehost/templates/vhost.erb +8 -0
  26. data/lib/capistrano/ext/slicehost/templates/vhost_nginx.erb +23 -0
  27. data/lib/capistrano/ext/slicehost/templates/vimrc.erb +4 -0
  28. data/lib/capistrano/ext/slicehost/useradd.rb +68 -0
  29. data/lib/capistrano/ext/slicehost/vim.rb +19 -0
  30. metadata +39 -10
@@ -0,0 +1,37 @@
1
+ namespace :postgresql do
2
+ desc "Restarts PostgreSQL database server"
3
+ task :restart, :roles => :db do
4
+ sudo "/etc/init.d/postgresql-8.3 restart"
5
+ end
6
+
7
+ desc "Starts PostgreSQL database server"
8
+ task :start, :roles => :db do
9
+ sudo "/etc/init.d/postgresql-8.3 start"
10
+ end
11
+
12
+ desc "Stops PostgreSQL database server"
13
+ task :stop, :roles => :db do
14
+ sudo "/etc/init.d/postgresql-8.3 stop"
15
+ end
16
+
17
+ desc "Export PostgreSQL database"
18
+ task :export, :roles => :db do
19
+ database = Capistrano::CLI.ui.ask("Which database should we export: ")
20
+ username = Capistrano::CLI.ui.ask("Username: ")
21
+ sudo "pg_dump -U #{username} #{database} > #{database}.sql"
22
+ end
23
+
24
+ desc "Import PostgreSQL database"
25
+ task :import, :roles => :db do
26
+ database = Capistrano::CLI.ui.ask("Which database should we create: ")
27
+ username = Capistrano::CLI.ui.ask("Username: ")
28
+ file = Capistrano::CLI.ui.ask("Which database file should we import: ")
29
+ sudo "createdb -U #{username} #{database}"
30
+ sudo "pg_restore -U #{username} -d #{database} < #{file}"
31
+ end
32
+
33
+ desc "Install PostgreSQL"
34
+ task :install, :roles => :db do
35
+ sudo "aptitude install -y postgresql"
36
+ end
37
+ end
@@ -0,0 +1,11 @@
1
+ namespace :profile do
2
+ desc "Setup .bashrc the way we like it and add directory colors."
3
+ task :configure, :roles => :web do
4
+ run "mv .bashrc /home/#{user}/.bashrc.bak"
5
+ put render("bashrc", binding), ".bashrc"
6
+ put render("mydircolors", binding), ".mydircolors"
7
+ sudo "mv /etc/nanorc /etc/nanorc.bak"
8
+ put render("nanorc", binding), "nanorc"
9
+ sudo "mv nanorc /etc/nanorc"
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ require 'erb'
2
+
3
+ def render(file, binding)
4
+ template = File.read("#{File.dirname(__FILE__)}/templates/#{file}.erb")
5
+ result = ERB.new(template).result(binding)
6
+ end
@@ -0,0 +1,59 @@
1
+ require 'net/http'
2
+
3
+ set :ruby_enterprise_url do
4
+ Net::HTTP.get('www.rubyenterpriseedition.com', '/download.html').scan(/http:.*\.tar\.gz/).first
5
+ end
6
+
7
+ set :ruby_enterprise_version do
8
+ "#{ruby_enterprise_url[/(ruby-enterprise.*)(.tar.gz)/, 1]}"
9
+ end
10
+
11
+ set :passenger_version do
12
+ capture("gem list passenger$ -r").gsub(/[\n|\s|passenger|(|)]/,"")
13
+ end
14
+
15
+ namespace :ruby do
16
+ desc "Install Ruby 1.8"
17
+ task :setup_18, :roles => :app do
18
+ sudo "aptitude install -y ruby1.8-dev ruby1.8 ri1.8 rdoc1.8 irb1.8 libreadline-ruby1.8 libruby1.8 libopenssl-ruby sqlite3 libsqlite3-ruby1.8"
19
+
20
+ # sudo "ln -s /usr/bin/ruby1.8 /usr/bin/ruby"
21
+ # sudo "ln -s /usr/bin/ri1.8 /usr/bin/ri"
22
+ # sudo "ln -s /usr/bin/rdoc1.8 /usr/bin/rdoc"
23
+ # sudo "ln -s /usr/bin/irb1.8 /usr/bin/irb"
24
+ end
25
+
26
+ desc "Install Ruby 1.9"
27
+ task :setup_19, :roles => :app do
28
+ sudo "aptitude install -y ruby1.9.1-dev libruby1.9.1 ruby1.9.1 ri1.9.1 rdoc1.9.1 irb1.9.1 libreadline-ruby1.9.1 libopenssl-ruby1.9.1 sqlite3 libsqlite3-ruby1.9.1"
29
+ end
30
+
31
+ desc "Install Ruby Enterpise Edition"
32
+ task :install_enterprise, :roles => :app do
33
+ sudo "aptitude install -y libssl-dev"
34
+ sudo "aptitude install -y libreadline5-dev"
35
+ run "test ! -d /opt/#{ruby_enterprise_version}"
36
+ run "wget -q #{ruby_enterprise_url}"
37
+ run "tar xzvf #{ruby_enterprise_version}.tar.gz"
38
+ run "rm #{ruby_enterprise_version}.tar.gz"
39
+ sudo "./#{ruby_enterprise_version}/installer --auto /opt/#{ruby_enterprise_version}"
40
+ sudo "rm -rf #{ruby_enterprise_version}/"
41
+ end
42
+
43
+ desc "Install Phusion Passenger"
44
+ task :install_passenger_apache, :roles => :app do
45
+ sudo "apt-get install apache2-mpm-prefork"
46
+ sudo "aptitude install -y apache2-prefork-dev"
47
+ sudo "/opt/#{ruby_enterprise_version}/bin/ruby /opt/#{ruby_enterprise_version}/bin/gem install passenger rake --no-rdoc --no-ri"
48
+ sudo "PATH='/opt/#{ruby_enterprise_version}/bin/':\$PATH /opt/#{ruby_enterprise_version}/bin/ruby /opt/#{ruby_enterprise_version}/bin/passenger-install-apache2-module --auto"
49
+
50
+ put render("passenger.load", binding), "/home/#{user}/passenger.load"
51
+ put render("passenger.conf", binding), "/home/#{user}/passenger.conf"
52
+
53
+ sudo "mv /home/#{user}/passenger.load /etc/apache2/mods-available/"
54
+ sudo "mv /home/#{user}/passenger.conf /etc/apache2/mods-available/"
55
+
56
+ sudo "a2enmod passenger"
57
+ apache.force_reload
58
+ end
59
+ end
@@ -0,0 +1,10 @@
1
+ namespace :slice do
2
+ desc "set up ssh, iptables, aptitude and vim"
3
+ task :configure do
4
+ ssh.setup
5
+ profile.configure
6
+ iptables.configure
7
+ aptitude.setup
8
+ vim.setup
9
+ end
10
+ end
@@ -0,0 +1,59 @@
1
+ ssh_options = { :keys => [File.expand_path("~/.ssh/id_dsa"),File.expand_path("~/.ssh/id_rsa") ], :port => 22 }
2
+
3
+ namespace :ssh do
4
+ desc <<-DESC
5
+ Reload SSH service.
6
+ DESC
7
+ task :reload, :roles => :gateway do
8
+ sudo "/etc/init.d/ssh reload"
9
+ end
10
+
11
+ desc <<-DESC
12
+ Setup SSH on the gateway host. Runs `upload_keys` and `configure_sshd` \
13
+ then reloads the SSH service to finalize the changes.
14
+ DESC
15
+ task :setup, :roles => :gateway do
16
+ upload_keys
17
+ configure_sshd
18
+ reload
19
+ end
20
+
21
+ desc <<-DESC
22
+ Uploads your local public SSH keys to the server. A .ssh folder is created if \
23
+ one does not already exist. The SSH keys default to the ones set in \
24
+ Capistrano's ssh_options. You can change this by setting ssh_options[:keys] = \
25
+ ["/home/user/.ssh/id_dsa"].
26
+
27
+ See "SSH copy" and "SSH Permissions" sections on \
28
+ http://articles.slicehost.com/2008/4/25/ubuntu-hardy-setup-page-1
29
+ DESC
30
+ task :upload_keys, :roles => :gateway do
31
+ run "mkdir -p ~/.ssh"
32
+ run "chown -R #{user}:#{user} ~/.ssh"
33
+ run "chmod 700 ~/.ssh"
34
+
35
+ authorized_keys = ssh_options[:keys].collect { |key|
36
+ begin
37
+ File.read("#{key}.pub")
38
+ rescue Errno::ENOENT => e
39
+ end
40
+
41
+ }.join("\n")
42
+ put authorized_keys, "./.ssh/authorized_keys", :mode => 0600
43
+ end
44
+
45
+ desc <<-DESC
46
+ Configure SSH daemon with more secure settings recommended by Slicehost. The \
47
+ will be configured to run on the port configured in Capistrano's "ssh_options". \
48
+ This defaults to the standard SSH port 22. You can change this by setting \
49
+ ssh_options[:port] = 3000. Note that this change will not take affect until \
50
+ reload the SSH service with `cap ssh:reload`.
51
+
52
+ See "SSH config" section on \
53
+ http://articles.slicehost.com/2008/4/25/ubuntu-hardy-setup-page-1
54
+ DESC
55
+ task :configure_sshd, :roles => :gateway do
56
+ put render("sshd_config", binding), "sshd_config"
57
+ sudo "mv sshd_config /etc/ssh/sshd_config"
58
+ end
59
+ end
@@ -0,0 +1,93 @@
1
+ # ~/.bashrc: executed by bash(1) for non-login shells.
2
+ # see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
3
+ # for examples
4
+
5
+ # If not running interactively, don't do anything
6
+ [ -z "$PS1" ] && return
7
+
8
+ # don't put duplicate lines in the history. See bash(1) for more options
9
+ export HISTCONTROL=ignoredups
10
+ # ... and ignore same sucessive entries.
11
+ export HISTCONTROL=ignoreboth
12
+
13
+ # check the window size after each command and, if necessary,
14
+ # update the values of LINES and COLUMNS.
15
+ shopt -s checkwinsize
16
+
17
+ # make less more friendly for non-text input files, see lesspipe(1)
18
+ [ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"
19
+
20
+ # set variable identifying the chroot you work in (used in the prompt below)
21
+ if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
22
+ debian_chroot=$(cat /etc/debian_chroot)
23
+ fi
24
+
25
+ # set a fancy prompt (non-color, unless we know we "want" color)
26
+ case "$TERM" in
27
+ xterm-color) color_prompt=yes;;
28
+ esac
29
+
30
+ # uncomment for a colored prompt, if the terminal has the capability; turned
31
+ # off by default to not distract the user: the focus in a terminal window
32
+ # should be on the output of commands, not on the prompt
33
+ #force_color_prompt=yes
34
+
35
+ if [ -n "$force_color_prompt" ]; then
36
+ if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
37
+ # We have color support; assume it's compliant with Ecma-48
38
+ # (ISO/IEC-6429). (Lack of such support is extremely rare, and such
39
+ # a case would tend to support setf rather than setaf.)
40
+ color_prompt=yes
41
+ else
42
+ color_prompt=
43
+ fi
44
+ fi
45
+
46
+ if [ "$color_prompt" = yes ]; then
47
+ PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;31m\]\w\[\033[00m\]\$ '
48
+ else
49
+ PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
50
+ fi
51
+ unset color_prompt force_color_prompt
52
+
53
+ # If this is an xterm set the title to user@host:dir
54
+ case "$TERM" in
55
+ xterm*|rxvt*)
56
+ PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME}: ${PWD/$HOME/~}\007"'
57
+ ;;
58
+ *)
59
+ ;;
60
+ esac
61
+
62
+ # Alias definitions.
63
+ # You may want to put all your additions into a separate file like
64
+ # ~/.bash_aliases, instead of adding them here directly.
65
+ # See /usr/share/doc/bash-doc/examples in the bash-doc package.
66
+
67
+ #if [ -f ~/.bash_aliases ]; then
68
+ # . ~/.bash_aliases
69
+ #fi
70
+
71
+ # enable color support of ls and also add handy aliases
72
+ if [ "$TERM" != "dumb" ] && [ -x /usr/bin/dircolors ]; then
73
+ eval "`dircolors ~/.mydircolors`"
74
+ alias ls='ls -alH --color=auto'
75
+ #alias dir='ls --color=auto --format=vertical'
76
+ #alias vdir='ls --color=auto --format=long'
77
+
78
+ #alias grep='grep --color=auto'
79
+ #alias fgrep='fgrep --color=auto'
80
+ #alias egrep='egrep --color=auto'
81
+ fi
82
+
83
+ # some more ls aliases
84
+ #alias ll='ls -l'
85
+ #alias la='ls -A'
86
+ #alias l='ls -CF'
87
+
88
+ # enable programmable completion features (you don't need to enable
89
+ # this, if it's already enabled in /etc/bash.bashrc and /etc/profile
90
+ # sources /etc/bash.bashrc).
91
+ if [ -f /etc/bash_completion ]; then
92
+ . /etc/bash_completion
93
+ fi
@@ -0,0 +1,42 @@
1
+ *filter
2
+
3
+
4
+ # Allows all loopback (lo0) traffic and drop all traffic to 127/8 that doesn't use lo0
5
+ -A INPUT -i lo -j ACCEPT
6
+ -A INPUT -i ! lo -d 127.0.0.0/8 -j REJECT
7
+
8
+
9
+ # Accepts all established inbound connections
10
+ -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
11
+
12
+
13
+ # Allows all outbound traffic
14
+ # You can modify this to only allow certain traffic
15
+ -A OUTPUT -j ACCEPT
16
+
17
+
18
+ # Allows HTTP and HTTPS connections from anywhere (the normal ports for websites)
19
+ -A INPUT -p tcp --dport 80 -j ACCEPT
20
+ -A INPUT -p tcp --dport 443 -j ACCEPT
21
+
22
+
23
+ # Allows SSH connections
24
+ #
25
+ # THE -dport NUMBER IS THE SAME ONE YOU SET UP IN THE SSHD_CONFIG FILE
26
+ #
27
+ -A INPUT -p tcp -m state --state NEW --dport <%= ssh_options[:port] %> -j ACCEPT
28
+
29
+
30
+ # Allow ping
31
+ -A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
32
+
33
+
34
+ # log iptables denied calls
35
+ -A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7
36
+
37
+
38
+ # Reject all other inbound - default deny unless explicitly allowed policy
39
+ -A INPUT -j REJECT
40
+ -A FORWARD -j REJECT
41
+
42
+ COMMIT
@@ -0,0 +1,170 @@
1
+ # Configuration file for dircolors, a utility to help you set the
2
+ # LS_COLORS environment variable used by GNU ls with the --color option.
3
+ # Copyright (C) 1996, 1999-2008
4
+ # Free Software Foundation, Inc.
5
+ # Copying and distribution of this file, with or without modification,
6
+ # are permitted provided the copyright notice and this notice are preserved.
7
+ # The keywords COLOR, OPTIONS, and EIGHTBIT (honored by the
8
+ # slackware version of dircolors) are recognized but ignored.
9
+ # Below, there should be one TERM entry for each termtype that is colorizable
10
+ TERM Eterm
11
+ TERM ansi
12
+ TERM color-xterm
13
+ TERM con132x25
14
+ TERM con132x30
15
+ TERM con132x43
16
+ TERM con132x60
17
+ TERM con80x25
18
+ TERM con80x28
19
+ TERM con80x30
20
+ TERM con80x43
21
+ TERM con80x50
22
+ TERM con80x60
23
+ TERM cons25
24
+ TERM console
25
+ TERM cygwin
26
+ TERM dtterm
27
+ TERM eterm-color
28
+ TERM gnome
29
+ TERM gnome-256color
30
+ TERM konsole
31
+ TERM kterm
32
+ TERM linux
33
+ TERM linux-c
34
+ TERM mach-color
35
+ TERM mlterm
36
+ TERM putty
37
+ TERM rxvt
38
+ TERM rxvt-cygwin
39
+ TERM rxvt-cygwin-native
40
+ TERM rxvt-unicode
41
+ TERM screen
42
+ TERM screen-256color
43
+ TERM screen-bce
44
+ TERM screen-w
45
+ TERM screen.linux
46
+ TERM vt100
47
+ TERM xterm
48
+ TERM xterm-16color
49
+ TERM xterm-256color
50
+ TERM xterm-88color
51
+ TERM xterm-color
52
+ TERM xterm-debian
53
+ # Below are the color init strings for the basic file types. A color init
54
+ # string consists of one or more of the following numeric codes:
55
+ # Attribute codes:
56
+ # 00=none 01=bold 04=underscore 05=blink 07=reverse 08=concealed
57
+ # Text color codes:
58
+ # 30=black 31=red 32=green 33=yellow 34=blue 35=magenta 36=cyan 37=white
59
+ # Background color codes:
60
+ # 40=black 41=red 42=green 43=yellow 44=blue 45=magenta 46=cyan 47=white
61
+ NORMAL 00 # global default, although everything should be something.
62
+ FILE 00 # normal file
63
+ DIR 01;32 # directory
64
+ LINK 01;36 # symbolic link. (If you set this to 'target' instead of a
65
+ # numerical value, the color is as for the file pointed to.)
66
+ FIFO 40;33 # pipe
67
+ SOCK 01;35 # socket
68
+ DOOR 01;35 # door
69
+ BLK 40;33;01 # block device driver
70
+ CHR 40;33;01 # character device driver
71
+ ORPHAN 40;31;01 # symlink to nonexistent file, or non-stat'able file
72
+ SETUID 37;41 # file that is setuid (u+s)
73
+ SETGID 30;43 # file that is setgid (g+s)
74
+ STICKY_OTHER_WRITABLE 30;42 # dir that is sticky and other-writable (+t,o+w)
75
+ OTHER_WRITABLE 34;42 # dir that is other-writable (o+w) and not sticky
76
+ STICKY 37;44 # dir with the sticky bit set (+t) and not other-writable
77
+ # This is for files with execute permission:
78
+ EXEC 01;32
79
+ # List any file extensions like '.gz' or '.tar' that you would like ls
80
+ # to colorize below. Put the extension, a space, and the color init string.
81
+ # (and any comments you want to add after a '#')
82
+ # If you use DOS-style suffixes, you may want to uncomment the following:
83
+ #.cmd 01;32 # executables (bright green)
84
+ #.exe 01;32
85
+ #.com 01;32
86
+ #.btm 01;32
87
+ #.bat 01;32
88
+ # Or if you want to colorize scripts even if they do not have the
89
+ # executable bit actually set.
90
+ #.sh 01;32
91
+ #.csh 01;32
92
+ # archives or compressed (bright red)
93
+ .tar 01;31
94
+ .tgz 01;31
95
+ .svgz 01;31
96
+ .arj 01;31
97
+ .taz 01;31
98
+ .lzh 01;31
99
+ .lzma 01;31
100
+ .zip 01;31
101
+ .z 01;31
102
+ .Z 01;31
103
+ .dz 01;31
104
+ .gz 01;31
105
+ .bz2 01;31
106
+ .bz 01;31
107
+ .tbz2 01;31
108
+ .tz 01;31
109
+ .deb 01;31
110
+ .rpm 01;31
111
+ .jar 01;31
112
+ .rar 01;31
113
+ .ace 01;31
114
+ .zoo 01;31
115
+ .cpio 01;31
116
+ .7z 01;31
117
+ .rz 01;31
118
+ # image formats
119
+ .jpg 01;35
120
+ .jpeg 01;35
121
+ .gif 01;35
122
+ .bmp 01;35
123
+ .pbm 01;35
124
+ .pgm 01;35
125
+ .ppm 01;35
126
+ .tga 01;35
127
+ .xbm 01;35
128
+ .xpm 01;35
129
+ .tif 01;35
130
+ .tiff 01;35
131
+ .png 01;35
132
+ .svg 01;35
133
+ .mng 01;35
134
+ .pcx 01;35
135
+ .mov 01;35
136
+ .mpg 01;35
137
+ .mpeg 01;35
138
+ .m2v 01;35
139
+ .mkv 01;35
140
+ .ogm 01;35
141
+ .mp4 01;35
142
+ .m4v 01;35
143
+ .mp4v 01;35
144
+ .vob 01;35
145
+ .qt 01;35
146
+ .nuv 01;35
147
+ .wmv 01;35
148
+ .asf 01;35
149
+ .rm 01;35
150
+ .rmvb 01;35
151
+ .flc 01;35
152
+ .avi 01;35
153
+ .fli 01;35
154
+ .gl 01;35
155
+ .dl 01;35
156
+ .xcf 01;35
157
+ .xwd 01;35
158
+ .yuv 01;35
159
+ # audio formats
160
+ .aac 00;36
161
+ .au 00;36
162
+ .flac 00;36
163
+ .mid 00;36
164
+ .midi 00;36
165
+ .mka 00;36
166
+ .mp3 00;36
167
+ .mpc 00;36
168
+ .ogg 00;36
169
+ .ra 00;36
170
+ .wav 00;36