smartmachine 1.0.1 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -14
  3. data/lib/smart_machine/apps/container.rb +1 -0
  4. data/lib/smart_machine/apps/manager.rb +1 -1
  5. data/lib/smart_machine/base.rb +6 -0
  6. data/lib/smart_machine/buildpackers/buildpacker.rb +49 -1
  7. data/lib/smart_machine/buildpackers/rails.rb +87 -12
  8. data/lib/smart_machine/commands/grid.rb +8 -0
  9. data/lib/smart_machine/commands/grid_commands/elasticsearch.rb +0 -3
  10. data/lib/smart_machine/commands/grid_commands/nextcloud.rb +65 -0
  11. data/lib/smart_machine/commands/grid_commands/terminal.rb +107 -0
  12. data/lib/smart_machine/commands/machine.rb +8 -0
  13. data/lib/smart_machine/configuration.rb +23 -1
  14. data/lib/smart_machine/credentials.rb +9 -0
  15. data/lib/smart_machine/docker.rb +10 -9
  16. data/lib/smart_machine/engine.rb +44 -9
  17. data/lib/smart_machine/grids/nextcloud.rb +93 -0
  18. data/lib/smart_machine/grids/prereceiver/Dockerfile +10 -13
  19. data/lib/smart_machine/grids/redis.rb +8 -3
  20. data/lib/smart_machine/grids/redmine.rb +61 -0
  21. data/lib/smart_machine/grids/terminal/entrypoint.rb +95 -0
  22. data/lib/smart_machine/grids/terminal/haproxy.cfg +45 -0
  23. data/lib/smart_machine/grids/terminal/init.el +310 -0
  24. data/lib/smart_machine/grids/terminal/wetty.rb +44 -0
  25. data/lib/smart_machine/grids/terminal.rb +179 -0
  26. data/lib/smart_machine/machine.rb +26 -5
  27. data/lib/smart_machine/syncer.rb +11 -10
  28. data/lib/smart_machine/templates/dotsmartmachine/config/nextcloud.yml +27 -0
  29. data/lib/smart_machine/templates/dotsmartmachine/config/redis.yml +6 -1
  30. data/lib/smart_machine/templates/dotsmartmachine/config/terminal.yml +13 -0
  31. data/lib/smart_machine/templates/dotsmartmachine/grids/nginx/fastcgi.conf +1 -1
  32. data/lib/smart_machine/templates/dotsmartmachine/grids/nginx/nginx.tmpl +448 -314
  33. data/lib/smart_machine/version.rb +2 -2
  34. data/lib/smart_machine.rb +3 -1
  35. metadata +57 -24
  36. data/lib/smart_machine/buildpackers/rails/Dockerfile +0 -21
  37. data/lib/smart_machine/commands/grid_commands/scheduler.rb +0 -15
  38. data/lib/smart_machine/engine/Dockerfile +0 -30
  39. data/lib/smart_machine/grids/elasticsearch/.keep +0 -0
  40. data/lib/smart_machine/grids/minio/.keep +0 -0
  41. data/lib/smart_machine/grids/nginx/.keep +0 -0
  42. data/lib/smart_machine/grids/prereceiver/fcgiwrap/APKBUILD +0 -49
  43. data/lib/smart_machine/grids/prereceiver/fcgiwrap/fcgiwrap.confd +0 -6
  44. data/lib/smart_machine/grids/prereceiver/fcgiwrap/fcgiwrap.initd +0 -43
  45. data/lib/smart_machine/grids/prereceiver/fcgiwrap/fcgiwrap.pre-install +0 -7
  46. data/lib/smart_machine/grids/prereceiver/fcgiwrap/packages/main/x86_64/APKINDEX.tar.gz +0 -0
  47. data/lib/smart_machine/grids/prereceiver/fcgiwrap/packages/main/x86_64/fcgiwrap-1.1.1-r4.apk +0 -0
  48. data/lib/smart_machine/grids/prereceiver/fcgiwrap/packages/main/x86_64/fcgiwrap-doc-1.1.1-r4.apk +0 -0
  49. data/lib/smart_machine/grids/prereceiver/fcgiwrap/packages/main/x86_64/fcgiwrap-openrc-1.1.1-r4.apk +0 -0
  50. data/lib/smart_machine/grids/redis/.keep +0 -0
  51. data/lib/smart_machine/grids/scheduler/Dockerfile +0 -14
  52. data/lib/smart_machine/grids/scheduler.rb +0 -188
  53. data/lib/smart_machine/templates/dotsmartmachine/grids/scheduler/crontabs/.keep +0 -0
