eycloud-recipe-sidekiq 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +6 -2
- data/eycloud-recipe-sidekiq.gemspec +3 -3
- data/libraries/sidekiq_instances.rb +9 -0
- data/metadata.json +1 -1
- data/metadata.rb +1 -1
- data/recipes/configure.rb +34 -17
- data/recipes/default.rb +1 -1
- data/recipes/restart.rb +13 -4
- data/templates/default/monitrc.conf.erb +8 -0
- data/templates/default/sidekiq.erb +219 -0
- data/templates/default/sidekiq.yml.erb +22 -0
- metadata +11 -10
- data/libraries/find_sidekiq_instances.rb +0 -21
- data/recipes/install.rb +0 -19
- data/template/default/monitrc.erb +0 -7
- data/template/default/sidekiq.erb +0 -78
data/README.md
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
# Sidekiq recipe for EY Cloud
|
2
2
|
|
3
|
-
|
3
|
+
Sidekiq is a Redis-backed Ruby library for creating background jobs, placing those jobs on multiple queues, and processing them later.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
|
7
|
+
Add the following to `main/recipes/default.rb` in your cookbooks:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
require_recipe "sidekiq"
|
11
|
+
```
|
8
12
|
|
9
13
|
## Contributing
|
10
14
|
|
@@ -1,12 +1,12 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
2
|
$:.push File.expand_path("../lib", __FILE__)
|
3
3
|
|
4
|
-
version = "0.
|
4
|
+
version = "0.2.0" # TODO get from metadata.json or .rb
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "eycloud-recipe-sidekiq"
|
8
8
|
s.version = version
|
9
|
-
s.authors = ["Dr Nic Williams"]
|
9
|
+
s.authors = ["Dr Nic Williams", "Jesse Cooke"]
|
10
10
|
s.email = ["drnicwilliams@gmail.com"]
|
11
11
|
s.homepage = ""
|
12
12
|
s.summary = %q{Sidekiq recipe for EY Cloud} # TODO from metadata
|
@@ -17,6 +17,6 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
18
|
s.require_paths = ["lib"]
|
19
19
|
|
20
|
-
# s.add_dependency("eycloud-helper-
|
20
|
+
# s.add_dependency("eycloud-helper-common")
|
21
21
|
s.add_development_dependency("rake")
|
22
22
|
end
|
data/metadata.json
CHANGED
data/metadata.rb
CHANGED
data/recipes/configure.rb
CHANGED
@@ -1,22 +1,39 @@
|
|
1
|
-
#
|
2
|
-
# Cookbook Name:: sidekiq
|
3
|
-
# Recipe:: restart
|
4
|
-
#
|
5
|
-
|
6
1
|
if sidekiq_instance?
|
7
2
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
3
|
+
# for now
|
4
|
+
worker_count = 1
|
5
|
+
|
6
|
+
node[:applications].each do |app, data|
|
7
|
+
template "/etc/monit.d/sidekiq_#{app}.monitrc" do
|
8
|
+
owner 'root'
|
9
|
+
group 'root'
|
10
|
+
mode 0644
|
11
|
+
source "monitrc.conf.erb"
|
15
12
|
variables({
|
16
|
-
:
|
17
|
-
:app_name =>
|
13
|
+
:num_workers => worker_count,
|
14
|
+
:app_name => app,
|
15
|
+
:rails_env => node[:environment][:framework_env]
|
18
16
|
})
|
19
17
|
end
|
20
|
-
|
21
|
-
|
22
|
-
|
18
|
+
|
19
|
+
template "/engineyard/bin/sidekiq" do
|
20
|
+
owner 'root'
|
21
|
+
group 'root'
|
22
|
+
mode 0755
|
23
|
+
source "sidekiq.erb"
|
24
|
+
end
|
25
|
+
|
26
|
+
worker_count.times do |count|
|
27
|
+
template "/data/#{app}/shared/config/sidekiq_#{count}.yml" do
|
28
|
+
owner node[:owner_name]
|
29
|
+
group node[:owner_name]
|
30
|
+
mode 0644
|
31
|
+
source "sidekiq.yml.erb"
|
32
|
+
variables({
|
33
|
+
:require => "/data/#{app}/current"
|
34
|
+
})
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
end
|
data/recipes/default.rb
CHANGED
data/recipes/restart.rb
CHANGED
@@ -1,7 +1,16 @@
|
|
1
|
-
#
|
2
|
-
# Cookbook Name:: sidekiq
|
3
|
-
# Recipe:: restart
|
4
|
-
#
|
5
1
|
|
6
2
|
if sidekiq_instance?
|
3
|
+
|
4
|
+
execute "ensure-sidekiq-is-setup-with-monit" do
|
5
|
+
command %Q{
|
6
|
+
monit reload
|
7
|
+
}
|
8
|
+
end
|
9
|
+
|
10
|
+
execute "restart-sidekiq" do
|
11
|
+
command %Q{
|
12
|
+
echo "sleep 20 && monit -g #{app}_sidekiq restart all" | at now
|
13
|
+
}
|
14
|
+
end
|
15
|
+
|
7
16
|
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<% (@num_workers || 1).times do |num| %>
|
2
|
+
check process sidekiq_<%= @app_name %>_<%= num %>
|
3
|
+
with pidfile /var/run/engineyard/sidekiq/<%= @app_name %>/sidekiq_<%= num %>.pid
|
4
|
+
start program = "/engineyard/bin/sidekiq <%= @app_name %> start <%= @rails_env %> sidekiq_<%= num %>.yml" with timeout 90 seconds
|
5
|
+
stop program = "/engineyard/bin/sidekiq <%= @app_name %> stop <%= @rails_env %> sidekiq_<%= num %>.yml" with timeout 90 seconds
|
6
|
+
if totalmem is greater than 300 MB for 2 cycles then restart # eating up memory?
|
7
|
+
group <%= @app_name %>_sidekiq
|
8
|
+
<% end %>
|
@@ -0,0 +1,219 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
#
|
3
|
+
# This script starts and stops the Sidekiq daemon
|
4
|
+
# This script belongs in /engineyard/bin/sidekiq
|
5
|
+
#
|
6
|
+
|
7
|
+
PATH=/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$PATH
|
8
|
+
CURDIR=`pwd`
|
9
|
+
|
10
|
+
usage() {
|
11
|
+
echo "Usage: $0 <appname> {start|stop|quit} <environment> <conf_file>"
|
12
|
+
echo -e "\nstop) is a synonym for quit"
|
13
|
+
echo "quit) issues -INT to request the worker to stop"
|
14
|
+
echo -e "\nSee http://mperham.github.com/sidekiq/ for more details"
|
15
|
+
exit 1
|
16
|
+
}
|
17
|
+
|
18
|
+
rm_lockfile(){
|
19
|
+
if [ -e $LOCK_FILE ]; then
|
20
|
+
logger -t "monit-sidekiq[$$]" "removing $LOCK_FILE for `cat $LOCK_FILE`"
|
21
|
+
rm $LOCK_FILE
|
22
|
+
fi
|
23
|
+
}
|
24
|
+
|
25
|
+
exit_cleanly() {
|
26
|
+
cd $CURDIR
|
27
|
+
logger -t "monit-sidekiq[$$]" "exiting wrapper cleanly with $RESULT"
|
28
|
+
exit $RESULT
|
29
|
+
}
|
30
|
+
|
31
|
+
unlock_and_exit_cleanly(){
|
32
|
+
rm_lockfile
|
33
|
+
exit_cleanly
|
34
|
+
}
|
35
|
+
|
36
|
+
set_pid_from_file(){
|
37
|
+
export PID=`cat $PID_FILE`
|
38
|
+
}
|
39
|
+
|
40
|
+
signal_worker() {
|
41
|
+
RESULT=0
|
42
|
+
if [ -f $PID_FILE ]; then
|
43
|
+
set_pid_from_file
|
44
|
+
logger -t "monit-sidekiq[$$]" "Issuing kill with -$SIG $PID"
|
45
|
+
SLEEP_COUNT=0
|
46
|
+
kill -$SIG $PID
|
47
|
+
fi
|
48
|
+
}
|
49
|
+
|
50
|
+
signal_worker_fatally(){
|
51
|
+
signal_worker()
|
52
|
+
if [ -f $PID_FILE ]; then
|
53
|
+
if [ -n "$ALLOW_TIMEOUT" ]; then
|
54
|
+
while [ -e /proc/$PID ]; do
|
55
|
+
sleep .25
|
56
|
+
let "SLEEP_COUNT+=1"
|
57
|
+
let "REPORT_TIME = $SLEEP_COUNT%4"
|
58
|
+
if(( "$SLEEP_COUNT" > $GRACE_TIME )); then
|
59
|
+
logger -t "monit-sidekiq[$$]" "Sidekiq worker with pid $PID for $WORKER_REF still running, issuing -TERM"
|
60
|
+
kill -15 $PID 2>/dev/null; true
|
61
|
+
elif(( $REPORT_TIME == 0 )); then
|
62
|
+
let "RUNTIME = $SLEEP_COUNT/4"
|
63
|
+
logger -t "monit-sidekiq[$$]" "waiting for $PID to die ( for $RUNTIME seconds now)"
|
64
|
+
fi
|
65
|
+
done
|
66
|
+
fi
|
67
|
+
sleep 1
|
68
|
+
if [ -d /proc/$PID ];then
|
69
|
+
for child in $(ps axo pid,ppid | awk "{ if ( \$2 == $PID ) { print \$1 }}");
|
70
|
+
do
|
71
|
+
kill -9 $child 2>/dev/null; true
|
72
|
+
logger -t "monit-sidekiq[$$]" "Murdering Sidekiq workers child with $child for $WORKER_REF"
|
73
|
+
break
|
74
|
+
done
|
75
|
+
while [ -d /proc/$PID ]; do
|
76
|
+
logger -t "monit-sidekiq[$$]" "Murdering Sidekiq worker with $PID for $WORKER_REF"
|
77
|
+
kill -9 $PID
|
78
|
+
sleep 1
|
79
|
+
done
|
80
|
+
fi
|
81
|
+
logger -t "monit-sidekiq[$$]" "Removing pid file for $PID - $WORKER_REF"
|
82
|
+
[ -e "$PID_FILE" -a ! -d /proc/$PID ] && rm -f $PID_FILE
|
83
|
+
fi
|
84
|
+
}
|
85
|
+
|
86
|
+
lock(){
|
87
|
+
RESULT=0
|
88
|
+
if [ -e $LOCK_FILE ]; then
|
89
|
+
LAST_LOCK_PID=`cat $LOCK_FILE`
|
90
|
+
if [ -n $LAST_LOCK_PID -a -z "`ps axo pid|grep $LAST_LOCK_PID`" -a -f $LOCK_FILE ];then
|
91
|
+
sleep 1
|
92
|
+
logger -t "monit-sidekiq[$$]" "Removing stale lock file for $WORKER_REF ($LAST_LOCK_PID)"
|
93
|
+
rm $LOCK_FILE 2>&1
|
94
|
+
else
|
95
|
+
logger -t "monit-sidekiq[$$]" "Monit already messing with $WORKER_REF ($LAST_LOCK_PID)"
|
96
|
+
RESULT=1
|
97
|
+
exit_cleanly
|
98
|
+
fi
|
99
|
+
fi
|
100
|
+
echo $$ > $LOCK_FILE
|
101
|
+
}
|
102
|
+
|
103
|
+
legacy_fix() {
|
104
|
+
#In the transition from 0.18.2 to 0.18.3 of ey monit scripts the way
|
105
|
+
#the pid file is used to find the process to kill has changed.
|
106
|
+
#To avert problems being left behind after an upgrade of this package,
|
107
|
+
if [ -f $PID_FILE ]; then
|
108
|
+
set_pid_from_file
|
109
|
+
if [ -n "`ps axo pid,command|grep $PID|grep 'su -c'`" ];then
|
110
|
+
logger -t "monit-sidekiq[$$]" "Monit Scripts have just been upgraded, killing old style workers"
|
111
|
+
for child in $(ps axo pid,ppid| awk "{ if ( \$2 == $PID ) { print \$1 }}");
|
112
|
+
do
|
113
|
+
kill -TERM $child 2> /dev/null
|
114
|
+
while [ -e /proc/$child ]; do
|
115
|
+
logger -t "monit-sidekiq[$$]" "killing legacy worker: $child"
|
116
|
+
[ -e /proc/$child ] && kill -9 $child 2> /dev/null
|
117
|
+
sleep 1
|
118
|
+
done
|
119
|
+
done
|
120
|
+
[ -e /proc/$PID ] && kill -9 $PID 2> /dev/null
|
121
|
+
rm $PID_FILE
|
122
|
+
unlock_exit_cleanly
|
123
|
+
fi
|
124
|
+
fi
|
125
|
+
}
|
126
|
+
|
127
|
+
if [ $# -lt 4 ]; then usage; fi
|
128
|
+
|
129
|
+
if [ "`whoami`" != "root" ]; then
|
130
|
+
logger -t `basename $0` -s "Must be run as root"
|
131
|
+
exit 1
|
132
|
+
fi
|
133
|
+
|
134
|
+
#Baisc Setup of default values
|
135
|
+
APP=$1 ; ACTION=$2; RACK_ENV=$3; CONF_FILE=$4;
|
136
|
+
|
137
|
+
APP_DIR="/data/${APP}"
|
138
|
+
APP_ROOT="${APP_DIR}/current"
|
139
|
+
APP_SHARED="${APP_DIR}/shared"
|
140
|
+
APP_CONFIG="${APP_SHARED}/config"
|
141
|
+
|
142
|
+
if [ -e "${APP_CONFIG}/${CONF_FILE}" ]; then
|
143
|
+
logger -t "sidekiq_${APP}" -s "Good, found a conf file. Proceeding..."
|
144
|
+
else
|
145
|
+
logger -t "sidekiq_${APP}" -s "/data/${APP}/shared/config/${CONF_FILE} not found for app: ${APP}"
|
146
|
+
exit 1
|
147
|
+
fi
|
148
|
+
|
149
|
+
WORKER_REF=`echo $CONF_FILE | sed s/.conf//`
|
150
|
+
LOG_FILE="$APP_ROOT/log/$WORKER_REF.log"
|
151
|
+
LOCK_FILE="/tmp/$WORKER_REF.monit-lock"
|
152
|
+
PID_FILE="/var/run/engineyard/sidekiq/$APP/$WORKER_REF.pid"
|
153
|
+
GEMFILE="$APP_ROOT/Gemfile"
|
154
|
+
SIDEKIQ="sidekiq"
|
155
|
+
if [ -f $GEMFILE ];then
|
156
|
+
SIDEKIQ="bundle exec $APP_ROOT/ey_bundler_binstubs/sidekiq"
|
157
|
+
fi
|
158
|
+
|
159
|
+
if [ -d $APP_ROOT ]; then
|
160
|
+
USER=$(stat -L -c"%U" $APP_ROOT)
|
161
|
+
export HOME="/home/$USER"
|
162
|
+
|
163
|
+
# Fix for SD-3786 - stop sending in VERBOSE= and VVERBOSE= by default
|
164
|
+
if declare -p VERBOSE >/dev/null 2>&1; then export V="VERBOSE=$VERBOSE"; fi
|
165
|
+
if declare -p VVERBOSE >/dev/null 2>&1; then export VV="VVERBOSE=$VVERBOSE"; fi
|
166
|
+
|
167
|
+
# Older versions of sudo need us to call env for the env vars to be set correctly
|
168
|
+
COMMAND="/usr/bin/env $V $VV APP_ROOT=${APP_ROOT} RACK_ENV=${RACK_ENV} RAILS_ENV=${RACK_ENV} $SIDEKIQ -e ${RACK_ENV} -C ${APP_CONFIG}/${CONF_FILE}"
|
169
|
+
|
170
|
+
if [ ! -d /var/run/engineyard/sidekiq/$APP ]; then
|
171
|
+
mkdir -p /var/run/engineyard/sidekiq/$APP
|
172
|
+
fi
|
173
|
+
|
174
|
+
# handle the second param, don't start if already existing
|
175
|
+
|
176
|
+
logger -t "monit-sidekiq[$$]" "${ACTION}ing Sidekiq worker $WORKER_REF"
|
177
|
+
case "$ACTION" in
|
178
|
+
start)
|
179
|
+
lock
|
180
|
+
cd $APP_ROOT
|
181
|
+
if [ -f $PID_FILE ]; then
|
182
|
+
set_pid_from_file
|
183
|
+
if [ -d /proc/$PID ]; then
|
184
|
+
logger -t "monit-sidekiq[$$]" "Sidekiq worker $WORKER_REF is already running with $PID."
|
185
|
+
RESULT=1
|
186
|
+
else
|
187
|
+
rm -f $PID_FILE
|
188
|
+
logger -t "monit-sidekiq[$$]" "Removing stale pid file ($PID_FILE) for pid $PID"
|
189
|
+
fi
|
190
|
+
fi
|
191
|
+
if [ ! -f $PID_FILE ]; then
|
192
|
+
sudo -u $USER -H $COMMAND >> $LOG_FILE 2>&1 &
|
193
|
+
RESULT=$?
|
194
|
+
logger -t "monit-sidekiq[$$]" "Started with pid $! and exit $RESULT"
|
195
|
+
echo $! > $PID_FILE
|
196
|
+
sleep .1
|
197
|
+
fi
|
198
|
+
unlock_and_exit_cleanly
|
199
|
+
;;
|
200
|
+
stop|quit)
|
201
|
+
legacy_fix
|
202
|
+
lock
|
203
|
+
SIG="INT"
|
204
|
+
[ -z "$GRACE_TIME" ] && GRACE_TIME=60
|
205
|
+
ALLOW_TIMEOUT=1
|
206
|
+
signal_worker
|
207
|
+
[ -e "$LOCK_FILE" ] && rm $LOCK_FILE
|
208
|
+
unlock_and_exit_cleanly
|
209
|
+
;;
|
210
|
+
*)
|
211
|
+
usage
|
212
|
+
exit_cleanly
|
213
|
+
;;
|
214
|
+
esac
|
215
|
+
else
|
216
|
+
echo "/data/$APP/current doesn't exist."
|
217
|
+
usage
|
218
|
+
fi
|
219
|
+
|
@@ -0,0 +1,22 @@
|
|
1
|
+
---
|
2
|
+
<% if @verbose %>
|
3
|
+
:verbose: <%= @verbose %>
|
4
|
+
<% end %>
|
5
|
+
<% if @environment %>
|
6
|
+
:environment: <%= @environment %>
|
7
|
+
<% end %>
|
8
|
+
<% if @require %>
|
9
|
+
:require: <%= @require %>
|
10
|
+
<% end %>
|
11
|
+
<% if @pidfile %>
|
12
|
+
:pidfile: <%= @pidfile %>
|
13
|
+
<% end %>
|
14
|
+
<% if @concurrency %>
|
15
|
+
:concurrency: <%= @concurrency %>
|
16
|
+
<% end %>
|
17
|
+
<% if @queues %>
|
18
|
+
:queues:
|
19
|
+
<% @queues.each do |name, priority| %>
|
20
|
+
- [<%= name %>, <%= priority %>]
|
21
|
+
<% end %>
|
22
|
+
<% end %>
|
metadata
CHANGED
@@ -1,19 +1,20 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eycloud-recipe-sidekiq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Dr Nic Williams
|
9
|
+
- Jesse Cooke
|
9
10
|
autorequire:
|
10
11
|
bindir: bin
|
11
12
|
cert_chain: []
|
12
|
-
date: 2012-03-
|
13
|
+
date: 2012-03-27 00:00:00.000000000 Z
|
13
14
|
dependencies:
|
14
15
|
- !ruby/object:Gem::Dependency
|
15
16
|
name: rake
|
16
|
-
requirement: &
|
17
|
+
requirement: &70286679065560 !ruby/object:Gem::Requirement
|
17
18
|
none: false
|
18
19
|
requirements:
|
19
20
|
- - ! '>='
|
@@ -21,7 +22,7 @@ dependencies:
|
|
21
22
|
version: '0'
|
22
23
|
type: :development
|
23
24
|
prerelease: false
|
24
|
-
version_requirements: *
|
25
|
+
version_requirements: *70286679065560
|
25
26
|
description: Sidekiq recipe for EY Cloud
|
26
27
|
email:
|
27
28
|
- drnicwilliams@gmail.com
|
@@ -35,15 +36,15 @@ files:
|
|
35
36
|
- README.md
|
36
37
|
- Rakefile
|
37
38
|
- eycloud-recipe-sidekiq.gemspec
|
38
|
-
- libraries/
|
39
|
+
- libraries/sidekiq_instances.rb
|
39
40
|
- metadata.json
|
40
41
|
- metadata.rb
|
41
42
|
- recipes/configure.rb
|
42
43
|
- recipes/default.rb
|
43
|
-
- recipes/install.rb
|
44
44
|
- recipes/restart.rb
|
45
|
-
-
|
46
|
-
-
|
45
|
+
- templates/default/monitrc.conf.erb
|
46
|
+
- templates/default/sidekiq.erb
|
47
|
+
- templates/default/sidekiq.yml.erb
|
47
48
|
homepage: ''
|
48
49
|
licenses: []
|
49
50
|
post_install_message:
|
@@ -58,7 +59,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
58
59
|
version: '0'
|
59
60
|
segments:
|
60
61
|
- 0
|
61
|
-
hash:
|
62
|
+
hash: 3781183210708579483
|
62
63
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
64
|
none: false
|
64
65
|
requirements:
|
@@ -67,7 +68,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
68
|
version: '0'
|
68
69
|
segments:
|
69
70
|
- 0
|
70
|
-
hash:
|
71
|
+
hash: 3781183210708579483
|
71
72
|
requirements: []
|
72
73
|
rubyforge_project:
|
73
74
|
rubygems_version: 1.8.17
|
@@ -1,21 +0,0 @@
|
|
1
|
-
class Chef
|
2
|
-
class Recipe
|
3
|
-
# Return which instance is to have redis installed on it
|
4
|
-
# This is determind as follows:
|
5
|
-
# 1. A utility prefixed with 'resque'
|
6
|
-
# 2. A solo
|
7
|
-
# Returns array of hash of instance data, including { "id" => "i-123456", }
|
8
|
-
def sidekiq_instances
|
9
|
-
@resque_instances ||= node[:engineyard][:environment][:instances].find do |x|
|
10
|
-
x[:role] == "solo" || node[:instance_role] == "eylocal" ||
|
11
|
-
(node[:role] == "util" && node[:name] == "sidekiq"
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
# Does this instance run resque?
|
16
|
-
def sidekiq_instance?
|
17
|
-
node[:instance_role] == "solo" || node[:instance_role] == "eylocal" ||
|
18
|
-
(node[:instance_role] == "util" && node[:name] == "sidekiq"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
data/recipes/install.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
#
|
2
|
-
# Cookbook Name:: sidekiq
|
3
|
-
# Recipe:: install
|
4
|
-
#
|
5
|
-
|
6
|
-
if sidekiq_instance?
|
7
|
-
|
8
|
-
template "/engineyard/bin/sidekiq" do
|
9
|
-
source "sidekiq.erb"
|
10
|
-
owner "root"
|
11
|
-
group "root"
|
12
|
-
mode 0655
|
13
|
-
variables({
|
14
|
-
:command_name => "sidekiq",
|
15
|
-
:command => "bundle exec sidekiq"
|
16
|
-
})
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
@@ -1,7 +0,0 @@
|
|
1
|
-
check process <%= "#{@app_name}_#{@command_name}" %>
|
2
|
-
with pidfile /var/run/engineyard/<%= @command_name %>/<%= @app_name %>/<%=@command_name %>.pid
|
3
|
-
start program = "/engineyard/bin/<%= "#{@command_name}" %>_wrapper <%= @app_name %> start"
|
4
|
-
stop program = "/engineyard/bin/<%= "#{@command_name}" %>_wrapper <%= @app_name %> stop"
|
5
|
-
# if mem > 200 MB for 2 cycles then restart
|
6
|
-
# if cpu > 100% for 2 cycles then restart
|
7
|
-
group <%= "#{@app_name}_#{@command_name}" %>
|
@@ -1,78 +0,0 @@
|
|
1
|
-
#!/bin/sh
|
2
|
-
#
|
3
|
-
# This script starts and stops the Sidekiq daemon
|
4
|
-
# This script belongs in /engineyard/bin/sidekiq
|
5
|
-
#
|
6
|
-
# Run the script as follows:
|
7
|
-
# /engineyard/bin/sidekiq app_name start|stop
|
8
|
-
#
|
9
|
-
|
10
|
-
# These variables are managed by Chef - modify them in recipes/default.rb
|
11
|
-
COMMAND_NAME="<%= @command_name %>" # Alpha-numeric characters and underscores only
|
12
|
-
COMMAND="sidekiq"
|
13
|
-
|
14
|
-
CURDIR=`pwd`
|
15
|
-
PATH=/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$PATH
|
16
|
-
|
17
|
-
RAILS_ROOT=/data/$1/current
|
18
|
-
|
19
|
-
PID_FILE=/var/run/engineyard/$COMMAND_NAME/$1/$COMMAND_NAME.pid
|
20
|
-
EXEC_LOG_FILE=/var/log/engineyard/$COMMAND_NAME/wrapper_$1.log
|
21
|
-
|
22
|
-
usage() {
|
23
|
-
echo "Usage: $0 <appname> {start|stop}"
|
24
|
-
exit 1
|
25
|
-
}
|
26
|
-
|
27
|
-
if [ $# -lt 2 ]; then usage; fi
|
28
|
-
|
29
|
-
if [ -d $RAILS_ROOT ]; then
|
30
|
-
mkdir -p /var/log/engineyard/$COMMAND_NAME/$1
|
31
|
-
mkdir -p /var/run/engineyard/$COMMAND_NAME/$1
|
32
|
-
|
33
|
-
# handle the second param, don't start if already existing
|
34
|
-
case "$2" in
|
35
|
-
start)
|
36
|
-
cd $RAILS_ROOT
|
37
|
-
echo "Starting $COMMAND_NAME"
|
38
|
-
if [ -f $PID_FILE ]; then
|
39
|
-
PID=`cat $PID_FILE`
|
40
|
-
if [ -d /proc/$PID ]; then
|
41
|
-
echo "$COMMAND_NAME is already running."
|
42
|
-
exit 1
|
43
|
-
fi
|
44
|
-
rm -f $PID_FILE
|
45
|
-
fi
|
46
|
-
exec $COMMAND 1>$EXEC_LOG_FILE 2>&1 <%= "&" if @run_in_background %>
|
47
|
-
<%= @run_in_background ? "echo $! > $PID_FILE;" : "echo $$ > $PID_FILE" %>
|
48
|
-
;;
|
49
|
-
stop)
|
50
|
-
GRACE_TIME=${GRACE_TIME:-40}
|
51
|
-
echo "Stopping $COMMAND_NAME"
|
52
|
-
if [ -f $PID_FILE ]; then
|
53
|
-
PID=`cat $PID_FILE`
|
54
|
-
kill $PID 2>/dev/null; true
|
55
|
-
SLEEP_COUNT=0
|
56
|
-
while [ -e /proc/$PID ]; do
|
57
|
-
sleep .25
|
58
|
-
let "SLEEP_COUNT+=1"
|
59
|
-
if(( "$SLEEP_COUNT" > $GRACE_TIME )); then
|
60
|
-
echo "Stop wait time exceeded. Killing..."
|
61
|
-
kill -9 $PID 2>/dev/null; true
|
62
|
-
break
|
63
|
-
fi
|
64
|
-
done
|
65
|
-
rm $PID_FILE
|
66
|
-
else
|
67
|
-
echo "No PID file found! Cannot stop $COMMAND_NAME"
|
68
|
-
fi
|
69
|
-
;;
|
70
|
-
*)
|
71
|
-
usage
|
72
|
-
;;
|
73
|
-
esac
|
74
|
-
else
|
75
|
-
echo "$RAILS_ROOT doesn't exist."
|
76
|
-
usage
|
77
|
-
fi
|
78
|
-
cd $CURDIR
|