rubypitaya 2.18.0 → 2.21.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rubypitaya/app-template/Gemfile +1 -1
  3. data/lib/rubypitaya/app-template/Gemfile.lock +7 -8
  4. data/lib/rubypitaya/app-template/Makefile +1 -1
  5. data/lib/rubypitaya/app-template/Rakefile +5 -10
  6. data/lib/rubypitaya/app-template/app/bll/player_bll.rb +1 -1
  7. data/lib/rubypitaya/app-template/app/config/initial_player.json +4 -1
  8. data/lib/rubypitaya/app-template/app/setup/rubypitaya.yml +27 -0
  9. data/lib/rubypitaya/app-template/bin/console +1 -2
  10. data/lib/rubypitaya/app-template/docker-compose.yml +0 -11
  11. data/lib/rubypitaya/app-template/docker/dev/Dockerfile +11 -6
  12. data/lib/rubypitaya/app-template/docker/entrypoint.sh +5 -4
  13. data/lib/rubypitaya/app-template/docker/prod/Dockerfile +16 -7
  14. data/lib/rubypitaya/app-template/docker/wait_for.sh +184 -0
  15. data/lib/rubypitaya/app-template/features/player.feature +1 -1
  16. data/lib/rubypitaya/app-template/helm/Chart.yaml +4 -0
  17. data/lib/rubypitaya/app-template/helm/templates/config-maps/nginx-config.yaml +9 -0
  18. data/lib/rubypitaya/app-template/helm/templates/deployments/connector.yaml +38 -0
  19. data/lib/rubypitaya/app-template/helm/templates/deployments/gameserver-nginx.yaml +40 -0
  20. data/lib/rubypitaya/app-template/helm/templates/deployments/rubypitaya.yaml +67 -0
  21. data/lib/rubypitaya/app-template/helm/templates/role-bindings/rubypitaya.yaml +12 -0
  22. data/lib/rubypitaya/app-template/helm/templates/roles/rubypitaya.yaml +31 -0
  23. data/lib/rubypitaya/app-template/helm/templates/service-accounts/rubypitaya.yaml +4 -0
  24. data/lib/rubypitaya/app-template/helm/templates/services/connector.yaml +13 -0
  25. data/lib/rubypitaya/app-template/helm/templates/services/etcd.yaml +18 -0
  26. data/lib/rubypitaya/app-template/helm/templates/services/gameserver-nginx.yaml +20 -0
  27. data/lib/rubypitaya/app-template/helm/templates/services/gameserver.yaml +20 -0
  28. data/lib/rubypitaya/app-template/helm/templates/services/nats.yaml +13 -0
  29. data/lib/rubypitaya/app-template/helm/templates/services/redis.yaml +14 -0
  30. data/lib/rubypitaya/app-template/helm/templates/services/rubypitaya.yaml +13 -0
  31. data/lib/rubypitaya/app-template/helm/templates/statefulsets/etcd.yaml +28 -0
  32. data/lib/rubypitaya/app-template/helm/templates/statefulsets/nats.yaml +26 -0
  33. data/lib/rubypitaya/app-template/helm/templates/statefulsets/redis.yaml +26 -0
  34. data/lib/rubypitaya/app-template/helm/values.yaml +36 -0
  35. data/lib/rubypitaya/app-template/kubernetes/deployment-rubypitaya.yaml +10 -14
  36. data/lib/rubypitaya/app-template/spec/player_handler_spec.rb +4 -3
  37. data/lib/rubypitaya/core/config.rb +10 -1
  38. data/lib/rubypitaya/core/database_config.rb +15 -10
  39. data/lib/rubypitaya/core/handler_base.rb +11 -0
  40. data/lib/rubypitaya/core/handler_router.rb +3 -11
  41. data/lib/rubypitaya/core/helpers/setup_helper.rb +1 -2
  42. data/lib/rubypitaya/core/http_routes.rb +33 -3
  43. data/lib/rubypitaya/core/main.rb +16 -13
  44. data/lib/rubypitaya/core/path.rb +0 -2
  45. data/lib/rubypitaya/core/setup.rb +10 -0
  46. data/lib/rubypitaya/core/spec-helpers/config_spec_helper.rb +2 -2
  47. data/lib/rubypitaya/core/spec-helpers/handler_spec_helper.rb +3 -1
  48. data/lib/rubypitaya/version.rb +1 -1
  49. metadata +37 -18
  50. data/lib/rubypitaya/app-template/app/setup/initial_player.yml +0 -2
  51. data/lib/rubypitaya/app-template/config/database.yml +0 -20
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 38d15208a32190c01690735d3d8433bb0f8cc9b6f71a64f7897ba668c21e4e97
4
- data.tar.gz: 7396c21b202d611ea5945fd9838b68323b4751777d3e154b20b31557ee470b7a
3
+ metadata.gz: 9505e2c4dbb300db345cff9e51d406c5f6b3c6f101c46105b8fa2e949b8c71bc
4
+ data.tar.gz: 9c1fb523cf378d6fa8bd7aa927611bfcd974b0583f22d8fdcbf3a3c71a438bec
5
5
  SHA512:
