rsense-server 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/Gemfile +14 -0
  4. data/Guardfile +5 -0
  5. data/LICENSE.txt +1 -0
  6. data/README.md +51 -0
  7. data/Rakefile +9 -0
  8. data/bin/_rsense.rb +115 -0
  9. data/config/puma.rb +2 -0
  10. data/lib/rsense/server/code.rb +38 -0
  11. data/lib/rsense/server/command/completion_result.rb +11 -0
  12. data/lib/rsense/server/command/special_meth.rb +18 -0
  13. data/lib/rsense/server/command/type_inference_method.rb +24 -0
  14. data/lib/rsense/server/command.rb +239 -0
  15. data/lib/rsense/server/config.rb +70 -0
  16. data/lib/rsense/server/gem_path.rb +18 -0
  17. data/lib/rsense/server/listeners/find_definition_event_listener.rb +91 -0
  18. data/lib/rsense/server/listeners/where_event_listener.rb +39 -0
  19. data/lib/rsense/server/load_path.rb +62 -0
  20. data/lib/rsense/server/options.rb +85 -0
  21. data/lib/rsense/server/parser.rb +17 -0
  22. data/lib/rsense/server/path_info.rb +17 -0
  23. data/lib/rsense/server/project.rb +24 -0
  24. data/lib/rsense/server/version.rb +5 -0
  25. data/lib/rsense/server.rb +18 -0
  26. data/rsense-server.gemspec +35 -0
  27. data/spec/fixtures/config_fixture/.rsense +4 -0
  28. data/spec/fixtures/deeply/nested/thing.rb +0 -0
  29. data/spec/fixtures/find_def_sample.json +10 -0
  30. data/spec/fixtures/sample.json +10 -0
  31. data/spec/fixtures/test_gem/.gitignore +22 -0
  32. data/spec/fixtures/test_gem/Gemfile +4 -0
  33. data/spec/fixtures/test_gem/LICENSE.txt +22 -0
  34. data/spec/fixtures/test_gem/README.md +29 -0
  35. data/spec/fixtures/test_gem/Rakefile +2 -0
  36. data/spec/fixtures/test_gem/lib/sample/version.rb +3 -0
  37. data/spec/fixtures/test_gem/lib/sample.rb +16 -0
  38. data/spec/fixtures/test_gem/sample.gemspec +23 -0
  39. data/spec/fixtures/test_gem/test.json +10 -0
  40. data/spec/rsense/server/code_spec.rb +44 -0
  41. data/spec/rsense/server/command/special_meth_spec.rb +23 -0
  42. data/spec/rsense/server/command_spec.rb +108 -0
  43. data/spec/rsense/server/config_spec.rb +27 -0
  44. data/spec/rsense/server/gem_path_spec.rb +16 -0
  45. data/spec/rsense/server/load_path_spec.rb +63 -0
  46. data/spec/rsense/server/options_spec.rb +33 -0
  47. data/spec/rsense/server/path_info_spec.rb +11 -0
  48. data/spec/rsense/server/project_spec.rb +18 -0
  49. data/spec/rsense/server_spec.rb +7 -0
  50. data/spec/spec_helper.rb +16 -0
  51. data/vendor/gems/puma-2.8.2-java/COPYING +55 -0
  52. data/vendor/gems/puma-2.8.2-java/DEPLOYMENT.md +92 -0
  53. data/vendor/gems/puma-2.8.2-java/Gemfile +17 -0
  54. data/vendor/gems/puma-2.8.2-java/History.txt +532 -0
  55. data/vendor/gems/puma-2.8.2-java/LICENSE +26 -0
  56. data/vendor/gems/puma-2.8.2-java/Manifest.txt +68 -0
  57. data/vendor/gems/puma-2.8.2-java/README.md +251 -0
  58. data/vendor/gems/puma-2.8.2-java/Rakefile +158 -0
  59. data/vendor/gems/puma-2.8.2-java/bin/puma +10 -0
  60. data/vendor/gems/puma-2.8.2-java/bin/puma-wild +17 -0
  61. data/vendor/gems/puma-2.8.2-java/bin/pumactl +12 -0
  62. data/vendor/gems/puma-2.8.2-java/docs/config.md +0 -0
  63. data/vendor/gems/puma-2.8.2-java/docs/nginx.md +80 -0
  64. data/vendor/gems/puma-2.8.2-java/docs/signals.md +42 -0
  65. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/PumaHttp11Service.java +17 -0
  66. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/ext_help.h +15 -0
  67. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/extconf.rb +8 -0
  68. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/http11_parser.c +1225 -0
  69. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/http11_parser.h +64 -0
  70. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/http11_parser.java.rl +161 -0
  71. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/http11_parser.rl +146 -0
  72. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/http11_parser_common.rl +54 -0
  73. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/io_buffer.c +155 -0
  74. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/mini_ssl.c +195 -0
  75. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/org/jruby/puma/Http11.java +225 -0
  76. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/org/jruby/puma/Http11Parser.java +488 -0
  77. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/org/jruby/puma/MiniSSL.java +289 -0
  78. data/vendor/gems/puma-2.8.2-java/ext/puma_http11/puma_http11.c +491 -0
  79. data/vendor/gems/puma-2.8.2-java/lib/puma/accept_nonblock.rb +23 -0
  80. data/vendor/gems/puma-2.8.2-java/lib/puma/app/status.rb +59 -0
  81. data/vendor/gems/puma-2.8.2-java/lib/puma/binder.rb +298 -0
  82. data/vendor/gems/puma-2.8.2-java/lib/puma/capistrano.rb +86 -0
  83. data/vendor/gems/puma-2.8.2-java/lib/puma/cli.rb +587 -0
  84. data/vendor/gems/puma-2.8.2-java/lib/puma/client.rb +289 -0
  85. data/vendor/gems/puma-2.8.2-java/lib/puma/cluster.rb +389 -0
  86. data/vendor/gems/puma-2.8.2-java/lib/puma/compat.rb +18 -0
  87. data/vendor/gems/puma-2.8.2-java/lib/puma/configuration.rb +377 -0
  88. data/vendor/gems/puma-2.8.2-java/lib/puma/const.rb +165 -0
  89. data/vendor/gems/puma-2.8.2-java/lib/puma/control_cli.rb +251 -0
  90. data/vendor/gems/puma-2.8.2-java/lib/puma/daemon_ext.rb +25 -0
  91. data/vendor/gems/puma-2.8.2-java/lib/puma/delegation.rb +11 -0
  92. data/vendor/gems/puma-2.8.2-java/lib/puma/detect.rb +4 -0
  93. data/vendor/gems/puma-2.8.2-java/lib/puma/events.rb +130 -0
  94. data/vendor/gems/puma-2.8.2-java/lib/puma/io_buffer.rb +7 -0
  95. data/vendor/gems/puma-2.8.2-java/lib/puma/java_io_buffer.rb +45 -0
  96. data/vendor/gems/puma-2.8.2-java/lib/puma/jruby_restart.rb +83 -0
  97. data/vendor/gems/puma-2.8.2-java/lib/puma/minissl.rb +148 -0
  98. data/vendor/gems/puma-2.8.2-java/lib/puma/null_io.rb +34 -0
  99. data/vendor/gems/puma-2.8.2-java/lib/puma/puma_http11.jar +0 -0
  100. data/vendor/gems/puma-2.8.2-java/lib/puma/rack_default.rb +7 -0
  101. data/vendor/gems/puma-2.8.2-java/lib/puma/rack_patch.rb +45 -0
  102. data/vendor/gems/puma-2.8.2-java/lib/puma/reactor.rb +183 -0
  103. data/vendor/gems/puma-2.8.2-java/lib/puma/runner.rb +146 -0
  104. data/vendor/gems/puma-2.8.2-java/lib/puma/server.rb +801 -0
  105. data/vendor/gems/puma-2.8.2-java/lib/puma/single.rb +102 -0
  106. data/vendor/gems/puma-2.8.2-java/lib/puma/tcp_logger.rb +32 -0
  107. data/vendor/gems/puma-2.8.2-java/lib/puma/thread_pool.rb +185 -0
  108. data/vendor/gems/puma-2.8.2-java/lib/puma/util.rb +9 -0
  109. data/vendor/gems/puma-2.8.2-java/lib/puma.rb +14 -0
  110. data/vendor/gems/puma-2.8.2-java/lib/rack/handler/puma.rb +66 -0
  111. data/vendor/gems/puma-2.8.2-java/puma.gemspec +55 -0
  112. data/vendor/gems/puma-2.8.2-java/test/test_app_status.rb +92 -0
  113. data/vendor/gems/puma-2.8.2-java/test/test_cli.rb +173 -0
  114. data/vendor/gems/puma-2.8.2-java/test/test_config.rb +26 -0
  115. data/vendor/gems/puma-2.8.2-java/test/test_http10.rb +27 -0
  116. data/vendor/gems/puma-2.8.2-java/test/test_http11.rb +144 -0
  117. data/vendor/gems/puma-2.8.2-java/test/test_integration.rb +165 -0
  118. data/vendor/gems/puma-2.8.2-java/test/test_iobuffer.rb +38 -0
  119. data/vendor/gems/puma-2.8.2-java/test/test_minissl.rb +25 -0
  120. data/vendor/gems/puma-2.8.2-java/test/test_null_io.rb +31 -0
  121. data/vendor/gems/puma-2.8.2-java/test/test_persistent.rb +238 -0
  122. data/vendor/gems/puma-2.8.2-java/test/test_puma_server.rb +323 -0
  123. data/vendor/gems/puma-2.8.2-java/test/test_rack_handler.rb +10 -0
  124. data/vendor/gems/puma-2.8.2-java/test/test_rack_server.rb +141 -0
  125. data/vendor/gems/puma-2.8.2-java/test/test_tcp_rack.rb +42 -0
  126. data/vendor/gems/puma-2.8.2-java/test/test_thread_pool.rb +156 -0
  127. data/vendor/gems/puma-2.8.2-java/test/test_unix_socket.rb +39 -0
  128. data/vendor/gems/puma-2.8.2-java/test/test_ws.rb +89 -0
  129. data/vendor/gems/puma-2.8.2-java/tools/jungle/README.md +9 -0
  130. data/vendor/gems/puma-2.8.2-java/tools/jungle/init.d/README.md +54 -0
  131. data/vendor/gems/puma-2.8.2-java/tools/jungle/init.d/puma +332 -0
  132. data/vendor/gems/puma-2.8.2-java/tools/jungle/init.d/run-puma +3 -0
  133. data/vendor/gems/puma-2.8.2-java/tools/jungle/upstart/README.md +61 -0
  134. data/vendor/gems/puma-2.8.2-java/tools/jungle/upstart/puma-manager.conf +31 -0
  135. data/vendor/gems/puma-2.8.2-java/tools/jungle/upstart/puma.conf +63 -0
  136. data/vendor/gems/puma-2.8.2-java/tools/trickletest.rb +45 -0
  137. metadata +389 -0
