badger-rails 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. data/BadgerGit.png +0 -0
  2. data/COPYING +674 -0
  3. data/LICENSING +30 -0
  4. data/Manifest +112 -0
  5. data/README.md +80 -0
  6. data/Rakefile +36 -0
  7. data/badger-rails.gemspec +34 -0
  8. data/bin/badger +486 -0
  9. data/lib/badger/Capfile +1 -0
  10. data/lib/badger/config/deploy.rb +211 -0
  11. data/lib/badger/config/rails-app.yml +6 -0
  12. data/lib/badger/config/rails-app.yml.bk +6 -0
  13. data/lib/badger/core/claws/app.claw +112 -0
  14. data/lib/badger/core/claws/db-app.claw +59 -0
  15. data/lib/badger/core/claws/rails-app.claw +125 -0
  16. data/lib/badger/core/files/badger/info +0 -0
  17. data/lib/badger/core/files/cap/Capfile +4 -0
  18. data/lib/badger/core/files/cap/deploy/production-app.rb +139 -0
  19. data/lib/badger/core/files/cap/deploy/production.rb +136 -0
  20. data/lib/badger/core/files/cap/deploy/staging-app.rb +139 -0
  21. data/lib/badger/core/files/cap/deploy/staging.rb +134 -0
  22. data/lib/badger/core/files/cap/deploy.rb +6 -0
  23. data/lib/badger/core/files/git/git +0 -0
  24. data/lib/badger/core/files/god/angel/resque-dev.god +54 -0
  25. data/lib/badger/core/files/god/angel/resque-stg.god +54 -0
  26. data/lib/badger/core/files/god/angel/resque.god +55 -0
  27. data/lib/badger/core/files/god/angel/unicorn-stg.god +62 -0
  28. data/lib/badger/core/files/god/angel/unicorn.god +62 -0
  29. data/lib/badger/core/files/god/god +108 -0
  30. data/lib/badger/core/files/god/unicorn-stg.rb +70 -0
  31. data/lib/badger/core/files/god/unicorn.rb +70 -0
  32. data/lib/badger/core/files/logrotate/logrotate.conf +23 -0
  33. data/lib/badger/core/files/logrotate/logrotate.cron +8 -0
  34. data/lib/badger/core/files/mysql/database.yml.bk +18 -0
  35. data/lib/badger/core/files/mysql/db_stats +0 -0
  36. data/lib/badger/core/files/mysql/my.cnf +11 -0
  37. data/lib/badger/core/files/nginx/nginx +106 -0
  38. data/lib/badger/core/files/nginx/nginx.conf +30 -0
  39. data/lib/badger/core/files/nginx/sites/port443.btl +42 -0
  40. data/lib/badger/core/files/nginx/sites/port80.btl +39 -0
  41. data/lib/badger/core/files/nginx/sites/production-web +117 -0
  42. data/lib/badger/core/files/nginx/sites/staging-web +41 -0
  43. data/lib/badger/core/files/postfix/main.cf +678 -0
  44. data/lib/badger/core/files/postfix/master.cf +81 -0
  45. data/lib/badger/core/files/redis/redis-server +59 -0
  46. data/lib/badger/core/files/redis/redis.conf +444 -0
  47. data/lib/badger/core/files/resque/resque.rb +5 -0
  48. data/lib/badger/core/files/resque/resque.yml +19 -0
  49. data/lib/badger/core/files/resque/resque_web.rb +2 -0
  50. data/lib/badger/core/files/ssh/authorized_keys +0 -0
  51. data/lib/badger/core/functions +174 -0
  52. data/lib/badger/core/scripts/app_info +40 -0
  53. data/lib/badger/core/scripts/app_scale +15 -0
  54. data/lib/badger/core/scripts/remove_app +25 -0
  55. data/lib/badger/core/scripts/remove_app_db +30 -0
  56. data/lib/badger/core/scripts/remove_gems +2 -0
  57. data/lib/badger/core/teeth/automake.th +9 -0
  58. data/lib/badger/core/teeth/badger.th +27 -0
  59. data/lib/badger/core/teeth/bison.th +20 -0
  60. data/lib/badger/core/teeth/bundler.th +4 -0
  61. data/lib/badger/core/teeth/capistrano-ext.th +37 -0
  62. data/lib/badger/core/teeth/chkconfig.th +4 -0
  63. data/lib/badger/core/teeth/curl.th +24 -0
  64. data/lib/badger/core/teeth/faac.th +11 -0
  65. data/lib/badger/core/teeth/ffmpeg.th +28 -0
  66. data/lib/badger/core/teeth/firewall.th +70 -0
  67. data/lib/badger/core/teeth/gcc-c++.th +9 -0
  68. data/lib/badger/core/teeth/gcc.th +9 -0
  69. data/lib/badger/core/teeth/git.th +23 -0
  70. data/lib/badger/core/teeth/god.th +17 -0
  71. data/lib/badger/core/teeth/lame.th +9 -0
  72. data/lib/badger/core/teeth/libffi.th +4 -0
  73. data/lib/badger/core/teeth/libid3tag.th +10 -0
  74. data/lib/badger/core/teeth/libmad.th +11 -0
  75. data/lib/badger/core/teeth/libogg.th +9 -0
  76. data/lib/badger/core/teeth/libtool.th +9 -0
  77. data/lib/badger/core/teeth/libxml2.th +19 -0
  78. data/lib/badger/core/teeth/libxslt.th +19 -0
  79. data/lib/badger/core/teeth/libyaml.th +19 -0
  80. data/lib/badger/core/teeth/logrotate.th +19 -0
  81. data/lib/badger/core/teeth/madplay.th +10 -0
  82. data/lib/badger/core/teeth/make.th +9 -0
  83. data/lib/badger/core/teeth/mysql-config.th +40 -0
  84. data/lib/badger/core/teeth/mysql-server.th +16 -0
  85. data/lib/badger/core/teeth/mysql.th +14 -0
  86. data/lib/badger/core/teeth/nginx.th +56 -0
  87. data/lib/badger/core/teeth/ntp.th +15 -0
  88. data/lib/badger/core/teeth/openssl.th +19 -0
  89. data/lib/badger/core/teeth/pcre.th +9 -0
  90. data/lib/badger/core/teeth/plugins.th +14 -0
  91. data/lib/badger/core/teeth/postfix.th +11 -0
  92. data/lib/badger/core/teeth/pwgen.th +9 -0
  93. data/lib/badger/core/teeth/rake.th +12 -0
  94. data/lib/badger/core/teeth/readline.th +19 -0
  95. data/lib/badger/core/teeth/redis.th +18 -0
  96. data/lib/badger/core/teeth/resque.th +12 -0
  97. data/lib/badger/core/teeth/ruby.th +52 -0
  98. data/lib/badger/core/teeth/rubygems.th +17 -0
  99. data/lib/badger/core/teeth/san_juan.th +4 -0
  100. data/lib/badger/core/teeth/sox.th +12 -0
  101. data/lib/badger/core/teeth/speex.th +12 -0
  102. data/lib/badger/core/teeth/sqlite3.th +14 -0
  103. data/lib/badger/core/teeth/ssh_keys.th +10 -0
  104. data/lib/badger/core/teeth/sshpass.th +9 -0
  105. data/lib/badger/core/teeth/sudo.th +9 -0
  106. data/lib/badger/core/teeth/syslog-ng.th +16 -0
  107. data/lib/badger/core/teeth/sysv-rc-conf.th +4 -0
  108. data/lib/badger/core/teeth/x264.th +11 -0
  109. data/lib/badger/core/teeth/xvid.th +11 -0
  110. data/lib/badger/core/teeth/yasm.th +11 -0
  111. data/lib/badger/core/teeth/zlib.th +9 -0
  112. data/lib/core.rb +313 -0
  113. data/lib/errors.rb +202 -0
  114. metadata +297 -0