@@ -16,7 +16,7 @@ module SmartMachine
16
16
 
17
17
  module VERSION
18
18
  MAJOR = 1
19
- MINOR = 0
19
+ MINOR = 1
20
20
  TINY = 1
21
21
  PRE = nil
22
22
 
@@ -26,7 +26,7 @@ module SmartMachine
26
26
  module RUBY_VERSION
27
27
  MAJOR = 2
28
28
  MINOR = 7
29
- TINY = 0
29
+ TINY = 7
30
30
  PRE = nil
31
31
 
32
32
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
data/lib/smart_machine.rb CHANGED
@@ -25,11 +25,13 @@ require 'smart_machine/buildpackers/rails'
25
25
  require 'smart_machine/grids/elasticsearch'
26
26
  require 'smart_machine/grids/minio'
27
27
  require 'smart_machine/grids/mysql'
28
+ require 'smart_machine/grids/nextcloud'
28
29
  require 'smart_machine/grids/nginx'
29
30
  require 'smart_machine/grids/prereceiver'
30
31
  require 'smart_machine/grids/redis'
31
- # require 'smart_machine/grids/scheduler'
32
32
  # require 'smart_machine/grids/solr'
33
+ require 'smart_machine/grids/terminal/wetty'
34
+ require 'smart_machine/grids/terminal'
33
35
 
34
36
  module SmartMachine
35
37
  class Error < StandardError; end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smartmachine
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - plainsource
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-10-14 00:00:00.000000000 Z
11
+ date: 2023-03-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: net-ssh
@@ -24,6 +24,46 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '6.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ed25519
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '1.2'
34
+ - - "<"
35
+ - !ruby/object:Gem::Version
36
+ version: '2.0'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '1.2'
44
+ - - "<"
45
+ - !ruby/object:Gem::Version
46
+ version: '2.0'
47
+ - !ruby/object:Gem::Dependency
48
+ name: bcrypt_pbkdf
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '1.0'
54
+ - - "<"
55
+ - !ruby/object:Gem::Version
56
+ version: '2.0'
57
+ type: :runtime
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '1.0'
64
+ - - "<"
65
+ - !ruby/object:Gem::Version
66
+ version: '2.0'
27
67
  - !ruby/object:Gem::Dependency
28
68
  name: bcrypt
29
69
  requirement: !ruby/object:Gem::Requirement
@@ -133,7 +173,6 @@ files:
133
173
  - lib/smart_machine/base.rb
134
174
  - lib/smart_machine/buildpackers/buildpacker.rb
135
175
  - lib/smart_machine/buildpackers/rails.rb
136
- - lib/smart_machine/buildpackers/rails/Dockerfile
137
176
  - lib/smart_machine/commands.rb
138
177
  - lib/smart_machine/commands/app.rb
139
178
  - lib/smart_machine/commands/buildpacker.rb
@@ -144,11 +183,12 @@ files:
144
183
  - lib/smart_machine/commands/grid_commands/elasticsearch.rb
145
184
  - lib/smart_machine/commands/grid_commands/minio.rb
146
185
  - lib/smart_machine/commands/grid_commands/mysql.rb
186
+ - lib/smart_machine/commands/grid_commands/nextcloud.rb
147
187
  - lib/smart_machine/commands/grid_commands/nginx.rb
148
188
  - lib/smart_machine/commands/grid_commands/prereceiver.rb
149
189
  - lib/smart_machine/commands/grid_commands/redis.rb
150
- - lib/smart_machine/commands/grid_commands/scheduler.rb
151
190
  - lib/smart_machine/commands/grid_commands/sub_thor.rb
191
+ - lib/smart_machine/commands/grid_commands/terminal.rb
152
192
  - lib/smart_machine/commands/machine.rb
153
193
  - lib/smart_machine/commands/syncer.rb
154
194
  - lib/smart_machine/commands/utilities.rb
@@ -156,30 +196,17 @@ files:
156
196
  - lib/smart_machine/credentials.rb
157
197
  - lib/smart_machine/docker.rb
158
198
  - lib/smart_machine/engine.rb
159
- - lib/smart_machine/engine/Dockerfile
160
199
  - lib/smart_machine/grids/elasticsearch.rb