@@ -0,0 +1,332 @@
1
+ #! /bin/sh
2
+ ### BEGIN INIT INFO
3
+ # Provides: puma
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: Example initscript
9
+ # Description: This file should be used to construct scripts to be
10
+ # placed in /etc/init.d.
11
+ ### END INIT INFO
12
+
13
+ # Author: Darío Javier Cravero <dario@exordo.com>
14
+ #
15
+ # Do NOT "set -e"
16
+
17
+ # PATH should only include /usr/* if it runs after the mountnfs.sh script
18
+ PATH=/usr/local/bin:/usr/local/sbin/:/sbin:/usr/sbin:/bin:/usr/bin
19
+ DESC="Puma rack web server"
20
+ NAME=puma
21
+ DAEMON=$NAME
22
+ SCRIPTNAME=/etc/init.d/$NAME
23
+ CONFIG=/etc/puma.conf
24
+ JUNGLE=`cat $CONFIG`
25
+ RUNPUMA=/usr/local/bin/run-puma
26
+
27
+ # Load the VERBOSE setting and other rcS variables
28
+ . /lib/init/vars.sh
29
+
30
+ # Define LSB log_* functions.
31
+ # Depend on lsb-base (>= 3.0-6) to ensure that this file is present.
32
+ . /lib/lsb/init-functions
33
+
34
+ #
35
+ # Function that starts the jungle
36
+ #
37
+ do_start() {
38
+ log_daemon_msg "=> Running the jungle..."
39
+ for i in $JUNGLE; do
40
+ dir=`echo $i | cut -d , -f 1`
41
+ user=`echo $i | cut -d , -f 2`
42
+ config_file=`echo $i | cut -d , -f 3`
43
+ if [ "$config_file" = "" ]; then
44
+ config_file="$dir/config/puma.rb"
45
+ fi
46
+ log_file=`echo $i | cut -d , -f 4`
47
+ if [ "$log_file" = "" ]; then
48
+ log_file="$dir/log/puma.log"
49
+ fi
50
+ do_start_one $dir $user $config_file $log_file
51
+ done
52
+ }
53
+
54
+ do_start_one() {
55
+ PIDFILE=$1/tmp/puma/pid
56
+ if [ -e $PIDFILE ]; then
57
+ PID=`cat $PIDFILE`
58
+ # If the puma isn't running, run it, otherwise restart it.
59
+ if [ "`ps -A -o pid= | grep -c $PID`" -eq 0 ]; then
60
+ do_start_one_do $1 $2 $3 $4
61
+ else
62
+ do_restart_one $1
63
+ fi
64
+ else
65
+ do_start_one_do $1 $2 $3 $4
66
+ fi
67
+ }
68
+
69
+ do_start_one_do() {
70
+ log_daemon_msg "--> Woke up puma $1"
71
+ log_daemon_msg "user $2"
72
+ log_daemon_msg "log to $4"
73
+ start-stop-daemon --verbose --start --chdir $1 --chuid $2 --background --exec $RUNPUMA -- $1 $3 $4
74
+ }
75
+
76
+ #
77
+ # Function that stops the jungle
78
+ #
79
+ do_stop() {
80
+ log_daemon_msg "=> Putting all the beasts to bed..."
81
+ for i in $JUNGLE; do
82
+ dir=`echo $i | cut -d , -f 1`
83
+ do_stop_one $dir
84
+ done
85
+ }
86
+ #
87
+ # Function that stops the daemon/service
88
+ #
89
+ do_stop_one() {
90
+ log_daemon_msg "--> Stopping $1"
91
+ PIDFILE=$1/tmp/puma/pid
92
+ STATEFILE=$1/tmp/puma/state
93
+ if [ -e $PIDFILE ]; then
94
+ PID=`cat $PIDFILE`
95
+ if [ "`ps -A -o pid= | grep -c $PID`" -eq 0 ]; then
96
+ log_daemon_msg "---> Puma $1 isn't running."
97
+ else
98
+ log_daemon_msg "---> About to kill PID `cat $PIDFILE`"
99
+ pumactl --state $STATEFILE stop
100
+ # Many daemons don't delete their pidfiles when they exit.
101
+ rm -f $PIDFILE $STATEFILE
102
+ fi
103
+ else
104
+ log_daemon_msg "---> No puma here..."
105
+ fi
106
+ return 0
107
+ }
108
+
109
+ #
110
+ # Function that restarts the jungle
111
+ #
112
+ do_restart() {
113
+ for i in $JUNGLE; do
114
+ dir=`echo $i | cut -d , -f 1`
115
+ do_restart_one $dir
116
+ done
117
+ }
118
+
119
+ #
120
+ # Function that sends a SIGUSR2 to the daemon/service
121
+ #
122
+ do_restart_one() {
123
+ PIDFILE=$1/tmp/puma/pid
124
+ i=`grep $1 $CONFIG`
125
+ dir=`echo $i | cut -d , -f 1`
126
+
127
+ if [ -e $PIDFILE ]; then
128
+ log_daemon_msg "--> About to restart puma $1"
129
+ pumactl --state $dir/tmp/puma/state restart
130
+ # kill -s USR2 `cat $PIDFILE`
131
+ # TODO Check if process exist
132
+ else
133
+ log_daemon_msg "--> Your puma was never playing... Let's get it out there first"
134
+ user=`echo $i | cut -d , -f 2`
135
+ config_file=`echo $i | cut -d , -f 3`
136
+ if [ "$config_file" = "" ]; then
137
+ config_file="$dir/config/puma.rb"
138
+ fi
139
+ log_file=`echo $i | cut -d , -f 4`
140
+ if [ "$log_file" = "" ]; then
141
+ log_file="$dir/log/puma.log"
142
+ fi
143
+ do_start_one $dir $user $config_file $log_file
144
+ fi
145
+ return 0
146
+ }
147
+
148
+ #
149
+ # Function that statuss the jungle
150
+ #
151
+ do_status() {
152
+ for i in $JUNGLE; do
153
+ dir=`echo $i | cut -d , -f 1`
154
+ do_status_one $dir
155
+ done
156
+ }
157
+
158
+ #
159
+ # Function that sends a SIGUSR2 to the daemon/service
160
+ #
161
+ do_status_one() {
162
+ PIDFILE=$1/tmp/puma/pid
163
+ i=`grep $1 $CONFIG`
164
+ dir=`echo $i | cut -d , -f 1`
165
+
166
+ if [ -e $PIDFILE ]; then
167
+ log_daemon_msg "--> About to status puma $1"
168
+ pumactl --state $dir/tmp/puma/state stats
169
+ # kill -s USR2 `cat $PIDFILE`
170
+ # TODO Check if process exist
171
+ else
172
+ log_daemon_msg "--> $1 isn't there :(..."
173
+ fi
174
+ return 0
175
+ }
176
+
177
+ do_add() {
178
+ str=""
179
+ # App's directory
180
+ if [ -d "$1" ]; then
181
+ if [ "`grep -c "^$1" $CONFIG`" -eq 0 ]; then
182
+ str=$1
183
+ else
184
+ echo "The app is already being managed. Remove it if you want to update its config."
185
+ exit 1
186
+ fi
187
+ else
188
+ echo "The directory $1 doesn't exist."
189
+ exit 1
190
+ fi
191
+ # User to run it as
192
+ if [ "`grep -c "^$2:" /etc/passwd`" -eq 0 ]; then
193
+ echo "The user $2 doesn't exist."
194
+ exit 1
195
+ else
196
+ str="$str,$2"
197
+ fi
198
+ # Config file
199
+ if [ "$3" != "" ]; then
200
+ if [ -e $3 ]; then
201
+ str="$str,$3"
202
+ else
203
+ echo "The config file $3 doesn't exist."
204
+ exit 1
205
+ fi
206
+ fi
207
+ # Log file
208
+ if [ "$4" != "" ]; then
209
+ str="$str,$4"
210
+ fi
211
+
212
+ # Add it to the jungle
213
+ echo $str >> $CONFIG
214
+ log_daemon_msg "Added a Puma to the jungle: $str. You still have to start it though."
215
+ }
216
+
217
+ do_remove() {
218
+ if [ "`grep -c "^$1" $CONFIG`" -eq 0 ]; then
219
+ echo "There's no app $1 to remove."
220
+ else
221
+ # Stop it first.
222
+ do_stop_one $1
223
+ # Remove it from the config.
224
+ sed -i "\\:^$1:d" $CONFIG
225
+ log_daemon_msg "Removed a Puma from the jungle: $1."
226
+ fi
227
+ }
228
+
229
+ case "$1" in
230
+ start)
231
+ [ "$VERBOSE" != no ] && log_daemon_msg "Starting $DESC" "$NAME"
232
+ if [ "$#" -eq 1 ]; then
233
+ do_start
234
+ else
235
+ i=`grep $2 $CONFIG`
236
+ dir=`echo $i | cut -d , -f 1`
237
+ user=`echo $i | cut -d , -f 2`
238
+ config_file=`echo $i | cut -d , -f 3`
239
+ if [ "$config_file" = "" ]; then
240
+ config_file="$dir/config/puma.rb"
241
+ fi
242
+ log_file=`echo $i | cut -d , -f 4`
243
+ if [ "$log_file" = "" ]; then
244
+ log_file="$dir/log/puma.log"
245
+ fi
246
+ do_start_one $dir $user $config_file $log_file
247
+ fi
248
+ case "$?" in
249
+ 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
250
+ 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
251
+ esac
252
+ ;;
253
+ stop)
254
+ [ "$VERBOSE" != no ] && log_daemon_msg "Stopping $DESC" "$NAME"
255
+ if [ "$#" -eq 1 ]; then
256
+ do_stop
257
+ else
258
+ i=`grep $2 $CONFIG`
259
+ dir=`echo $i | cut -d , -f 1`
260
+ do_stop_one $dir
261
+ fi
262
+ case "$?" in
263
+ 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
264
+ 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
265
+ esac
266
+ ;;
267
+ status)
268
+ # TODO Implement.
269
+ log_daemon_msg "Status $DESC" "$NAME"
270
+ if [ "$#" -eq 1 ]; then
271
+ do_status
272
+ else
273
+ i=`grep $2 $CONFIG`
274
+ dir=`echo $i | cut -d , -f 1`
275
+ do_status_one $dir
276
+ fi
277
+ case "$?" in
278
+ 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
279
+ 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
280
+ esac
281
+ ;;
282
+ restart)
283
+ log_daemon_msg "Restarting $DESC" "$NAME"
284
+ if [ "$#" -eq 1 ]; then
285
+ do_restart
286
+ else
287
+ i=`grep $2 $CONFIG`
288
+ dir=`echo $i | cut -d , -f 1`
289
+ do_restart_one $dir
290
+ fi
291
+ case "$?" in
292
+ 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
293
+ 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
294
+ esac
295
+ ;;
296
+ add)
297
+ if [ "$#" -lt 3 ]; then
298
+ echo "Please, specifiy the app's directory and the user that will run it at least."
299
+ echo " Usage: $SCRIPTNAME add /path/to/app user /path/to/app/config/puma.rb /path/to/app/config/log/puma.log"
300
+ echo " config and log are optionals."
301
+ exit 1
302
+ else
303
+ do_add $2 $3 $4 $5
304
+ fi
305
+ case "$?" in
306
+ 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
307
+ 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
308
+ esac
309
+ ;;
310
+ remove)
311
+ if [ "$#" -lt 2 ]; then
312
+ echo "Please, specifiy the app's directory to remove."
313
+ exit 1
314
+ else
315
+ do_remove $2
316
+ fi
317
+ case "$?" in
318
+ 0|1) [ "$VERBOSE" != no ] && log_end_msg 0 ;;
319
+ 2) [ "$VERBOSE" != no ] && log_end_msg 1 ;;
320
+ esac
321
+ ;;
322
+ *)
323
+ echo "Usage:" >&2
324
+ echo " Run the jungle: $SCRIPTNAME {start|stop|status|restart}" >&2
325
+ echo " Add a Puma: $SCRIPTNAME add /path/to/app user /path/to/app/config/puma.rb /path/to/app/config/log/puma.log"
326
+ echo " config and log are optionals."
327
+ echo " Remove a Puma: $SCRIPTNAME remove /path/to/app"
328
+ echo " On a Puma: $SCRIPTNAME {start|stop|status|restart} PUMA-NAME" >&2
329
+ exit 3
330
+ ;;
331
+ esac
332
+ :
@@ -0,0 +1,3 @@
1
+ #!/bin/bash
2
+ app=$1; config=$2; log=$3;
3
+ cd $app && exec bundle exec puma -C $config 2>&1 >> $log
@@ -0,0 +1,61 @@
1
+ # Puma as a service using Upstart
2
+
3
+ Manage multiple Puma servers as services on the same box using Ubuntu upstart.
4
+
5
+ ## Installation
6
+
7
+ # Copy the scripts to services directory
8
+ sudo cp puma.conf puma-manager.conf /etc/init
9
+
10
+ # Create an empty configuration file
11
+ sudo touch /etc/puma.conf
12
+
13
+ ## Managing the jungle
14
+
15
+ Puma apps are referenced in /etc/puma.conf by default. Add each app's path as a new line, e.g.:
16
+
17
+ ```
18
+ /home/apps/my-cool-ruby-app
19
+ /home/apps/another-app/current
20
+ ```
21
+
22
+ Start the jungle running:
23
+
24
+ `sudo start puma-manager`
25
+
26
+ This script will run at boot time.
27
+
28
+ Start a single puma like this:
29
+
30
+ `sudo start puma app=/path/to/app`
31
+
32
+ ## Logs
33
+
34
+ Everything is logged by upstart, defaulting to `/var/log/upstart`.
35
+
36
+ Each puma instance is named after its directory, so for an app called `/home/apps/my-app` the log file would be `/var/log/upstart/puma-_home_apps_my-app.log`.
37
+
38
+ ## Conventions
39
+
40
+ * The script expects:
41
+ * a config file to exist under `config/puma.rb` in your app. E.g.: `/home/apps/my-app/config/puma.rb`.
42
+ * a temporary folder to put the PID, socket and state files to exist called `tmp/puma`. E.g.: `/home/apps/my-app/tmp/puma`. Puma will take care of the files for you.
43
+
44
+ You can always change those defaults by editing the scripts.
45
+
46
+ ## Here's what a minimal app's config file should have
47
+
48
+ ```
49
+ pidfile "/path/to/app/tmp/puma/pid"
50
+ state_path "/path/to/app/tmp/puma/state"
51
+ activate_control_app
52
+ ```
53
+
54
+ ## Before starting...
55
+
56
+ You need to customise `puma.conf` to:
57
+
58
+ * Set the right user your app should be running on unless you want root to execute it!
59
+ * Look for `setuid apps` and `setgid apps`, uncomment those lines and replace `apps` to whatever your deployment user is.
60
+ * Replace `apps` on the paths (or set the right paths to your user's home) everywhere else.
61
+ * Uncomment the source lines for `rbenv` or `rvm` support unless you use a system wide installation of Ruby.
@@ -0,0 +1,31 @@
1
+ # /etc/init/puma-manager.conf - manage a set of Pumas
2
+
3
+ # This example config should work with Ubuntu 12.04+. It
4
+ # allows you to manage multiple Puma instances with
5
+ # Upstart, Ubuntu's native service management tool.
6
+ #
7
+ # See puma.conf for how to manage a single Puma instance.
8
+ #
9
+ # Use "stop puma-manager" to stop all Puma instances.
10
+ # Use "start puma-manager" to start all instances.
11
+ # Use "restart puma-manager" to restart all instances.
12
+ # Crazy, right?
13
+ #
14
+
15
+ description "Manages the set of puma processes"
16
+
17
+ # This starts upon bootup and stops on shutdown
18
+ start on runlevel [2345]
19
+ stop on runlevel [06]
20
+
21
+ # Set this to the number of Puma processes you want
22
+ # to run on this machine
23
+ env PUMA_CONF="/etc/puma.conf"
24
+
25
+ pre-start script
26
+ for i in `cat $PUMA_CONF`; do
27
+ app=`echo $i | cut -d , -f 1`
28
+ logger -t "puma-manager" "Starting $app"
29
+ start puma app=$app
30
+ done
31
+ end script
@@ -0,0 +1,63 @@
1
+ # /etc/init/puma.conf - Puma config
2
+
3
+ # This example config should work with Ubuntu 12.04+. It
4
+ # allows you to manage multiple Puma instances with
5
+ # Upstart, Ubuntu's native service management tool.
6
+ #
7
+ # See workers.conf for how to manage all Puma instances at once.
8
+ #
9
+ # Save this config as /etc/init/puma.conf then manage puma with:
10
+ # sudo start puma app=PATH_TO_APP
11
+ # sudo stop puma app=PATH_TO_APP
12
+ # sudo status puma app=PATH_TO_APP
13
+ #
14
+ # or use the service command:
15
+ # sudo service puma {start,stop,restart,status}
16
+ #
17
+
18
+ description "Puma Background Worker"
19
+
20
+ # no "start on", we don't want to automatically start
21
+ stop on (stopping puma-manager or runlevel [06])
22
+
23
+ # change apps to match your deployment user if you want to use this as a less privileged user (recommended!)
24
+ setuid apps
25
+ setgid apps
26
+
27
+ respawn
28
+ respawn limit 3 30
29
+
30
+ instance ${app}
31
+
32
+ script
33
+ # this script runs in /bin/sh by default
34
+ # respawn as bash so we can source in rbenv/rvm
35
+ # quoted heredoc to tell /bin/sh not to interpret
36
+ # variables
37
+ exec /bin/bash <<'EOT'
38
+ # set HOME to the setuid user's home, there doesn't seem to be a better, portable way
39
+ export HOME="$(eval echo ~$(id -un))"
40
+
41
+ if [ -d "$HOME/.rbenv/bin" ]; then
42
+ export PATH="$HOME/.rbenv/bin:$HOME/.rbenv/shims:$PATH"
43
+ elif [ -f /etc/profile.d/rvm.sh ]; then
44
+ source /etc/profile.d/rvm.sh
45
+ elif [ -f /usr/local/rvm/scripts/rvm ]; then
46
+ source /etc/profile.d/rvm.sh
47
+ elif [ -f "$HOME/.rvm/scripts/rvm" ]; then
48
+ source "$HOME/.rvm/scripts/rvm"
49
+ elif [ -f /usr/local/share/chruby/chruby.sh ]; then
50
+ source /usr/local/share/chruby/chruby.sh
51
+ if [ -f /usr/local/share/chruby/auto.sh ]; then
52
+ source /usr/local/share/chruby/auto.sh
53
+ fi
54
+ # if you aren't using auto, set your version here
55
+ # chruby 2.0.0
56
+ fi
57
+
58
+ cd $app
59
+ logger -t puma "Starting server: $app"
60
+
61
+ exec bundle exec puma -C config/puma.rb
62
+ EOT
63
+ end script
@@ -0,0 +1,45 @@
1
+ require 'socket'
2
+ require 'stringio'
3
+
4
+ def do_test(st, chunk)
5
+ s = TCPSocket.new('127.0.0.1',ARGV[0].to_i);
6
+ req = StringIO.new(st)
7
+ nout = 0
8
+ randstop = rand(st.length / 10)
9
+ STDERR.puts "stopping after: #{randstop}"
10
+
11
+ begin
12
+ while data = req.read(chunk)
13
+ nout += s.write(data)
14
+ s.flush
15
+ sleep 0.1
16
+ if nout > randstop
17
+ STDERR.puts "BANG! after #{nout} bytes."
18
+ break
19
+ end
20
+ end
21
+ rescue Object => e
22
+ STDERR.puts "ERROR: #{e}"
23
+ ensure
24
+ s.close
25
+ end
26
+ end
27
+
28
+ content = "-" * (1024 * 240)
29
+ st = "GET / HTTP/1.1\r\nHost: www.zedshaw.com\r\nContent-Type: text/plain\r\nContent-Length: #{content.length}\r\n\r\n#{content}"
30
+
31
+ puts "length: #{content.length}"
32
+
33
+ threads = []
34
+ ARGV[1].to_i.times do
35
+ t = Thread.new do
36
+ size = 100
37
+ puts ">>>> #{size} sized chunks"
38
+ do_test(st, size)
39
+ end
40
+
41
+ t.abort_on_exception = true
42
+ threads << t
43
+ end
44
+
45
+ threads.each {|t| t.join}