6
- metadata.gz: 6b70755f160f42aa9a145bf55c0709bb82ec92f1f2105874127439bdc286ea124e7f2093cdae34a377d595bb54e21e75af244d34cbd9c30f8feac08849db7d9a
7
- data.tar.gz: 50df16ee2575fd5840b0af30cfa3aedb9a7e4b35d27291a3a484ac2233b09b41700618ef9a1d8b2223cc1dba3e0cc0d8c7fc42a168971e548bd0301e34b77e7d
6
+ metadata.gz: 07c2486f386fef386ec1e002e57a2f723c6ff9f12e693d3c41abb322cf226cea49a9d5eab743f94ffb6d3b72627f48ef40716a03172d9ab58d53d0d53ca6f465
7
+ data.tar.gz: 6c2d3d381cb44074f9b4df501671c4a330e5c370b1b392e041a831d342615394dca786ed72d36de1673dbef45005c18aca0cb279d18f7f0011d0c833a2a8ca1a
@@ -1,6 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- gem 'rubypitaya', '2.18.0'
3
+ gem 'rubypitaya', '2.21.0'
4
4
 
5
5
  group :development do
6
6
  gem 'pry', '0.14.0'
@@ -50,14 +50,14 @@ GEM
50
50
  etcdv3 (0.10.2)
51
51
  grpc (~> 1.17)
52
52
  eventmachine (1.2.7)
53
- ffi (1.14.2)
54
- google-protobuf (3.15.3-x86_64-linux)
53
+ ffi (1.15.0)
54
+ google-protobuf (3.15.8)
55
55
  googleapis-common-protos-types (1.0.6)
56
56
  google-protobuf (~> 3.14)
57
- grpc (1.36.0-x86_64-linux)
58
- google-protobuf (~> 3.14)
57
+ grpc (1.37.0)
58
+ google-protobuf (~> 3.15)
59
59
  googleapis-common-protos-types (~> 1.0)
60
- i18n (1.8.9)
60
+ i18n (1.8.10)
61
61
  concurrent-ruby (~> 1.0)
62
62
  listen (3.4.1)
63
63
  rb-fsevent (~> 0.10, >= 0.10.3)
@@ -108,10 +108,9 @@ GEM
108
108
  rspec-support (~> 3.10.0)
109
109
  rspec-support (3.10.2)
110
110
  ruby2_keywords (0.0.4)
111
- rubypitaya (2.18.0)
111
+ rubypitaya (2.21.0)
112
112
  activerecord (= 6.1.3)
113
113
  etcdv3 (= 0.10.2)
114
- eventmachine (= 1.2.7)
115
114
  nats (= 0.11.0)
116
115
  ostruct (= 0.3.3)
117
116
  pg (= 1.2.3)
@@ -149,7 +148,7 @@ DEPENDENCIES
149
148
  listen (= 3.4.1)
150
149
  pry (= 0.14.0)
151
150
  rspec (= 3.10.0)
152
- rubypitaya (= 2.18.0)
151
+ rubypitaya (= 2.21.0)
153
152
 
154
153
  BUNDLED WITH
155
154
  2.1.4