161
- - lib/smart_machine/grids/elasticsearch/.keep
162
200
  - lib/smart_machine/grids/minio.rb
163
- - lib/smart_machine/grids/minio/.keep
164
201
  - lib/smart_machine/grids/mysql.rb
165
202
  - lib/smart_machine/grids/mysql/docker-entrypoint-initdb.d/.keep
203
+ - lib/smart_machine/grids/nextcloud.rb
166
204
  - lib/smart_machine/grids/nginx.rb
167
- - lib/smart_machine/grids/nginx/.keep
168
205
  - lib/smart_machine/grids/prereceiver.rb
169
206
  - lib/smart_machine/grids/prereceiver/Dockerfile
170
- - lib/smart_machine/grids/prereceiver/fcgiwrap/APKBUILD
171
- - lib/smart_machine/grids/prereceiver/fcgiwrap/fcgiwrap.confd
172
- - lib/smart_machine/grids/prereceiver/fcgiwrap/fcgiwrap.initd
173
- - lib/smart_machine/grids/prereceiver/fcgiwrap/fcgiwrap.pre-install
174
- - lib/smart_machine/grids/prereceiver/fcgiwrap/packages/main/x86_64/APKINDEX.tar.gz
175
- - lib/smart_machine/grids/prereceiver/fcgiwrap/packages/main/x86_64/fcgiwrap-1.1.1-r4.apk
176
- - lib/smart_machine/grids/prereceiver/fcgiwrap/packages/main/x86_64/fcgiwrap-doc-1.1.1-r4.apk
177
- - lib/smart_machine/grids/prereceiver/fcgiwrap/packages/main/x86_64/fcgiwrap-openrc-1.1.1-r4.apk
178
207
  - lib/smart_machine/grids/prereceiver/pre-receive
179
208
  - lib/smart_machine/grids/redis.rb
180
- - lib/smart_machine/grids/redis/.keep
181
- - lib/smart_machine/grids/scheduler.rb
182
- - lib/smart_machine/grids/scheduler/Dockerfile
209
+ - lib/smart_machine/grids/redmine.rb
183
210
  - lib/smart_machine/grids/solr.rb
184
211
  - lib/smart_machine/grids/solr/config/.keep
185
212
  - lib/smart_machine/grids/solr/config/README.txt
@@ -344,6 +371,11 @@ files:
344
371
  - lib/smart_machine/grids/solr/docker-entrypoint-initdb.d/.keep
345
372
  - lib/smart_machine/grids/solr/sunspot/conf/schema.xml
346
373
  - lib/smart_machine/grids/solr/sunspot/conf/solrconfig.xml
374
+ - lib/smart_machine/grids/terminal.rb
375
+ - lib/smart_machine/grids/terminal/entrypoint.rb
376
+ - lib/smart_machine/grids/terminal/haproxy.cfg
377
+ - lib/smart_machine/grids/terminal/init.el
378
+ - lib/smart_machine/grids/terminal/wetty.rb
347
379
  - lib/smart_machine/logger.rb
348
380
  - lib/smart_machine/machine.rb
349
381
  - lib/smart_machine/scp.rb
@@ -357,15 +389,16 @@ files:
357
389
  - lib/smart_machine/templates/dotsmartmachine/config/minio.yml
358
390
  - lib/smart_machine/templates/dotsmartmachine/config/mysql.yml
359
391
  - lib/smart_machine/templates/dotsmartmachine/config/mysql/schedule.rb
392
+ - lib/smart_machine/templates/dotsmartmachine/config/nextcloud.yml
360
393
  - lib/smart_machine/templates/dotsmartmachine/config/prereceiver.yml
361
394
  - lib/smart_machine/templates/dotsmartmachine/config/redis.yml
395
+ - lib/smart_machine/templates/dotsmartmachine/config/terminal.yml
362
396
  - lib/smart_machine/templates/dotsmartmachine/config/users.yml
363
397
  - lib/smart_machine/templates/dotsmartmachine/gitignore-template
364
398
  - lib/smart_machine/templates/dotsmartmachine/grids/nginx/certificates/.keep
365
399
  - lib/smart_machine/templates/dotsmartmachine/grids/nginx/fastcgi.conf
366
400
  - lib/smart_machine/templates/dotsmartmachine/grids/nginx/htpasswd/.keep
367
401
  - lib/smart_machine/templates/dotsmartmachine/grids/nginx/nginx.tmpl