@@ -0,0 +1,174 @@
1
+ for tooth in `cd /etc/badger/core/teeth/ && ls`
2
+ do
3
+ source /etc/badger/core/teeth/$tooth
4
+ done
5
+
6
+ if [ -d "/etc/badger/core/scripts/badger/teeth/" ]
7
+ then
8
+ for tooth in `cd /etc/badger/core/scripts/badger/teeth/ && ls`
9
+ do
10
+ source /etc/badger/core/scripts/badger/teeth/$tooth
11
+ done
12
+ fi
13
+
14
+ GFPath=https://github.com/downloads/curiousminds/packages
15
+
16
+ tmpIP=$(ifconfig | sed -rn 's/.*r:([^ ]+) .*/\1/p')
17
+ declare -a CentOsIPs=($tmpIP)
18
+
19
+ Async() {
20
+ $* 1>&1 &
21
+ }
22
+
23
+ Install() {
24
+ yum -y install $* || apt-get install $*
25
+ }
26
+
27
+ Sync() {
28
+ echo $1 $2
29
+ rsync $1 $2
30
+ if [ -n "$3" ]
31
+ then
32
+ chmod $3 $2
33
+ fi
34
+ }
35
+
36
+ Service() {
37
+ Status=$(service $1 status | grep stopped)
38
+ if [ -z "$Status" ]
39
+ then
40
+ service $1 restart
41
+ echo "$1 is running :)"
42
+ else
43
+ service $1 start
44
+ fi
45
+ }
46
+
47
+ Status() {
48
+ service $1 status && return 0
49
+ service $1 restart
50
+ }
51
+
52
+ Dir() {
53
+ mkdir -p $1
54
+ if [ -n "$2" ]
55
+ then
56
+ chmod $2 $1
57
+ fi
58
+ }
59
+
60
+ Exists() {
61
+ if [ -f $1 ]
62
+ then
63
+ if [ -z $2 ]
64
+ then
65
+ n=$(echo $1 | tr "/" "\n")
66
+ name=(echo $n)
67
+ c=${#name[@]}
68
+ let c--
69
+ file_name=`echo "${name[c]}"`
70
+ echo $file_name installed
71
+ return 0
72
+ else
73
+ echo $2 installed
74
+ return 0
75
+ fi
76
+ else
77
+ return 1
78
+ fi
79
+ }
80
+
81
+ AptExists() {
82
+ if dpkg-query -W $1
83
+ then
84
+ return 0
85
+ else
86
+ return 1
87
+ fi
88
+ }
89
+
90
+ YumExists() {
91
+ yummy=$(rpm -qa | grep $1)
92
+ if [ -z "$yummy" ]
93
+ then
94
+ return 1
95
+ else
96
+ return 0
97
+ fi
98
+ }
99
+
100
+ GemExists() {
101
+ gemList=$(gem list | grep $1)
102
+ if [ -z "$gemList" ]
103
+ then
104
+ return 0
105
+ else
106
+ echo $1 Installed
107
+ return 1
108
+ fi
109
+ }
110
+
111
+ Nil() {
112
+ if [ -z $1 ]
113
+ then
114
+ return 1
115
+ else
116
+ return 0
117
+ fi
118
+ }
119
+
120
+ CentOsRelease() {
121
+ REL=(`cat /etc/*-release | sed 's/[^0-9]*//g'`)
122
+ if [ $REL -gt 60 ]
123
+ then
124
+ return 0
125
+ else
126
+ return 1
127
+ fi
128
+ }
129
+
130
+ IsCentOs() {
131
+ cat /etc/*-release | grep CentOS -m 1
132
+ }
133
+
134
+ GemVersion() {
135
+ if [ `gem --version` == $1 ]
136
+ then
137
+ return 1
138
+ else
139
+ return 0
140
+ fi
141
+ }
142
+
143
+ XenKernel() {
144
+ uname -a | egrep -c '(rscloud)|(xen)'
145
+ }
146
+
147
+ UserGroup() {
148
+ chown $2 $1
149
+ if [ -z $3 ]
150
+ then
151
+ chgrp $2 $1
152
+ else
153
+ chgrp $3 $1
154
+ fi
155
+ }
156
+
157
+ Mysql() {
158
+ mysql -e "SHOW DATABASES;" | grep -x $1 || mysql -e "CREATE DATABASE \`$1\`;"
159
+ mysql -e "SELECT * FROM mysql.db WHERE User='$2' AND Db='$1' AND Host='$3'" | grep $2 ||
160
+ mysql -e "GRANT ALL PRIVILEGES ON \`$1\`.* TO '$2'@'$3' IDENTIFIED BY '$4' WITH GRANT OPTION;"
161
+ }
162
+
163
+ Template() {
164
+ source $1
165
+ }
166
+
167
+ IndexOf() {
168
+ local i=1 S=$2; shift
169
+ while [ $S != $1 ]
170
+ do ((i++)); shift
171
+ [ -z "$1" ] && { i=0; break; }
172
+ done
173
+ echo $i
174
+ }
@@ -0,0 +1,40 @@
1
+ #!/bin/bash
2
+
3
+ tmpIP=$(ifconfig | sed -rn 's/.*r:([^ ]+) .*/\1/p')
4
+ declare -a CentOsIPs=($tmpIP)
5
+ UPTIME=$( uptime )
6
+
7
+ function get_hd_usage() {
8
+ DFYO=(`df -Pm | sed -e 1d | head -3 | sed -n 1p`)
9
+ let total_space=1000*${DFYO[2]}/${DFYO[1]}
10
+ let df_units=total_space/10
11
+ let df_decimal=total_space%10
12
+ echo $df_units.$df_decimal
13
+ }
14
+ function git_link() {
15
+ repo=$( cd /opt/git/ && ls | grep .git )
16
+ echo "git@${CentOsIPs[0]}:/opt/git/$repo"
17
+ }
18
+ function IPS() {
19
+ tmpIP=$(ifconfig | sed -rn 's/.*r:([^ ]+) .*/\1/p')
20
+ declare -a CentOsIPs=($tmpIP)
21
+ }
22
+ function project_name() {
23
+ repo=$( cd /opt/git/ && ls | grep .git )
24
+ name=${repo//${CentOsIPs[0]}/}
25
+ project=${name//.git/}
26
+ echo $project
27
+ }
28
+ echo
29
+ echo "Name: $( project_name )"
30
+ echo "External IP: ${CentOsIPs[0]}"
31
+ echo "Internal IP: ${CentOsIPs[1]}"
32
+ echo "Uptime: ${UPTIME}"
33
+ echo "Disk Usage: %$(get_hd_usage)"
34
+ echo "Git Repo: $(git_link)"
35
+ echo "Rails Project: /opt/web/current"
36
+ echo "Rails Logs: /opt/web/current/log"
37
+ echo "Nginx Logs: /var/log/nginx"
38
+ echo "Mysql Logs: /var/log/mysql"
39
+ echo "Mysql Info: /root/.my.cnf"
40
+ echo
@@ -0,0 +1,15 @@
1
+ #!/bin/bash
2
+ service god restart
3
+ killall -u badger -s QUIT
4
+ sed -i "s/.*num_of_workers =.*/num_of_workers = $1/g" /etc/badger/core/files/god/angel/resque-stg.god
5
+ sed -i "s/.*num_of_workers =.*/num_of_workers = $1/g" /etc/badger/core/files/god/angel/resque.god
6
+
7
+ rsync /etc/badger/core/files/god/angel/resque-stg.god /home/badger/resque-stg.god
8
+ rsync /etc/badger/core/files/god/angel/resque-stg.god /home/badger/resque.god
9
+ sleep 1
10
+ if [ $2 == "staging" ]
11
+ then
12
+ su badger -c 'export PATH=/opt/ruby/bin:/opt/rubygems/bin:$PATH; export GEM_HOME=/opt/rubygems; sudo /opt/rubygems/bin/god load /etc/badger/core/files/god/angel/resque-stg.god'
13
+ else
14
+ su badger -c 'export PATH=/opt/ruby/bin:/opt/rubygems/bin:$PATH; export GEM_HOME=/opt/rubygems; sudo /opt/rubygems/bin/god load /etc/badger/core/files/god/angel/resque.god'
15
+ fi
@@ -0,0 +1,25 @@
1
+ #!/bin/bash
2
+ rm -rf /opt/git/$1.git
3
+ echo $1
4
+ rm -rf /opt/tmp
5
+ rm -rf /opt/web
6
+ service nginx stop
7
+ killall -u redis
8
+ killall -u badger
9
+ [ "$(cat /etc/issue | egrep '(CentOS)|(Red\ Hat)')" ] && service mysqld stop
10
+ [ "$(cat /etc/issue | egrep '(Ubuntu)|(Debian)')" ] && service mysql stop
11
+ service god stop
12
+ cd /etc/badger/core/scripts/
13
+ chmod +x remove_gems
14
+ ./remove_gems
15
+ cd /
16
+
17
+ iptables -F
18
+ iptables -A INPUT -i lo -j ACCEPT
19
+ iptables -A INPUT -i eth1 -j ACCEPT
20
+ iptables -A INPUT -j ACCEPT -m state --state RELATED,ESTABLISHED
21
+ iptables -A INPUT -p icmp -m icmp --icmp-type any -j ACCEPT
22
+ iptables -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
23
+ iptables -A INPUT -j REJECT --reject-with icmp-host-prohibited
24
+
25
+ rm -rf /etc/badger
@@ -0,0 +1,30 @@
1
+ #!/bin/bash
2
+ rm -rf /opt/git/$1.git
3
+ echo $1
4
+ rm -rf /opt/tmp
5
+ rm -rf /opt/web
6
+ service nginx stop
7
+ killall -u redis
8
+ killall -u badger
9
+ [ "$(cat /etc/issue | egrep '(CentOS)|(Red\ Hat)')" ] && service mysqld stop
10
+ [ "$(cat /etc/issue | egrep '(Ubuntu)|(Debian)')" ] && service mysql stop
11
+ service god stop
12
+ cd /etc/badger/core/scripts/
13
+ chmod +x remove_gems
14
+ ./remove_gems
15
+ cd /
16
+
17
+ iptables -F
18
+ iptables -A INPUT -i lo -j ACCEPT
19
+ iptables -A INPUT -i eth1 -j ACCEPT
20
+ iptables -A INPUT -j ACCEPT -m state --state RELATED,ESTABLISHED
21
+ iptables -A INPUT -p icmp -m icmp --icmp-type any -j ACCEPT
22
+ iptables -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
23
+ iptables -A INPUT -j REJECT --reject-with icmp-host-prohibited
24
+
25
+ rm -rf /etc/badger
26
+ rm -rf /root/.my.cnf
27
+ rm -rf /root/.badger.conf
28
+ yum -y remove mysql-server
29
+ apt-get -y remove mysql-server mysql-client
30
+ rm -rf /var/lib/mysql
@@ -0,0 +1,2 @@
1
+ #!/bin/bash
2
+ gem list | cut -d " " -f1 | egrep -v '(bundler|god)' | xargs gem uninstall -aIx
@@ -0,0 +1,9 @@
1
+ yum_automake() {
2
+ Exists /usr/bin/automake && return 0
3
+ yum -y install automake
4
+ }
5
+
6
+ apt_automake() {
7
+ Exists /usr/bin/automake && return 0
8
+ apt-get -y install automake
9
+ }
@@ -0,0 +1,27 @@
1
+ config_badger() {
2
+ Exists /home/badger/.bashrc badger && return 0
3
+ groupadd badger
4
+ useradd -m badger -g badger
5
+
6
+ echo 'gem: --no-ri --no-rdoc' > /home/badger/.gemrc
7
+ echo 'gem: --no-ri --no-rdoc' > /root/.gemrc
8
+ echo 'badger ALL=(ALL) NOPASSWD: ALL' > /etc/sudoers
9
+ echo 'Defaults env_keep="GEM_HOME"' >> /etc/sudoers
10
+ echo 'Defaults env_reset' >> /etc/sudoers
11
+
12
+ Dir /home/badger/ 700
13
+ echo 'badger added'
14
+
15
+ Dir /home/badger/.ssh 700
16
+ chown badger:badger /home/badger/.ssh
17
+
18
+ badger_pub_key=$(cat /root/.ssh/id_rsa.pub)
19
+ Sync /root/.ssh/id_rsa /home/badger/.ssh/id_rsa 700
20
+ chown badger:badger /home/badger/.ssh/id_rsa
21
+
22
+ Sync /root/.ssh/id_rsa.pub /home/badger/.ssh/id_rsa.pub 700
23
+ chown badger:badger /home/badger/.ssh/id_rsa.pub
24
+
25
+ echo $badger_pub_key >> /home/git/.ssh/authorized_keys
26
+ echo $badger_pub_key >> /home/badger/.ssh/authorized_keys
27
+ }
@@ -0,0 +1,20 @@
1
+ yum_bison() {
2
+ YumExists bison && return 0
3
+ yum -y install bison
4
+ }
5
+
6
+ yum_bison-devel() {
7
+ YumExists bison-devel && return 0
8
+ yum -y install bison-devel
9
+ }
10
+
11
+ apt_bison() {
12
+ Exists /usr/bin/bison && return 0
13
+ apt-get -y install bison
14
+ }
15
+
16
+ apt_libbison-dev() {
17
+ AptExists libbison-dev && return 0
18
+ wget https://github.com/downloads/curiousminds/packages/libbison-dev_2.5.dfsg-2.1_amd64.deb
19
+ dpkg -i libbison-dev_2.5.dfsg-2.1_amd64.deb
20
+ }
@@ -0,0 +1,4 @@
1
+ gem_bundler() {
2
+ Exists /opt/rubygems/bin/bundle && return 0
3
+ gem install bundler
4
+ }
@@ -0,0 +1,37 @@
1
+ gem_capistrano-ext() {
2
+ GemExists capistrano-ext || return 0
3
+ gem install capistrano-ext
4
+ }
5
+
6
+ config_capistrano() {
7
+ Dir /opt/tmp/web 777
8
+ Dir /opt/web 744
9
+ chown badger:badger /opt/web || echo 'user badger web'
10
+
11
+ Dir /opt/web/shared 777
12
+ chown badger:badger /opt/web/shared || echo 'user badger shared'
13
+
14
+ Dir /opt/web/shared/log 777
15
+ chown badger:badger /opt/web/shared/log || echo 'user badger log'
16
+
17
+ Dir /opt/web/shared/pids 777
18
+ chown badger:badger /opt/web/shared/pids || echo 'user badger pids'
19
+
20
+ Sync /etc/badger/core/files/cap/Capfile /opt/tmp/web/Capfile
21
+ Sync /etc/badger/core/files/cap/deploy.rb /opt/tmp/web/config/deploy.rb
22
+
23
+ Dir /opt/tmp/web/config/deploy
24
+ Sync /etc/badger/core/files/cap/deploy/production.rb /opt/tmp/web/config/deploy/production.rb
25
+ Sync /etc/badger/core/files/cap/deploy/staging.rb /opt/tmp/web/config/deploy/staging.rb
26
+
27
+ Sync /etc/badger/core/files/cap/deploy/production-app.rb /opt/tmp/web/config/deploy/production-app.rb
28
+ Sync /etc/badger/core/files/cap/deploy/staging-app.rb /opt/tmp/web/config/deploy/staging-app.rb
29
+ cd /opt/tmp/web/
30
+ if [ -z "$2" ]
31
+ then
32
+ cap $1 deploy
33
+ else
34
+ cap $1 -s app_domain=$2 deploy
35
+ fi
36
+ }
37
+
@@ -0,0 +1,4 @@
1
+ apt_chkconfig() {
2
+ Exists /sbin/chkconfig && return 0
3
+ apt-get -y install chkconfig
4
+ }
@@ -0,0 +1,24 @@
1
+ yum_curl() {
2
+ YumExists libcurl && return 0
3
+ yum -y install libcurl
4
+ }
5
+
6
+ yum_curl-devel() {
7
+ YumExists libcurl-devel && return 0
8
+ yum -y install libcurl-devel
9
+ }
10
+
11
+ apt_curl() {
12
+ Exists /usr/bin/curl && return 0
13
+ apt-get -y install curl
14
+ }
15
+
16
+ apt_curl_openssl-dev() {
17
+ AptExists libcurl4-openssl-dev && return 0
18
+ apt-get -y install libcurl4-openssl-dev
19
+ }
20
+
21
+ apt_curl_gnutls-dev() {
22
+ AptExists libcurl4-gnutls-dev && return 0
23
+ apt-get -y install libcurl4-gnutls-dev
24
+ }
@@ -0,0 +1,11 @@
1
+ install_source_faac() {
2
+ Exists /usr/lib/libfaac.so libfaac && return 0
3
+ cd /usr/local/src
4
+ wget -q $GFPath/faac-1.28.tar.gz
5
+ tar -xzvf faac-1.28.tar.gz
6
+ rm -rf faac-1.28.tar.gz
7
+ cd faac-*
8
+ /usr/local/src/faac-1.28/bootstrap && ./configure --prefix=/usr --disable-mp4v2
9
+ make
10
+ make install
11
+ }
@@ -0,0 +1,28 @@
1
+ install_source_ffmpeg() {
2
+ Exists /usr/local/bin/ffmpeg && return 0
3
+ cd /usr/local/src
4
+ wget -q $GFPath/ffmpeg-0.8.3.tar.gz
5
+ tar -xzvf ffmpeg-0.8.3.tar.gz
6
+ rm -rf ffmpeg-0.8.3.tar.gz
7
+ cd ffmpeg-*
8
+ ./configure --enable-libspeex --enable-gpl --enable-postproc --enable-nonfree --enable-postproc --enable-avfilter --enable-pthreads --enable-libxvid --enable-libx264 --enable-libmp3lame --enable-libfaac --disable-ffserver --disable-ffplay &&
9
+ make && make install &&
10
+ cat /etc/ld.so.conf | grep /usr/lib || echo /usr/lib >> /etc/ld.so.conf
11
+ /sbin/ldconfig
12
+ }
13
+
14
+ install_media_group() {
15
+ install_source_yasm
16
+ install_source_x264
17
+ install_source_lame
18
+ install_source_libmad
19
+ install_source_libid3tag
20
+ install_source_madplay
21
+ install_source_sox
22
+ install_source_faac
23
+ install_source_xvid
24
+ install_libogg
25
+ install_libogg-devel
26
+ install_source_libspeex
27
+ install_source_ffmpeg
28
+ }
@@ -0,0 +1,70 @@
1
+ firewall() {
2
+ case $1 in
3
+ web)
4
+ iptables -F
5
+ iptables -A INPUT -i lo -j ACCEPT
6
+ iptables -A INPUT -i eth1 -j ACCEPT
7
+ iptables -A INPUT -j ACCEPT -m state --state RELATED,ESTABLISHED
8
+ iptables -A INPUT -p icmp -m icmp --icmp-type any -j ACCEPT
9
+ iptables -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
10
+ iptables -I INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent --set
11
+ iptables -I INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent --update --seconds 300 --hitcount 10 -j DROP
12
+ iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
13
+ iptables -A INPUT -p tcp -m tcp --dport 443 -j ACCEPT
14
+ iptables -A INPUT -j REJECT --reject-with icmp-host-prohibited
15
+ echo firewall up
16
+ ;;
17
+
18
+ db)
19
+ iptables -F
20
+ iptables -A INPUT -i lo -j ACCEPT
21
+ iptables -A INPUT -i eth1 -j ACCEPT
22
+ iptables -A INPUT -j ACCEPT -m state --state RELATED,ESTABLISHED
23
+ iptables -A INPUT -p icmp -m icmp --icmp-type any -j ACCEPT
24
+ iptables -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
25
+ iptables -I INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent --set
26
+ iptables -I INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent --update --seconds 300 --hitcount 10 -j DROP
27
+ iptables -A INPUT -i eth0 -p tcp -m tcp --dport 3306 -j ACCEPT
28
+ iptables -A INPUT -i eth0 -p tcp -m tcp --dport 6379 -j ACCEPT
29
+ iptables -A INPUT -j REJECT --reject-with icmp-host-prohibited
30
+ echo firewall up
31
+ ;;
32
+
33
+ app)
34
+ iptables -F
35
+ iptables -A INPUT -i lo -j ACCEPT
36
+ iptables -A INPUT -i eth1 -j ACCEPT
37
+ iptables -A INPUT -j ACCEPT -m state --state RELATED,ESTABLISHED
38
+ iptables -A INPUT -p icmp -m icmp --icmp-type any -j ACCEPT
39
+ iptables -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
40
+ iptables -I INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent --set
41
+ iptables -I INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent --update --seconds 300 --hitcount 10 -j DROP
42
+ iptables -A INPUT -j REJECT --reject-with icmp-host-prohibited
43
+ echo firewall up
44
+ ;;
45
+
46
+ badger)
47
+ iptables -F
48
+ iptables -A INPUT -i lo -j ACCEPT
49
+ iptables -A INPUT -i eth1 -j ACCEPT
50
+ iptables -A INPUT -j ACCEPT -m state --state RELATED,ESTABLISHED
51
+ iptables -A INPUT -p icmp -m icmp --icmp-type any -j ACCEPT
52
+ iptables -A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
53
+ iptables -I INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent --set
54
+ iptables -I INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent --update --seconds 300 --hitcount 10 -j DROP
55
+ iptables -A INPUT -j REJECT --reject-with icmp-host-prohibited
56
+ echo firewall up
57
+ ;;
58
+
59
+ *)
60
+ echo 'you must specify a server (web||db||app)'
61
+ exit -99
62
+ ;;
63
+ esac
64
+ }
65
+
66
+ add_fail2ban() {
67
+ fail2ban-client status && return 0
68
+ yum -y install fail2ban
69
+ fail2ban-client start
70
+ }
@@ -0,0 +1,9 @@
1
+ yum_gcc-c++() {
2
+ Exists /usr/bin/c++ && return 0
3
+ yum -y install gcc-c++
4
+ }
5
+
6
+ apt_g++() {
7
+ Exists /usr/bin/c++ && return 0
8
+ apt-get -y install g++
9
+ }
@@ -0,0 +1,9 @@
1
+ yum_gcc() {
2
+ Exists /usr/bin/gcc && return 0
3
+ yum -y install gcc
4
+ }
5
+
6
+ apt_gcc() {
7
+ Exists /usr/bin/gcc && return 0
8
+ apt-get -y install gcc
9
+ }
@@ -0,0 +1,23 @@
1
+ yum_git() {
2
+ Exists /usr/bin/git && return 0
3
+ yum -y install git
4
+ }
5
+
6
+ apt_git() {
7
+ Exists /usr/bin/git && return 0
8
+ apt-get -y install git-core
9
+ }
10
+
11
+ git_clone() {
12
+ Exists /opt/tmp/web/Capfile repo && return 0
13
+ git clone $(sed -n 1p /etc/badger/core/files/git/git) /opt/tmp/web
14
+ }
15
+
16
+ git_repo() {
17
+ Exists /opt/tmp/web/Capfile repo && return 0
18
+ cd /root
19
+ rsync --rsh="sshpass -p $(sed -n 1p /etc/badger/core/files/ssh/app) ssh -o StrictHostKeyChecking=no -l root" .ssh/id_rsa.pub $(sed -n 2p /etc/badger/core/files/ssh/app):/home/git/.ssh/app
20
+ sshpass -p $(sed -n 1p /etc/badger/core/files/ssh/app) ssh -o StrictHostKeyChecking=no root@$(sed -n 2p /etc/badger/core/files/ssh/app) 'cat /home/git/.ssh/authorized_keys | grep "$(cat /home/git/.ssh/app)" || echo $(cat /home/git/.ssh/app) >> /home/git/.ssh/authorized_keys'
21
+ repo=$(sshpass -p $(sed -n 1p /etc/badger/core/files/ssh/app) ssh root@$(sed -n 2p /etc/badger/core/files/ssh/app) 'sed -n 1p /etc/badger/core/files/git/git')
22
+ git clone $repo /opt/tmp/web
23
+ }
@@ -0,0 +1,17 @@
1
+ gem_god() {
2
+ Exists /opt/rubygems/bin/god && return 0
3
+ gem install god
4
+ }
5
+
6
+ config_god() {
7
+ workers=$[$(cat /proc/cpuinfo | grep processor | tail -1 | egrep "[0-9]{1,}" -o)+2]
8
+
9
+ sed -i "s/.*worker_processes.*/worker_processes $workers/g" /etc/badger/core/files/god/unicorn-stg.rb
10
+ sed -i "s/.*worker_processes.*/worker_processes $workers/g" /etc/badger/core/files/god/unicorn.rb
11
+
12
+ sed -i "s/.*num_of_workers =.*/num_of_workers = $workers/g" /etc/badger/core/files/god/angel/resque-stg.god
13
+ sed -i "s/.*num_of_workers =.*/num_of_workers = $workers/g" /etc/badger/core/files/god/angel/resque.god
14
+
15
+ Sync /etc/badger/core/files/god/god /etc/init.d/god 744
16
+ Service god
17
+ }
@@ -0,0 +1,9 @@
1
+ install_source_lame() {
2
+ Exists /usr/bin/lame && return 0
3
+ cd /usr/local/src/
4
+ wget -q http://downloads.sourceforge.net/lame/lame-3.98.4.tar.gz
5
+ tar -xzvf lame-3.98.4.tar.gz
6
+ rm -rf lame-3.98.4.tar.gz
7
+ cd lame-*
8
+ ./configure --prefix=/usr/ && make && make install
9
+ }
@@ -0,0 +1,4 @@
1
+ apt_libffi-dev() {
2
+ AptExists libffi-dev && return 0
3
+ apt-get -y install libffi-dev
4
+ }
@@ -0,0 +1,10 @@
1
+ install_source_libid3tag() {
2
+ Exists /usr/lib/libid3tag.so libid3tag && return 0
3
+ cd /usr/local/src
4
+ wget -q $GFPath/libid3tag-0.15.1b.tar.gz
5
+ tar -xzvf libid3tag-0.15.1b.tar.gz
6
+ rm -rf libid3tag-0.15.1b.tar.gz
7
+ cd libid3tag-*
8
+ ./configure --prefix=/usr &&
9
+ make && make install
10
+ }
@@ -0,0 +1,11 @@
1
+ install_source_libmad() {
2
+ Exists /usr/lib/libmad.so libmad && return 0
3
+ cd /usr/local/src
4
+ wget -q $GFPath/libmad-0.15.1b.tar.gz
5
+ tar -xzvf libmad-0.15.1b.tar.gz
6
+ rm -rf libmad-0.15.1b.tar.gz
7
+ cd libmad-*
8
+ sed -i '/-fforce-mem/d' configure &&
9
+ ./configure --prefix=/usr &&
10
+ make && make install
11
+ }
@@ -0,0 +1,9 @@
1
+ install_libogg() {
2
+ YumExists libogg && return 0
3
+ yum install -y libogg
4
+ }
5
+
6
+ install_libogg-devel() {
7
+ YumExists libogg-devel && return 0
8
+ yum install -y libogg-devel
9
+ }
@@ -0,0 +1,9 @@
1
+ yum_libtool() {
2
+ Exists /usr/bin/libtool && return 0
3
+ yum -y install libtool
4
+ }
5
+
6
+ apt_libtool() {
7
+ Exists /usr/bin/libtool && return 0
8
+ apt-get -y install libtool
9
+ }