@@ -41,7 +41,7 @@ test-cucumber:
41
41
  ## Update gems dependencies on Gemfile.lock
42
42
  update-dependencies:
43
43
  @rm -f Gemfile.lock
44
- @docker run --rm -v "$(PWD)":/usr/src/app -w /usr/src/app ruby:2.7.2 bundle install
44
+ @docker run --rm -v "$(PWD)":/usr/src/app -w /usr/src/app ruby:2.7.2-slim bundle install
45
45
 
46
46
  ## + Improve metagame
47
47
 
@@ -8,8 +8,7 @@ namespace :db do
8
8
 
9
9
  desc 'Create the database'
10
10
  task :create do
11
- environment_name = ENV.fetch("RUBYPITAYA_ENV") { 'development' }
12
- database_config = RubyPitaya::DatabaseConfig.new(environment_name, RubyPitaya::Path::DATABASE_CONFIG_PATH)
11
+ database_config = RubyPitaya::DatabaseConfig.new
13
12
  connection_data = database_config.connection_data_without_database
14
13
 
15
14
  ActiveRecord::Base.establish_connection(connection_data)
@@ -21,8 +20,7 @@ namespace :db do
21
20
 
22
21
  desc 'Migrate the database'
23
22
  task :migrate do
24
- environment_name = ENV.fetch("RUBYPITAYA_ENV") { 'development' }
25
- database_config = RubyPitaya::DatabaseConfig.new(environment_name, RubyPitaya::Path::DATABASE_CONFIG_PATH)
23
+ database_config = RubyPitaya::DatabaseConfig.new
26
24
  connection_data = database_config.connection_data
27
25
  migrations_paths = [RubyPitaya::Path::Core::MIGRATIONS_FOLDER_PATH]
28
26
  migrations_paths += RubyPitaya::Path::Plugins::MIGRATIONS_FOLDER_PATHS
@@ -38,8 +36,7 @@ namespace :db do
38
36
 
39
37
  desc 'Rollback migrations'
40
38
  task :rollback do
41
- environment_name = ENV.fetch("RUBYPITAYA_ENV") { 'development' }
42
- database_config = RubyPitaya::DatabaseConfig.new(environment_name, RubyPitaya::Path::DATABASE_CONFIG_PATH)
39
+ database_config = RubyPitaya::DatabaseConfig.new
43
40
  connection_data = database_config.connection_data
44
41
  migrations_paths = [RubyPitaya::Path::Core::MIGRATIONS_FOLDER_PATH]
45
42
  migrations_paths += RubyPitaya::Path::Plugins::MIGRATIONS_FOLDER_PATHS
@@ -64,8 +61,7 @@ namespace :db do
64
61
 
65
62
  desc 'Drop the database'
66
63
  task :drop do
67
- environment_name = ENV.fetch("RUBYPITAYA_ENV") { 'development' }
68
- database_config = RubyPitaya::DatabaseConfig.new(environment_name, RubyPitaya::Path::DATABASE_CONFIG_PATH)
64
+ database_config = RubyPitaya::DatabaseConfig.new
69
65
  connection_data = database_config.connection_data_without_database
70
66
 
71
67
  ActiveRecord::Base.establish_connection(connection_data)
@@ -78,8 +74,7 @@ namespace :db do
78
74
 
79
75
  desc 'migration status'
80
76
  task :status do
81
- environment_name = ENV.fetch("RUBYPITAYA_ENV") { 'development' }
82
- database_config = RubyPitaya::DatabaseConfig.new(environment_name, RubyPitaya::Path::DATABASE_CONFIG_PATH)
77
+ database_config = RubyPitaya::DatabaseConfig.new
83
78
  connection_data = database_config.connection_data
84
79
  migrations_paths = [RubyPitaya::Path::Core::MIGRATIONS_FOLDER_PATH]
85
80
  migrations_paths += RubyPitaya::Path::Plugins::MIGRATIONS_FOLDER_PATHS
@@ -2,7 +2,7 @@ class PlayerBLL
2
2
 
3
3
  def create_new_player(setup, config)
4
4
  name = config['initial_player'][:name]
