forked from cheald/murmur-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage-dbus.rb
executable file
·74 lines (68 loc) · 1.63 KB
/
manage-dbus.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/env
require 'interfaces/dbus'
require 'helpers'
# DBus works with less overhead, but doesn't support remote management via Glacier2, or any of the newer stuff. Use Ice where possible.
$manager = Murmur::DBus::Manager.new
class UnknownCommandException < Exception; end
def print_options(server)
server.get_config.each do |key, val|
if %w"key certificate".include? key then
val = val.gsub(/[\r\n]/, "")[0..32] + "..."
end
pt(key, val)
end
end
def server_command(id, cmd, *args)
server = $manager.get_server(id)
case cmd
when "set"
key = args.shift
val = args.join(" ")
server[key] = val
puts "Server ID #{server.id}: #{key} set to #{val}"
server.restart!
puts "Server restarted"
when "start"
server.start!
when "stop"
server.stop!
when "supw"
pw = args.shift
raise "Cannot set a blank superuser password" if pw.nil? or pw == ""
server["superuser_password"] = pw
when "restart"
server.restart!
when "destroy"
server.destroy!
when "", "config", nil
print_options server
else
raise UnknownCommandException
end
end
def meta_command(command, *args)
case command
when "list"
pt "Server ID", "Running", 2
pt "---------", "------", 2
$manager.list_servers.each do |serverID|
server = $manager.get_server(serverID)
pt serverID, server.running?, 2
end
when "new"
server = $manager.create_server
puts "\nServer created. New ID is #{server.id}\n\nServer config:\n-------------\n"
print_options server
else
raise UnknownCommandException
end
end
begin
if (ARGV[0] || 0).to_i != 0 then
server_command(*ARGV)
else
meta_command(*ARGV)
end
rescue UnknownCommandException
help
end