standup 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.2
1
+ 0.3.3
@@ -0,0 +1,4 @@
1
+ check process delayed_job
2
+ with pidfile /opt/webapp/tmp/pids/delayed_job.pid
3
+ start program = "/usr/bin/env PATH=$PATH:/usr/local/bin RAILS_ENV=production /opt/webapp/script/delayed_job start"
4
+ stop program = "/usr/bin/env PATH=$PATH:/usr/local/bin RAILS_ENV=production /opt/webapp/script/delayed_job stop"
@@ -0,0 +1,9 @@
1
+ Standup.script do
2
+ def run
3
+ scripts.monit.add_watch script_file('delayed_job_monit.conf')
4
+ end
5
+
6
+ def restart
7
+ scripts.monit.restart_watch 'delayed_job'
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ # Defaults for monit initscript
2
+ # sourced by /etc/init.d/monit
3
+ # installed at /etc/default/monit by maintainer scripts
4
+ # Stefan Alfredsson <alfs@debian.org>
5
+
6
+ # You must set this variable to for monit to start
7
+ startup=1
8
+
9
+ # To change the intervals which monit should run,
10
+ # edit the configuration file /etc/monit/monitrc
11
+ # It can no longer be configured here.
@@ -0,0 +1,9 @@
1
+ set daemon 60
2
+ with start delay 60
3
+
4
+ set logfile /var/log/monit.log
5
+
6
+ set httpd port 2812
7
+ allow localhost
8
+
9
+ include /etc/monit/conf.d/*
@@ -0,0 +1,5 @@
1
+ check process sshd with pidfile /var/run/sshd.pid
2
+ start program "/etc/init.d/ssh start"
3
+ stop program "/etc/init.d/ssh stop"
4
+ if failed port 22 protocol ssh then restart
5
+ if 5 restarts within 5 cycles then timeout
data/scripts/monit.rb ADDED
@@ -0,0 +1,26 @@
1
+ Standup.script do
2
+ def run
3
+ install_package 'monit'
4
+
5
+ upload script_file('monitrc'),
6
+ :to => '/etc/monit',
7
+ :sudo => true
8
+ upload script_file('monit'),
9
+ :to => '/etc/default/monit',
10
+ :sudo => true
11
+
12
+ add_watch script_file('sshd.conf')
13
+ end
14
+
15
+ def add_watch file, name = File.basename(file), restart = true
16
+ upload file,
17
+ :to => "/etc/monit/conf.d/#{name}",
18
+ :sudo => true
19
+
20
+ sudo '/etc/init.d/monit restart' if restart
21
+ end
22
+
23
+ def restart_watch name
24
+ sudo "monit restart #{name}"
25
+ end
26
+ end
@@ -0,0 +1,254 @@
1
+ #! /bin/sh
2
+ ### BEGIN INIT INFO
3
+ # Provides: nginx
4
+ # Required-Start: $remote_fs $syslog
5
+ # Required-Stop: $remote_fs $syslog
6
+ # Default-Start: 2 3 4 5
7
+ # Default-Stop: 0 1 6
8
+ # Short-Description: nginx init.d script for Ubuntu 8.10 and lesser versions.
9
+ # Description: nginx init.d script for Ubuntu 8.10 and lesser versions.
10
+ ### END INIT INFO
11
+ #------------------------------------------------------------------------------
12
+ # nginx - this script, which starts and stops the nginx daemon for ubuntu.
13
+ #
14
+ # description: Nginx is an HTTP(S) server, HTTP(S) reverse \
15
+ # proxy and IMAP/POP3 proxy server. This \
16
+ # script will manage the initiation of the \
17
+ # server and it's process state.
18
+ #
19
+ # processname: nginx
20
+ # config: /usr/local/nginx/conf/nginx.conf
21
+ # pidfile: /acronymlabs/server/nginx.pid
22
+ # Provides: nginx
23
+ #
24
+ # Author: Jason Giedymin
25
+ # <jason.giedymin AT acronymlabs.com>.
26
+ #
27
+ # Version: 1.0 01-Apr-2009 jason.giedymin AT gmail.com
28
+ # Notes: nginx init.d script for Ubuntu 8.10 and lesser versions.
29
+ #
30
+ #------------------------------------------------------------------------------
31
+ # MIT X11 License
32
+ #------------------------------------------------------------------------------
33
+ #
34
+ # Copyright (c) 2009 Jason Giedymin, http://AcronymLabs.com
35
+ #
36
+ # Permission is hereby granted, free of charge, to any person obtaining
37
+ # a copy of this software and associated documentation files (the
38
+ # "Software"), to deal in the Software without restriction, including
39
+ # without limitation the rights to use, copy, modify, merge, publish,
40
+ # distribute, sublicense, and/or sell copies of the Software, and to
41
+ # permit persons to whom the Software is furnished to do so, subject to
42
+ # the following conditions:
43
+ #
44
+ # The above copyright notice and this permission notice shall be
45
+ # included in all copies or substantial portions of the Software.
46
+ #
47
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
48
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
49
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
50
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
51
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
52
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
53
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
54
+ #------------------------------------------------------------------------------
55
+
56
+ #------------------------------------------------------------------------------
57
+ # Functions
58
+ #------------------------------------------------------------------------------
59
+ . /lib/lsb/init-functions
60
+
61
+ #------------------------------------------------------------------------------
62
+ # Consts
63
+ #------------------------------------------------------------------------------
64
+ PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
65
+ DAEMON=/opt/nginx/sbin/nginx
66
+
67
+ PS="nginx"
68
+ PIDNAME="nginx" #Lets you do $PS-Master or $PS-Slave
69
+ PIDFILE=$PIDNAME.pid #pid file
70
+ PIDSPATH=/var/run
71
+ DESCRIPTION="Nginx Server..."
72
+
73
+ RUNAS=root #user to run as
74
+
75
+ SCRIPT_OK=0 #ala error codes
76
+ SCRIPT_ERROR=1 #ala error codes
77
+ TRUE=1 #boolean
78
+ FALSE=0 #boolean
79
+
80
+ lockfile=/var/lock/subsys/nginx
81
+ NGINX_CONF_FILE="/opt/nginx/conf/nginx.conf"
82
+
83
+ #------------------------------------------------------------------------------
84
+ # Simple Tests
85
+ #------------------------------------------------------------------------------
86
+
87
+ #test if nginx is a file and executable
88
+ test -x $DAEMON || exit 0
89
+
90
+ # Include nginx defaults if available
91
+ if [ -f /etc/default/nginx ] ; then
92
+ . /etc/default/nginx
93
+ fi
94
+
95
+ #set exit condition
96
+ #set -e
97
+
98
+ #------------------------------------------------------------------------------
99
+ # Functions
100
+ #------------------------------------------------------------------------------
101
+
102
+ setFilePerms(){
103
+
104
+ if [ -f $PIDSPATH/$PIDFILE ]; then
105
+ chmod -f 400 $PIDSPATH/$PIDFILE
106
+ fi
107
+ }
108
+
109
+ configtest() {
110
+ $DAEMON -t -c $NGINX_CONF_FILE
111
+ }
112
+
113
+ getPSCount() {
114
+ return `pgrep -f $PS | wc -l`
115
+ }
116
+
117
+ isRunning(){
118
+ pidof_daemon
119
+ PID=$?
120
+
121
+ if [ $PID -gt 0 ]; then
122
+ return 1
123
+ else
124
+ return 0
125
+ fi
126
+ }
127
+
128
+ status(){
129
+ isRunning
130
+ isAlive=$?
131
+
132
+ if [ "${isAlive}" -eq $TRUE ]; then
133
+ echo "$PIDNAME found running with processes: `pidof $PS`"
134
+ else
135
+ echo "$PIDNAME is NOT running."
136
+ fi
137
+
138
+
139
+ }
140
+
141
+ removePIDFile(){
142
+ if [ -f $PIDSPATH/PIDFILE ]; then
143
+ rm -f $PIDSPATH/$PIDFILE
144
+ fi
145
+ }
146
+
147
+ start() {
148
+ log_daemon_msg "Starting $DESCRIPTION"
149
+
150
+ isRunning
151
+ isAlive=$?
152
+
153
+ if [ "${isAlive}" -eq $TRUE ]; then
154
+ log_end_msg $SCRIPT_ERROR
155
+ else
156
+ start-stop-daemon --start --quiet --chuid $RUNAS --pidfile $PIDSPATH/$PIDFILE --exec $DAEMON
157
+ setFilePerms
158
+ log_end_msg $SCRIPT_OK
159
+ fi
160
+ }
161
+
162
+ stop() {
163
+ log_daemon_msg "Stopping $DESCRIPTION"
164
+
165
+ isRunning
166
+ isAlive=$?
167
+ if [ "${isAlive}" -eq $TRUE ]; then
168
+ start-stop-daemon --stop --quiet --pidfile $PIDSPATH/$PIDFILE
169
+
170
+ removePIDFile
171
+
172
+ log_end_msg $SCRIPT_OK
173
+ else
174
+ log_end_msg $SCRIPT_ERROR
175
+ fi
176
+ }
177
+
178
+ reload() {
179
+ configtest || return $?
180
+
181
+ log_daemon_msg "Reloading (via HUP) $DESCRIPTION"
182
+
183
+ isRunning
184
+ if [ $? -eq $TRUE ]; then
185
+ `killall -HUP $PS` #to be safe
186
+
187
+ log_end_msg $SCRIPT_OK
188
+ else
189
+ log_end_msg $SCRIPT_ERROR
190
+ fi
191
+ }
192
+
193
+ terminate() {
194
+ log_daemon_msg "Force terminating (via KILL) $DESCRIPTION"
195
+
196
+ PIDS=`pidof $PS` || true
197
+
198
+ [ -e $PIDSPATH/$PIDFILE ] && PIDS2=`cat $PIDSPATH/$PIDFILE`
199
+
200
+ for i in $PIDS; do
201
+ if [ "$i" = "$PIDS2" ]; then
202
+ kill $i
203
+ removePIDFile
204
+ fi
205
+ done
206
+
207
+ log_end_msg $SCRIPT_OK
208
+
209
+ }
210
+
211
+ pidof_daemon() {
212
+ PIDS=`pidof $PS` || true
213
+
214
+ [ -e $PIDSPATH/$PIDFILE ] && PIDS2=`cat $PIDSPATH/$PIDFILE`
215
+
216
+ for i in $PIDS; do
217
+ if [ "$i" = "$PIDS2" ]; then
218
+ return 1
219
+ fi
220
+ done
221
+ return 0
222
+ }
223
+
224
+ case "$1" in
225
+ start)
226
+ start
227
+ ;;
228
+ stop)
229
+ stop
230
+ ;;
231
+ restart|force-reload)
232
+ stop
233
+ start
234
+ ;;
235
+ reload)
236
+ $1
237
+ ;;
238
+ status)
239
+ status
240
+ ;;
241
+ configtest)
242
+ $1
243
+ ;;
244
+ terminate)
245
+ $1
246
+ ;;
247
+ *)
248
+ FULLPATH=/etc/init.d/$PIDNAME
249
+ echo "Usage: $FULLPATH {start|stop|restart|force-reload|status|configtest|terminate}"
250
+ exit 1
251
+ ;;
252
+ esac
253
+
254
+ exit 0
@@ -1,6 +1,8 @@
1
1
  #user nobody;
2
2
  worker_processes 1;
3
3
 
4
+ pid /var/run/nginx.pid;
5
+
4
6
  events {
5
7
  worker_connections 1024;
6
8
  }
@@ -0,0 +1,4 @@
1
+ check process nginx with pidfile /var/run/nginx.pid
2
+ start program = "/etc/init.d/nginx start"
3
+ stop program = "/etc/init.d/nginx stop"
4
+ if 5 restarts within 5 cycles then timeout
data/scripts/passenger.rb CHANGED
@@ -13,19 +13,19 @@ Standup.script do
13
13
  :to =>'/opt/nginx/conf/nginx.conf',
14
14
  :sudo => true
15
15
 
16
- upload script_file('upstart.conf'),
17
- :to =>'/etc/init/nginx.conf',
16
+ upload script_file('nginx'),
17
+ :to =>'/etc/init.d/nginx',
18
18
  :sudo => true
19
- sudo 'initctl reload-configuration'
19
+
20
+ sudo 'chmod +x /etc/init.d/nginx'
21
+ sudo '/usr/sbin/update-rc.d -f nginx defaults'
22
+
23
+ scripts.monit.add_watch script_file('nginx_monit.conf')
20
24
 
21
25
  restart_nginx
22
26
  end
23
27
 
24
28
  def restart_nginx
25
- if exec('initctl status nginx') =~ /running/i
26
- sudo 'initctl restart nginx'
27
- else
28
- sudo 'initctl start nginx'
29
- end
29
+ scripts.monit.restart_watch 'nginx'
30
30
  end
31
31
  end
data/scripts/setup.rb CHANGED
@@ -1,11 +1,15 @@
1
1
  Standup.script do
2
2
  self.description = 'Do all setup from scratch and/or incrementally'
3
3
 
4
- self.default_params = 'ec2 basics ruby postgresql passenger webapp update'
4
+ self.default_params = 'ec2 basics monit ruby postgresql passenger webapp update'
5
5
 
6
6
  def run
7
7
  params.strip.split.each do |name|
8
8
  scripts[name].titled_run
9
9
  end
10
10
  end
11
+
12
+ def has_script? name
13
+ params.strip.split.include? name
14
+ end
11
15
  end
data/scripts/update.rb CHANGED
@@ -10,6 +10,7 @@ Standup.script do
10
10
  sudo 'mkdir -p tmp'
11
11
  sudo 'chown -R nobody:nogroup /opt/webapp'
12
12
  sudo 'touch tmp/restart.txt'
13
+ scripts.delayed_job.restart if scripts.setup.has_script? 'delayed_job'
13
14
  end
14
15
  end
15
16
  end
data/standup.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{standup}
8
- s.version = "0.3.2"
8
+ s.version = "0.3.3"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ilia Ablamonov", "Cloud Castle Inc."]
@@ -39,15 +39,22 @@ Gem::Specification.new do |s|
39
39
  "scripts/allocate_ip.rb",
40
40
  "scripts/appconsole.rb",
41
41
  "scripts/basics.rb",
42
+ "scripts/delayed_job.rb",
43
+ "scripts/delayed_job/delayed_job_monit.conf",
42
44
  "scripts/ec2.rb",
43
45
  "scripts/generate.rb",
44
46
  "scripts/generate/script.rb",
45
47
  "scripts/init.rb",
46
48
  "scripts/init/standup.yml",
47
49
  "scripts/localize.rb",
50
+ "scripts/monit.rb",
51
+ "scripts/monit/monit",
52
+ "scripts/monit/monitrc",
53
+ "scripts/monit/sshd.conf",
48
54
  "scripts/passenger.rb",
55
+ "scripts/passenger/nginx",
49
56
  "scripts/passenger/nginx.conf",
50
- "scripts/passenger/upstart.conf",
57
+ "scripts/passenger/nginx_monit.conf",
51
58
  "scripts/postgresql.rb",
52
59
  "scripts/postgresql/postgresql.conf",
53
60
  "scripts/ruby.rb",
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: standup
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 21
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 2
10
- version: 0.3.2
9
+ - 3
10
+ version: 0.3.3
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ilia Ablamonov
@@ -156,15 +156,22 @@ files:
156
156
  - scripts/allocate_ip.rb
157
157
  - scripts/appconsole.rb
158
158
  - scripts/basics.rb
159
+ - scripts/delayed_job.rb
160
+ - scripts/delayed_job/delayed_job_monit.conf
159
161
  - scripts/ec2.rb
160
162
  - scripts/generate.rb
161
163
  - scripts/generate/script.rb
162
164
  - scripts/init.rb
163
165
  - scripts/init/standup.yml
164
166
  - scripts/localize.rb
167
+ - scripts/monit.rb
168
+ - scripts/monit/monit
169
+ - scripts/monit/monitrc
170
+ - scripts/monit/sshd.conf
165
171
  - scripts/passenger.rb
172
+ - scripts/passenger/nginx
166
173
  - scripts/passenger/nginx.conf
167
- - scripts/passenger/upstart.conf
174
+ - scripts/passenger/nginx_monit.conf
168
175
  - scripts/postgresql.rb
169
176
  - scripts/postgresql/postgresql.conf
170
177
  - scripts/ruby.rb
@@ -1,10 +0,0 @@
1
- description "nginx http daemon"
2
-
3
- start on runlevel [2]
4
- stop on runlevel [016]
5
-
6
- console output
7
-
8
- exec /opt/nginx/sbin/nginx -c /opt/nginx/conf/nginx.conf -g "daemon off;"
9
-
10
- respawn