5
- gold = setup['initial_player.wallet.gold']
5
+ gold = config['initial_player'][:wallet][:gold]
6
6
 
7
7
  player = Player.new(name: name, gold: gold, user: User.new)
8
8
  player.save!
@@ -1,3 +1,6 @@
1
1
  {
2
- "name": "Guest"
2
+ "name": "Guest",
3
+ "wallet": {
4
+ "gold": 10
5
+ }
3
6
  }
@@ -0,0 +1,27 @@
1
+ server:
2
+ name: 'rubypitaya'
3
+ environment: development
4
+
5
+ nats:
6
+ url: 'nats://nats:4222'
7
+
8
+ etcd:
9
+ url: 'http://etcd:2379'
10
+ prefix: 'rubypitaya/'
11
+ leaseSeconds: '60'
12
+
13
+ redis:
14
+ url: 'redis://redis:6379'
15
+
16
+ database:
17
+ host: 'db'
18
+ port: 5432
19
+ user: 'postgres'
20
+ password: 'postgres'
21
+ name: 'ruby_pitaya'
22
+
23
+ http:
24
+ auth:
25
+ user: 'user'
26
+ pass: 'pass'
27
+ enabled: 'false'
@@ -7,8 +7,7 @@ require 'rubypitaya'
7
7
  require 'rubypitaya/core/database_config'
8
8
 
9
9
  # Database connection
10
- environment_name = ENV.fetch("RUBYPITAYA_ENV") { 'development' }
11
- database_config = RubyPitaya::DatabaseConfig.new(environment_name, RubyPitaya::Path::DATABASE_CONFIG_PATH)
10
+ database_config = RubyPitaya::DatabaseConfig.new
12
11
  ActiveRecord::Base.establish_connection(database_config.connection_data)
13
12
  ActiveRecord::Base.logger = ActiveSupport::Logger.new(STDOUT)
14
13
  ActiveSupport::LogSubscriber.colorize_logging = true
@@ -60,18 +60,7 @@ services:
60
60
  ports:
61
61
  - '80:4567'
62
62
  environment:
63
- SERVER_NAME: 'rubypitaya'
64
- RUBYPITAYA_ENV: 'development'
65
63
  HISTFILE: '/app/rubypitaya/.bash-history'
66
- NATS_URL: 'nats://nats:4222'
67
- ETCD_URL: 'http://etcd:2379'
68
- ETCD_PREFIX: 'rubypitaya/'
69
- ETCD_LEASE_SECONDS: '60'
70
- REDIS_URL: 'redis://redis:6379'
71
- DATABASE_HOST: 'db'
72
- DATABASE_USER: 'postgres'
73
- DATABASE_PASSWORD: 'postgres'
74
- DATABASE_NAME: 'ruby_pitaya'
75
64
 
76
65
  rubypitaya-console:
77
66
  <<: *rubypitaya
@@ -1,19 +1,24 @@
1
- FROM ruby:2.7.2
1
+ FROM ruby:2.7.2-slim
2
2
 
3
3
  ENV LANG=C.UTF-8
4
4
  ENV LC_ALL=C.UTF-8
5
5
 
6
6
  RUN apt update && \
7
7
  apt install -y --no-install-recommends \
