Class: LionAdmin::Base
- Inherits:
-
Object
- Object
- LionAdmin::Base
- Defined in:
- lib/LionAdmin/base.rb
Constant Summary collapse
- SERVER_ADMIN =
"/usr/sbin/serveradmin"
Instance Method Summary collapse
- #change_settings(service, pref, value) ⇒ Object
- #check_if_running(service) ⇒ Object
- #fullstatus(service) ⇒ Object
- #get_running_services ⇒ Object
- #get_stopped_services ⇒ Object
-
#initialize(user) ⇒ Base
constructor
A new instance of Base.
- #run_command(service, command) ⇒ Object
- #services ⇒ Object
- #settings(service) ⇒ Object
- #start_service(service) ⇒ Object
- #status(service) ⇒ Object
- #stop_service(service) ⇒ Object
- #version ⇒ Object
Constructor Details
#initialize(user) ⇒ Base
Returns a new instance of Base.
9 10 11 12 |
# File 'lib/LionAdmin/base.rb', line 9 def initialize(user) @user_prefix = "ssh #{user} sudo" exit unless File.exists?(SERVER_ADMIN) end |
Instance Method Details
#change_settings(service, pref, value) ⇒ Object
84 85 86 87 |
# File 'lib/LionAdmin/base.rb', line 84 def change_settings(service,pref,value) output_plist = Plist::parse_xml(%x[#{@user_prefix} #{SERVER_ADMIN} settings #{service}:#{pref} = #{value} -x]) return output_plist[pref] end |
#check_if_running(service) ⇒ Object
89 90 91 92 93 94 95 96 97 |
# File 'lib/LionAdmin/base.rb', line 89 def check_if_running(service) status = status(service) if !service.nil? state = status["state"] if !status.nil? if !state.nil? && state.match(/RUNNING/) return true else return false end end |
#fullstatus(service) ⇒ Object
21 22 23 |
# File 'lib/LionAdmin/base.rb', line 21 def fullstatus(service) fullstatus = Plist::parse_xml(%x[#{@user_prefix} #{SERVER_ADMIN} fullstatus -x #{service}]) end |
#get_running_services ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/LionAdmin/base.rb', line 62 def get_running_services running_services = Array.new list_of_services = services list_of_services.each do |s| if check_if_running(s) running_services.push(s) end end return running_services end |
#get_stopped_services ⇒ Object
73 74 75 76 77 78 79 80 81 82 |
# File 'lib/LionAdmin/base.rb', line 73 def get_stopped_services stopped_services = Array.new list_of_services = services list_of_services.each do |s| unless check_if_running(s) stopped_services.push(s) end end return stopped_services end |
#run_command(service, command) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/LionAdmin/base.rb', line 53 def run_command(service,command) output = Plist::parse_xml(%x[#{@user_prefix} #{SERVER_ADMIN} command #{service}:command = #{command}]) if output.match("UNEXPECTED_COMMAND") return "received unexpected command" else return output end end |
#services ⇒ Object
17 18 19 |
# File 'lib/LionAdmin/base.rb', line 17 def services services = %x[#{@user_prefix} #{SERVER_ADMIN} list].split("\n") end |
#settings(service) ⇒ Object
29 30 31 |
# File 'lib/LionAdmin/base.rb', line 29 def settings(service) settings = Plist::parse_xml(%x[#{@user_prefix} #{SERVER_ADMIN} settings -x #{service}]) end |
#start_service(service) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'lib/LionAdmin/base.rb', line 33 def start_service(service) if check_if_running(service) return "service is already running..." else puts "starting service: #{service}..." %x[#{@user_prefix} #{SERVER_ADMIN} start #{service}] puts "service: #{service} started!" end end |
#status(service) ⇒ Object
25 26 27 |
# File 'lib/LionAdmin/base.rb', line 25 def status(service) status = Plist::parse_xml(%x[#{@user_prefix} #{SERVER_ADMIN} status -x #{service}]) end |
#stop_service(service) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/LionAdmin/base.rb', line 43 def stop_service(service) if check_if_running(service) puts "stopping service: #{service}..." %x[#{@user_prefix} #{SERVER_ADMIN} stop #{service}] puts "service: #{service} stopped!" else return "service is already stopped" end end |
#version ⇒ Object
14 15 16 |
# File 'lib/LionAdmin/base.rb', line 14 def version version = %x[#{@user_prefix} #{SERVER_ADMIN} -v] end |