Module: GSM
- Defined in:
- lib/dockergsm.rb
Class Method Summary collapse
- .console(id) ⇒ Object
- .create(game, id, port, opt) ⇒ Object
- .delete(id) ⇒ Object
- .start(id) ⇒ Object
- .status(id) ⇒ Object
- .stop(id) ⇒ Object
Class Method Details
.console(id) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/dockergsm.rb', line 28 def self.console(id) # get game type data = `docker inspect -f '{{range .Config.Env}}{{println .}}{{end}}' #{id}` raise "server #{id} does not exist" unless $?.success? # run specific console image = data.split(/\n/).find { |e| /DOCKERGSM_IMAGE/ =~ e }[16..-1] config = YAML.load_file("#{__dir__}/games.yml")[image] puts "INFO: exit the console with #{config['console_esc']}" exec config['console'].sub!('ID', id) end |
.create(game, id, port, opt) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/dockergsm.rb', line 5 def self.create(game, id, port, opt) # check if game valid configs = YAML.load_file("#{__dir__}/games.yml") raise "game '#{game}' is not yet supported" unless configs.key? game # get server configs config = configs[game] port ||= config['port_default'] command = "docker run -e DOCKERGSM_IMAGE #{game} #{config['options']} " \ "#{config['port_opt'].gsub!('PORT', port.to_s)} " \ "--name #{id} #{config['image']} #{opt}" # create server `#{command}` raise 'failed to create server' unless $?.success? end |
.delete(id) ⇒ Object
55 56 57 58 59 |
# File 'lib/dockergsm.rb', line 55 def self.delete(id) # delete server `docker rm #{id}` raise 'failed to delete server' unless $?.success? end |
.start(id) ⇒ Object
22 23 24 25 26 |
# File 'lib/dockergsm.rb', line 22 def self.start(id) # start server `docker start #{id}` raise 'failed to start server' unless $?.success? end |
.status(id) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'lib/dockergsm.rb', line 40 def self.status(id) # get inspect data data = `docker inspect -f '{{.State.Status}}' #{id}` raise "server #{id} does not exist" unless $?.success? # output status puts "Status of #{id}: #{data}" end |
.stop(id) ⇒ Object
49 50 51 52 53 |
# File 'lib/dockergsm.rb', line 49 def self.stop(id) # stop server `docker stop #{id}` raise 'failed to stop server' unless $?.success? end |