8
- docker.io \
9
- postgresql-client \
8
+ git \
9
+ netcat \
10
+ libpq-dev \
11
+ build-essential \
10
12
  && rm -rf /var/lib/apt/lists/*
11
13
 
12
- COPY Gemfile Gemfile.lock ./
14
+ WORKDIR /app/rubypitaya/
13
15
 
14
- RUN bundle install
16
+ COPY Gemfile Gemfile.lock ./
15
17
 
16
- WORKDIR /app/rubypitaya/
18
+ RUN bundle config --global jobs 4 && \
19
+ bundle config --global set clean 'true' \
20
+ bundle config --global git.allow_insecure true && \
21
+ bundle install
17
22
 
18
23
  COPY . .
19
24
 
@@ -3,10 +3,11 @@
3
3
  cmd="$@"
4
4
 
5
5
  echo "=> Waiting for postgres"
6
- until PGPASSWORD=$DATABASE_PASSWORD psql -h "$DATABASE_HOST" -U "$DATABASE_USER" -c '\q' > /dev/null 2>&1; do
7
- echo "=> Waiting for Postgres..."
8
- sleep 1
9
- done
6
+
7
+ RUBYPITAYA_DATABASE_HOST=${RUBYPITAYA_DATABASE_HOST:-'db'}
8
+ RUBYPITAYA_DATABASE_PORT=${RUBYPITAYA_DATABASE_PORT:-5432}
9
+
10
+ ./docker/wait_for.sh $RUBYPITAYA_DATABASE_HOST:$RUBYPITAYA_DATABASE_PORT
10
11
 
11
12
  echo "=> Postgres is ready"
12
13
 
@@ -1,16 +1,21 @@
1
- FROM ruby:2.7.2 as builder
1
+ FROM ruby:2.7.2-slim as builder
2
2
 
3
3
  RUN apt update && \
4
4
  apt install -y --no-install-recommends \
5
5
  curl \
6
+ libpq-dev \
7
+ build-essential \
6
8
  && rm -rf /var/lib/apt/lists/*
7
9
 
8
10
  COPY Gemfile Gemfile.lock ./
9
11
 
10
- RUN bundle config --local without "development test" && \
12
+ RUN bundle config --global jobs 4 && \
13
+ bundle config --global set clean 'true' \
14
+ bundle config --global git.allow_insecure true && \
15
+ bundle config --global without "development test" && \
11
16
  bundle install
12
17
 
13
- RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
18
+ # RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/amd64/kubectl
14
19
 
15
20
  FROM ruby:2.7.2-slim
16
21
 
@@ -19,13 +24,17 @@ ENV LC_ALL=C.UTF-8
19
24
 
20
25
  RUN apt update && \
21
26
  apt install -y --no-install-recommends \
22
- postgresql-client \
27
+ netcat \
28
+ libpq5 \
23
29
  && rm -rf /var/lib/apt/lists/*
24
30
 
25
31
  COPY --from=builder /usr/local/bundle /usr/local/bundle
26
- COPY --from=builder /kubectl /usr/local/bin/kubectl
27
-
28
- RUN chmod +x /usr/local/bin/kubectl
32
+ RUN rm -rf /usr/local/bundle/cache
33
+ RUN rm -rf /usr/local/bundle/build_info
34
+ RUN rm -rf /usr/local/bundle/doc
35
+
36
+ # COPY --from=builder /kubectl /usr/local/bin/kubectl
37
+ # RUN chmod +x /usr/local/bin/kubectl
29
38
 
30
39
  WORKDIR /app/rubypitaya/
31
40
 
@@ -0,0 +1,184 @@
1
+ #!/bin/sh
2
+
3
+ # The MIT License (MIT)
4
+ #
5
+ # Copyright (c) 2017 Eficode Oy
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the "Software"), to deal
9
+ # in the Software without restriction, including without limitation the rights
10
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the Software is
12
+ # furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included in all
15
+ # copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ # SOFTWARE.
24
+
25
+ set -- "$@" -- "$TIMEOUT" "$QUIET" "$PROTOCOL" "$HOST" "$PORT" "$result"
26
+ TIMEOUT=15
27
+ QUIET=0
28
+ # The protocol to make the request with, either "tcp" or "http"
29
+ PROTOCOL="tcp"
30
+
31
+ echoerr() {
32
+ if [ "$QUIET" -ne 1 ]; then printf "%s\n" "$*" 1>&2; fi
33
+ }
34
+
35
+ usage() {
36
+ exitcode="$1"
37
+ cat << USAGE >&2
38
+ Usage:
39
+ $cmdname host:port|url [-t timeout] [-- command args]
40
+ -q | --quiet Do not output any status messages
41
+ -t TIMEOUT | --timeout=timeout Timeout in seconds, zero for no timeout
42
+ -- COMMAND ARGS Execute command with args after the test finishes
43
+ USAGE
44
+ exit "$exitcode"
45
+ }
46
+
47
+ wait_for() {
48
+ case "$PROTOCOL" in
49
+ tcp)
50
+ if ! command -v nc >/dev/null; then
51
+ echoerr 'nc command is missing!'
52
+ exit 1
53
+ fi
54
+ ;;
55
+ wget)
56
+ if ! command -v wget >/dev/null; then
57
+ echoerr 'nc command is missing!'
58
+ exit 1
59
+ fi
60
+ ;;
61
+ esac
62
+
63
+ while :; do
64
+ case "$PROTOCOL" in
65
+ tcp)
66
+ nc -z "$HOST" "$PORT" > /dev/null 2>&1
67
+ ;;
68
+ http)
69
+ wget --timeout=1 -q "$HOST" -O /dev/null > /dev/null 2>&1
70
+ ;;
71
+ *)
72
+ echoerr "Unknown protocol '$PROTOCOL'"
73
+ exit 1
74
+ ;;
75
+ esac
76
+
77
+ result=$?
78
+
79
+ if [ $result -eq 0 ] ; then
80
+ if [ $# -gt 7 ] ; then
81
+ for result in $(seq $(($# - 7))); do
82
+ result=$1
83
+ shift
84
+ set -- "$@" "$result"
85
+ done
86
+
87
+ TIMEOUT=$2 QUIET=$3 PROTOCOL=$4 HOST=$5 PORT=$6 result=$7
88
+ shift 7
89
+ exec "$@"
90
+ fi
91
+ exit 0
92
+ fi
93
+
94
+ if [ "$TIMEOUT" -le 0 ]; then
95
+ break
96
+ fi
97
+ TIMEOUT=$((TIMEOUT - 1))
98
+
99
+ sleep 1
100
+ done
101
+ echo "Operation timed out" >&2
102
+ exit 1
103
+ }
104
+
105
+ while :; do
106
+ case "$1" in
107
+ http://*|https://*)
108
+ HOST="$1"
109
+ PROTOCOL="http"
110
+ shift 1
111
+ ;;
112
+ *:* )
113
+ HOST=$(printf "%s\n" "$1"| cut -d : -f 1)
114
+ PORT=$(printf "%s\n" "$1"| cut -d : -f 2)
115
+ shift 1
116
+ ;;
117
+ -q | --quiet)
118
+ QUIET=1
119
+ shift 1
120
+ ;;
121
+ -q-*)
122
+ QUIET=0
123
+ echoerr "Unknown option: $1"
124
+ usage 1
125
+ ;;
126
+ -q*)
127
+ QUIET=1
128
+ result=$1
129
+ shift 1
130
+ set -- -"${result#-q}" "$@"
131
+ ;;
132
+ -t | --timeout)
133
+ TIMEOUT="$2"
134
+ shift 2
135
+ ;;
136
+ -t*)
137
+ TIMEOUT="${1#-t}"
138
+ shift 1
139
+ ;;
140
+ --timeout=*)
141
+ TIMEOUT="${1#*=}"
142
+ shift 1
143
+ ;;
144
+ --)
145
+ shift
146
+ break
147
+ ;;
148
+ --help)
149
+ usage 0
150
+ ;;
151
+ -*)
152
+ QUIET=0
153
+ echoerr "Unknown option: $1"
154
+ usage 1
155
+ ;;
156
+ *)
157
+ QUIET=0
158
+ echoerr "Unknown argument: $1"
159
+ usage 1
160
+ ;;
161
+ esac
162
+ done
163
+
164
+ if ! [ "$TIMEOUT" -ge 0 ] 2>/dev/null; then
165
+ echoerr "Error: invalid timeout '$TIMEOUT'"
166
+ usage 3
167
+ fi
168
+
169
+ case "$PROTOCOL" in
170
+ tcp)
171
+ if [ "$HOST" = "" -o "$PORT" = "" ]; then
172
+ echoerr "Error: you need to provide a host and port to test."
173
+ usage 2
174
+ fi
175
+ ;;
176
+ http)
177
+ if [ "$HOST" = "" ]; then
178
+ echoerr "Error: you need to provide a host to test."
179
+ usage 2
180
+ fi
181
+ ;;
182
+ esac
183
+
184
+ wait_for "$@"