dockergsm 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/dockergsm +13 -4
- data/lib/dockergsm.rb +19 -9
- data/lib/games.yml +44 -4
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eab6a686b4bec781787445ea1cc8c9fe70046f66
|
4
|
+
data.tar.gz: d9ce95ca2c93e04f2bd8a57c26f78fb1f277adb6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4fb2a6b7835e1e33f79e555baf0a79e4f69069a8a2f4c7c737967844ee3849f004a0dff63979b306d00eb055c9db0f5141275b584df5741a7268003e35bd5bb
|
7
|
+
data.tar.gz: 4647b2e1dd96c6844f55b70e95ef249130988bd81b3d18d1d8c44e30179bc1c29b5dc4a7f6e5ea6093639a8b6d4d79361318806278737ec9332e016bc1cbf2df
|
data/bin/dockergsm
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require_relative '../lib/dockergsm.rb'
|
2
|
+
require 'dockergsm'
|
4
3
|
require 'thor'
|
4
|
+
require 'yaml'
|
5
5
|
|
6
6
|
# provide yes/no dialog
|
7
7
|
def yn_dialog(message, default = false)
|
@@ -39,19 +39,23 @@ class Engine < Thor
|
|
39
39
|
|
40
40
|
desc 'list', 'list supported servers'
|
41
41
|
def list
|
42
|
+
puts "GAME\tFULL NAME"
|
42
43
|
YAML.load_file("#{__dir__}/../lib/games.yml").each do |key, value|
|
43
|
-
puts "#{key}
|
44
|
+
puts "#{key}\t#{value['name']}"
|
44
45
|
end
|
45
46
|
end
|
46
47
|
|
47
48
|
desc 'create ID', 'create and start new server'
|
48
49
|
method_option :port, type: :numeric, aliases: '-p'
|
49
50
|
method_option :game, required: true, type: :string, aliases: '-g'
|
51
|
+
method_option :config, type: :string, aliases: '-o'
|
50
52
|
def create(id)
|
51
53
|
err_handler("Creating server #{id} (game: #{options.game})...",
|
52
54
|
"Successfully created server #{id}\n" \
|
53
55
|
"Run `dockergsm status #{id}` to view server status",
|
54
|
-
proc {
|
56
|
+
proc {
|
57
|
+
GSM.create(options.game, id, options.port, options.config)
|
58
|
+
})
|
55
59
|
end
|
56
60
|
|
57
61
|
desc 'start ID', 'start server'
|
@@ -62,6 +66,11 @@ class Engine < Thor
|
|
62
66
|
proc { GSM.start(id) })
|
63
67
|
end
|
64
68
|
|
69
|
+
desc 'console ID', 'open server console'
|
70
|
+
def console(id)
|
71
|
+
err_handler(false, false, proc { GSM.console(id) })
|
72
|
+
end
|
73
|
+
|
65
74
|
desc 'status ID', 'get status of server'
|
66
75
|
def status(id)
|
67
76
|
err_handler(false, false, proc { GSM.status(id) })
|
data/lib/dockergsm.rb
CHANGED
@@ -2,7 +2,7 @@ require 'json'
|
|
2
2
|
require 'yaml'
|
3
3
|
|
4
4
|
module GSM
|
5
|
-
def self.create(game, id, port)
|
5
|
+
def self.create(game, id, port, opt)
|
6
6
|
# check if game valid
|
7
7
|
configs = YAML.load_file("#{__dir__}/games.yml")
|
8
8
|
raise "game '#{game}' is not yet supported" unless configs.key? game
|
@@ -10,13 +10,12 @@ module GSM
|
|
10
10
|
# get server configs
|
11
11
|
config = configs[game]
|
12
12
|
port ||= config['port_default']
|
13
|
-
command = "docker run #{config['options']} " \
|
14
|
-
"#{config['port_opt'].
|
15
|
-
"--name #{id} #{config['image']}"
|
13
|
+
command = "docker run -e DOCKERGSM_IMAGE #{game} #{config['options']} " \
|
14
|
+
"#{config['port_opt'].gsub!('PORT', port.to_s)} " \
|
15
|
+
"--name #{id} #{config['image']} #{opt}"
|
16
16
|
|
17
17
|
# create server
|
18
|
-
|
19
|
-
p command
|
18
|
+
`#{command}`
|
20
19
|
raise 'failed to create server' unless $?.success?
|
21
20
|
end
|
22
21
|
|
@@ -26,14 +25,25 @@ module GSM
|
|
26
25
|
raise 'failed to start server' unless $?.success?
|
27
26
|
end
|
28
27
|
|
28
|
+
def self.console(id)
|
29
|
+
# get game type
|
30
|
+
data = `docker inspect -f '{{range .Config.Env}}{{println .}}{{end}}' #{id}`
|
31
|
+
raise "server #{id} does not exist" unless $?.success?
|
32
|
+
|
33
|
+
# run specific console
|
34
|
+
image = data.split(/\n/).find { |e| /DOCKERGSM_IMAGE/ =~ e }[16..-1]
|
35
|
+
config = YAML.load_file("#{__dir__}/games.yml")[image]
|
36
|
+
puts "INFO: exit the console with #{config['console_esc']}"
|
37
|
+
exec config['console'].sub!('ID', id)
|
38
|
+
end
|
39
|
+
|
29
40
|
def self.status(id)
|
30
41
|
# get inspect data
|
31
|
-
|
42
|
+
data = `docker inspect -f '{{.State.Status}}' #{id}`
|
32
43
|
raise "server #{id} does not exist" unless $?.success?
|
33
44
|
|
34
45
|
# output status
|
35
|
-
|
36
|
-
puts "Status of #{id}: #{data[0]['State']['Status']}"
|
46
|
+
puts "Status of #{id}: #{data}"
|
37
47
|
end
|
38
48
|
|
39
49
|
def self.stop(id)
|
data/lib/games.yml
CHANGED
@@ -1,14 +1,54 @@
|
|
1
1
|
mc:
|
2
|
-
name: Minecraft Java Edition
|
2
|
+
name: 'Minecraft: Java Edition'
|
3
3
|
image: itzg/minecraft-server
|
4
|
-
options: -e EULA=TRUE -d
|
4
|
+
options: -e EULA=TRUE -d -it
|
5
5
|
port_opt: -p PORT:25565
|
6
6
|
port_default: 25565
|
7
|
+
console: docker attach ID
|
8
|
+
console_esc: Ctrl-P, Ctrl-Q
|
7
9
|
repo: https://github.com/itzg/docker-minecraft-server
|
8
|
-
|
9
|
-
name: Minecraft Bedrock Edition
|
10
|
+
mcb:
|
11
|
+
name: 'Minecraft: Bedrock Edition'
|
10
12
|
image: itzg/minecraft-bedrock-server
|
11
13
|
options: -e EULA=TRUE -d
|
12
14
|
port_opt: -p PORT:19132/udp
|
13
15
|
port_default: 19132
|
16
|
+
console: docker attach ID
|
17
|
+
console_esc: Ctrl-P + Ctrl-Q
|
14
18
|
repo: https://github.com/itzg/docker-minecraft-bedrock-server
|
19
|
+
csgo:
|
20
|
+
name: 'Counter-Strike: Global Offensive'
|
21
|
+
image: gonzih/csgo-server
|
22
|
+
options: -d
|
23
|
+
port_opt: -p PORT:27015 -p PORT:27015/udp
|
24
|
+
port_default: 27015
|
25
|
+
console: docker exec -i ID rcon-cli
|
26
|
+
console_esc: Ctrl-C
|
27
|
+
repo: https://github.com/Gonzih/docker-csgo-server
|
28
|
+
tf2:
|
29
|
+
name: Team Fortress 2
|
30
|
+
image: gonzih/tf2-server
|
31
|
+
options: -d
|
32
|
+
port_opt: -p PORT:27015/udp
|
33
|
+
port_default: 27015
|
34
|
+
console: docker exec -i ID rcon-cli
|
35
|
+
console_esc: Ctrl-C
|
36
|
+
repo: https://github.com/Gonzih/docker-tf2-server
|
37
|
+
fact:
|
38
|
+
name: Factorio
|
39
|
+
image: factoriotools/factorio
|
40
|
+
options: -d -it
|
41
|
+
port_opt: -p PORT:34197/udp -p 27015:27015/tcp
|
42
|
+
port_default: 34197
|
43
|
+
console: docker attach ID
|
44
|
+
console_esc: Ctrl-P + Ctrl-Q
|
45
|
+
repo: https://github.com/factoriotools/factorio-docker
|
46
|
+
gmod:
|
47
|
+
name: Garry's Mod
|
48
|
+
image: suchipi/gmod-server
|
49
|
+
options: -d -it
|
50
|
+
port_opt: -p PORT:27015/udp
|
51
|
+
port_default: 27015
|
52
|
+
console: docker attach ID
|
53
|
+
console_esc: Ctrl-P + Ctrl-Q
|
54
|
+
repo: https://github.com/Gonzih/docker-tf2-server
|