368
- - lib/smart_machine/templates/dotsmartmachine/grids/scheduler/crontabs/.keep
369
402
  - lib/smart_machine/templates/dotsmartmachine/grids/solr/solr/.keep
370
403
  - lib/smart_machine/templates/dotsmartmachine/tmp/.keep
371
404
  - lib/smart_machine/templates/dotsmartmachine/vendor/.keep
@@ -376,8 +409,8 @@ licenses:
376
409
  metadata:
377
410
  homepage_uri: https://github.com/plainsource/smartmachine
378
411
  bug_tracker_uri: https://github.com/plainsource/smartmachine/issues
379
- changelog_uri: https://github.com/plainsource/smartmachine/releases/tag/v1.0.1
380
- source_code_uri: https://github.com/plainsource/smartmachine/tree/v1.0.1
412
+ changelog_uri: https://github.com/plainsource/smartmachine/releases/tag/v1.1.1
413
+ source_code_uri: https://github.com/plainsource/smartmachine/tree/v1.1.1
381
414
  post_install_message:
382
415
  rdoc_options: []
383
416
  require_paths:
@@ -386,14 +419,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
386
419
  requirements:
387
420
  - - ">="
388
421
  - !ruby/object:Gem::Version
389
- version: 2.7.0
422
+ version: 2.7.7
390
423
  required_rubygems_version: !ruby/object:Gem::Requirement
391
424
  requirements:
392
425
  - - ">="
393
426
  - !ruby/object:Gem::Version
394
427
  version: 1.8.11
395
428
  requirements: []
396
- rubygems_version: 3.1.2
429
+ rubygems_version: 3.1.6
397
430
  signing_key:
398
431
  specification_version: 4
399
432
  summary: Full-stack deployment framework for Rails.
@@ -1,21 +0,0 @@
1
- ARG SMARTMACHINE_VERSION
2
-
3
- FROM smartmachine/smartengine:$SMARTMACHINE_VERSION
4
- LABEL maintainer="plainsource <plainsource@humanmind.me>"
5
-
6
- # Ruby on Rails Essentials
7
- RUN apk add --update build-base && \
8
- apk add --update tzdata && \
9
- apk add --update nodejs && \
10
- apk add --update yarn && \
11
- apk add --update mariadb-dev && \
12
- apk add --update imagemagick && \
13
- apk add --update ffmpeg && \
14
- apk add --update mupdf && \
15
- apk add --update mupdf-tools && \
16
- rm -rf /var/cache/apk/*
17
-
18
- # Gems
19
- RUN gem install bundler -v 2.1.4
20
-
21
- CMD ["smartmachine", "buildpacker", "packer", "rails"]
@@ -1,15 +0,0 @@
1
- module SmartMachine
2
- module Commands
3
- module GridCommands
4
- class Scheduler < SubThor
5
- include Utilities
6
-
7
- # def start
8
- # end
9
-
10
- # def stop
11
- # end
12
- end
13
- end
14
- end
15
- end
@@ -1,30 +0,0 @@
1
- FROM ruby:2.7.0-alpine3.11
2
- LABEL maintainer="plainsource <plainsource@humanmind.me>"
3
-
4
- # User
5
- # --- Fix to change docker gid to 998 (if it is in use) so that addgroup is free to create a group with docker gid.
6
- ARG USER_NAME
7
- ARG USER_UID
8
- ARG DOCKER_GID
9
- ARG DOCKER_GNAME
10
- RUN sed -i "s/$DOCKER_GID/998/" /etc/group && \
11
- adduser --disabled-password --gecos "" --uid "$USER_UID" "$USER_NAME" && \
12
- addgroup --gid "$DOCKER_GID" "$DOCKER_GNAME" && adduser "$USER_NAME" "$DOCKER_GNAME"
13
-
14
- # Essentials
15
- RUN apk add --update build-base && \
16
- apk add --update xz && \
17
- apk add --update docker && \
18
- apk add --update git && \
19
- apk add --update rsync && \
20
- rm -rf /var/cache/apk/*
21
-
22
- # smartmachine gem
23
- ARG SMARTMACHINE_VERSION
24
- COPY ./smartmachine-$SMARTMACHINE_VERSION.gem ./smartmachine-$SMARTMACHINE_VERSION.gem
25
- RUN gem install --no-document ./smartmachine-$SMARTMACHINE_VERSION.gem && \
26
- rm ./smartmachine-$SMARTMACHINE_VERSION.gem
27
-
28
- # smartmachine master key
29
- ARG SMARTMACHINE_MASTER_KEY
30
- ENV SMARTMACHINE_MASTER_KEY=$SMARTMACHINE_MASTER_KEY
File without changes
File without changes
File without changes
@@ -1,49 +0,0 @@
1
- # Contributor: Eivind Uggedal <eu@eju.no>
2
- # Maintainer: Natanael Copa <ncopa@alpinelinux.org>
3
- pkgname=fcgiwrap
4
- #pkgver=1.1.0
5
- pkgver=1.1.1
6
- #pkgrel=3
7
- pkgrel=4
8
- pkgdesc="Simple server for running CGI applications over FastCGI"
9
- # This url has been changed to add no_buffering feature for fcgiwrap where has not been currently merged by gnosek
10
- #url="https://github.com/gnosek/fcgiwrap"
11
- url="https://github.com/notr1ch/fcgiwrap"
12
- arch="all"
13
- license="MIT"
14
- pkgusers="fcgiwrap"
15
- pkggroups="www-data"
16
- install="$pkgname.pre-install"
17
- makedepends="$depends_dev autoconf libtool automake fcgi-dev"
18
- subpackages="$pkgname-doc $pkgname-openrc"
19
- # This source has been changed to add no_buffering feature for fcgiwrap where has not been currently merged by gnosek. Please note the use of master branch instead of $pkgver.
20
- #source="$pkgname-$pkgver.tar.gz::https://github.com/gnosek/$pkgname/archive/$pkgver.tar.gz
21
- source="$pkgname-$pkgver.tar.gz::https://github.com/notr1ch/$pkgname/archive/master.tar.gz
22
- $pkgname.initd
23
- $pkgname.confd"
24
-
25
- #builddir="$srcdir/$pkgname-$pkgver"
26
- builddir="$srcdir/$pkgname-master"
27
-
28
- build() {
29
- cd "$builddir"
30
- autoreconf --install
31
- CFLAGS="$CFLAGS -Wno-implicit-fallthrough" \
32
- ./configure --prefix=/usr \
33
- --mandir=/share/man \
34
- --sbindir=/bin
35
- make
36
- }
37
-
38
- package() {
39
- cd "$builddir"
40
- install -d -m2775 -o fcgiwrap -g www-data "$pkgdir"/run/fcgiwrap
41
- make DESTDIR="$pkgdir" install
42
- install -Dm755 $srcdir/$pkgname.initd "$pkgdir"/etc/init.d/$pkgname
43
- install -Dm644 $srcdir/$pkgname.confd "$pkgdir"/etc/conf.d/$pkgname
44
- }
45
-
46
-
47
- sha512sums="4ffacd247f48ff0827531da1e9fbf19262d51827668d90cde1ec30ea23139cdf6f45a3b2a955a2a3b8e9ddbc85e7e4fa4dd18217e71288441c8cabdff5c24846 fcgiwrap-1.1.1.tar.gz
48
- 0dbf5f4387e5dc5de6e9bd6d98247e175f1a7943fe1d04ea916881b1269fd0b62abfafac91f8c0dd2f4dc9c71118195ba9dd7cf9bb5e3d93e6e711ec7d770453 fcgiwrap.initd
49
- 893e9afa92c20c9d0dab68fffc806a1be1f2e28a7e73bbb497316386a9ee083be4bad68a90f660e489311a9812a512b50fb0edb8b9c49b12f6cd266ba53b01a6 fcgiwrap.confd"
@@ -1,6 +0,0 @@
1
- # set number of preforked children. defaults to number of system CPUs
2
- #nproc=$(nproc)
3
-
4
- # set listen socket. Defaults to unix:/run/fcgiwrap/fcgiwrap.sock
5
- #socket=unix:/run/fcgiwrap/fcgiwrap.sock
6
-
@@ -1,43 +0,0 @@
1
- #!/sbin/openrc-run
2
-
3
- name="fcgiwrap"
4
- description="fcgiwrap cgi daemon"
5
-
6
- command="/usr/bin/fcgiwrap"
7
- command_background="yes"
8
- user="fcgiwrap"
9
- group="www-data"
10
- : ${socket:=unix:/run/fcgiwrap/fcgiwrap.sock}
11
-
12
- depend() {
13
- need net localmount
14
- after firewall
15
- }
16
-
17
- start_pre() {
18
- command_args="-c ${nproc:-$(nproc)} -s $socket"
19
- case "$socket" in
20
- unix:/*)
21
- local socket_path=${socket#unix:}
22
- checkpath --directory --mode 2775 --owner ${user}:${group} \
23
- ${socket_path%/*}
24
- ;;
25
- esac
26
- }
27
-
28
- start() {
29
- ebegin "Starting ${name}"
30
- start-stop-daemon --exec ${command} \
31
- --background \
32
- -u ${user} -g ${group} \
33
- --start -- ${command_args}
34
- eend $?
35
- }
36
-
37
- stop_post() {
38
- case "$socket" in
39
- unix:/*)
40
- rm -f "${socket#unix:}"
41
- ;;
42
- esac
43
- }
@@ -1,7 +0,0 @@
1
- #!/bin/sh
2
-
3
- addgroup -S www-data 2>/dev/null
4
- adduser -S -D -H -h /var/run/fcgiwrap -s /sbin/nologin -G www-data \
5
- fcgiwrap 2>/dev/null
6
- exit 0
7
-
File without changes
@@ -1,14 +0,0 @@
1
- ARG SMARTMACHINE_VERSION
2
-
3
- FROM smartmachine:$SMARTMACHINE_VERSION
4
- LABEL maintainer="plainsource <plainsource@humanmind.me>"
5
-
6
- # Scheduler Essentials
7
- RUN apk add --update busybox-suid && \
8
- apk add --update bash && \
9
- rm -rf /var/cache/apk/*
10
-
11
- # Gems
12
- RUN gem install whenever -v 1.0.0
13
-
14
- CMD ["crond", "-f", "-l", "0", "-L", "/dev/stdout"]
@@ -1,188 +0,0 @@
1
- # The main SmartMachine Grids Scheduler driver
2
- module SmartMachine
3
- class Grids
4
- class Scheduler < SmartMachine::Base
5
-
6
- def initialize
7
- end
8
-
9
- def install
10
- puts "-----> Installing Scheduler"
11
-
12
- ssh = SmartMachine::SSH.new
13
- commands = ["smartmachine runner scheduler create"]
14
- ssh.run commands
15
-
16
- puts "-----> Scheduler Installation Complete"
17
- end
18
-
19
- def uninstall
20
- puts "-----> Uninstalling Scheduler"
21
-
22
- ssh = SmartMachine::SSH.new
23
- commands = ["smartmachine runner scheduler destroy"]
24
- ssh.run commands
25
-
26
- puts "-----> Scheduler Uninstallation Complete"
27
- end
28
-
29
- def update
30
- uninstall
31
- install
32
- end
33
-
34
- def create
35
- unless system("docker image inspect #{scheduler_image_name}", [:out, :err] => File::NULL)
36
- print "-----> Creating image #{scheduler_image_name} ... "
37
- if system("docker image build -t #{scheduler_image_name} \
38
- --build-arg SMARTMACHINE_VERSION=#{SmartMachine.version} \
39
- #{SmartMachine.config.root_path}/lib/smart_machine/grids/scheduler", out: File::NULL)
40
- puts "done"
41
-
42
- up
43
- end
44
- end
45
- end
46
-
47
- def destroy
48
- down
49
-
50
- if system("docker image inspect #{scheduler_image_name}", [:out, :err] => File::NULL)
51
- print "-----> Removing image #{scheduler_image_name} ... "
52
- if system("docker image rm #{scheduler_image_name}", out: File::NULL)
53
- puts "done"
54
- end
55
- end
56
- end
57
-
58
- def up
59
- if SmartMachine::Docker.running?
60
- if system("docker image inspect #{scheduler_image_name}", [:out, :err] => File::NULL)
61
- print "-----> Creating container scheduler with image #{scheduler_image_name} ... "
62
- if system("docker create \
63
- --name='scheduler' \
64
- --env MAILTO=#{SmartMachine.config.sysadmin_email} \
65
- --user `id -u` \
66
- --workdir /home/`id -un`/.smartmachine \
67
- --volume='#{SmartMachine.config.user_home_path}/.smartmachine/config:#{SmartMachine.config.user_home_path}/.smartmachine/config' \
68
- --volume='#{SmartMachine.config.user_home_path}/.smartmachine/grids/scheduler:#{SmartMachine.config.user_home_path}/.smartmachine/grids/scheduler' \
69
- --volume='#{SmartMachine.config.user_home_path}/.smartmachine/bin/smartmachine.sh:/usr/local/bundle/bin/smartmachine' \
70
- --volume='/var/run/docker.sock:/var/run/docker.sock:ro' \
71
- --restart='always' \
72
- #{scheduler_image_name}", out: File::NULL)
73
- puts "done"
74
-
75
- print "-----> Starting container scheduler with image #{scheduler_image_name} ... "
76
- if system("docker start scheduler", out: File::NULL)
77
- puts "done"
78
-
79
- restore_crontabs
80
- else
81
- puts "error"
82
- end
83
- end
84
- end
85
- end
86
- end
87
-
88
- def down
89
- if SmartMachine::Docker.running?
90
- # Stopping & Removing containers - in reverse order
91
- if system("docker inspect -f '{{.State.Running}}' 'scheduler'", [:out, :err] => File::NULL)
92
- print "-----> Stopping container scheduler with image #{scheduler_image_name} ... "
93
- if system("docker stop 'scheduler'", out: File::NULL)
94
- puts "done"
95
-
96
- print "-----> Removing container scheduler with image #{scheduler_image_name} ... "
97
- if system("docker rm 'scheduler'", out: File::NULL)
98
- puts "done"
99
- end
100
- end
101
- else
102
- puts "-----> Container 'scheduler' is currently not running."
103
- end
104
- end
105
- end
106
-
107
-
108
- def start(*args)
109
- args.flatten!
110
- type = args.empty? ? '--all' : args.shift
111
-
112
- self.class.running!
113
-
114
- if type == '--mysql'
115
- system("docker exec -i scheduler sh -c 'exec scheduler start --mysql'")
116
- end
117
- end
118
-
119
- def stop(*args)
120
- args.flatten!
121
- type = args.empty? ? '--all' : args.shift
122
-
123
- self.class.running!
124
-
125
- if type == '--mysql'
126
- system("docker exec -i scheduler sh -c 'exec scheduler stop --mysql'")
127
- end
128
- end
129
-
130
- def mysql(*args)
131
- args.flatten!
132
- action = args.empty? ? '' : args.shift
133
-
134
- return unless ['start', 'stop'].include? action
135
-
136
- command = "whenever --set 'output=#{SmartMachine.config.user_home_path}/.smartmachine/grids/scheduler/crontabs/crontabs.log' --load-file #{SmartMachine.config.user_home_path}/.smartmachine/config/mysql/schedule.rb"
137
-
138
- if action == 'start'
139
- command += " --update-crontab"
140
- action_text = "Starting"
141
- elsif action == 'stop'
142
- command += " --clear-crontab"
143
- action_text = "Stopping"
144
- end
145
-
146
- print "-----> #{action_text} automatic backup schedule for mysql ... "
147
- if system(command, out: File::NULL)
148
- puts "done"
149
- else
150
- puts "error"
151
- end
152
- ensure
153
- backup_crontabs
154
- end
155
-
156
- def scheduler_image_name
157
- "smartmachine/scheduler:#{SmartMachine.version}"
158
- end
159
-
160
- def restore_crontabs
161
- if system("docker exec scheduler sh -c 'exec test -f #{SmartMachine.config.user_home_path}/.smartmachine/grids/scheduler/crontabs/`id -un`'")
162
- print "-----> Restoring latest crontabs ... "
163
-
164
- if system("docker exec scheduler sh -c 'exec crontab - < #{SmartMachine.config.user_home_path}/.smartmachine/grids/scheduler/crontabs/`id -un`'")
165
- puts "done"
166
- else
167
- puts "error"
168
- end
169
- end
170
- end
171
-
172
- def backup_crontabs
173
- print "-----> Backing up latest crontabs ... "
174
- if system("crontab -l > #{SmartMachine.config.user_home_path}/.smartmachine/grids/scheduler/crontabs/`id -un`", out: File::NULL)
175
- puts "done"
176
- else
177
- puts "error"
178
- end
179
- end
180
-
181
- def self.running!
182
- unless system("docker inspect -f '{{.State.Running}}' 'scheduler'", [:out, :err] => File::NULL)
183
- raise "Scheduler is not running. Please start scheduler before scheduling"
184
- end
185
- end
186
- end
187
- end
188
- end