LionAdmin 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +18 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +26 -0
- data/LICENSE +22 -0
- data/LionAdmin.gemspec +19 -0
- data/README.md +58 -0
- data/Rakefile +2 -0
- data/lib/LionAdmin.rb +5 -0
- data/lib/LionAdmin/base.rb +73 -0
- data/lib/LionAdmin/version.rb +3 -0
- data/spec/LionAdmin_spec.rb +5 -0
- data/spec/spec_helper.rb +2 -0
- metadata +81 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
LionAdmin (0.0.1)
|
5
|
+
plist
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.1.3)
|
11
|
+
plist (3.1.0)
|
12
|
+
rspec (2.11.0)
|
13
|
+
rspec-core (~> 2.11.0)
|
14
|
+
rspec-expectations (~> 2.11.0)
|
15
|
+
rspec-mocks (~> 2.11.0)
|
16
|
+
rspec-core (2.11.1)
|
17
|
+
rspec-expectations (2.11.2)
|
18
|
+
diff-lcs (~> 1.1.3)
|
19
|
+
rspec-mocks (2.11.2)
|
20
|
+
|
21
|
+
PLATFORMS
|
22
|
+
ruby
|
23
|
+
|
24
|
+
DEPENDENCIES
|
25
|
+
LionAdmin!
|
26
|
+
rspec
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Anurag Mohanty
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/LionAdmin.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/LionAdmin/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Anurag Mohanty"]
|
6
|
+
gem.email = ["anurag@columbia.edu"]
|
7
|
+
gem.description = %q{ruby wrapper to the serveradmin binary}
|
8
|
+
gem.summary = %q{ruby wrapper to the serveradmin binary}
|
9
|
+
gem.homepage = "https://github.com/tevren/LionAdmin"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "LionAdmin"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = LionAdmin::VERSION
|
17
|
+
gem.add_dependency "plist"
|
18
|
+
gem.add_development_dependency "rspec"
|
19
|
+
end
|
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# LionAdmin
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'LionAdmin'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install LionAdmin
|
18
|
+
|
19
|
+
|
20
|
+
To configure your Lion/Mountain Lion server for passwordless ssh-entry run the following commands on the L/ML server:
|
21
|
+
|
22
|
+
$ ssh-keygen -t rsa
|
23
|
+
|
24
|
+
This will prompt you for a location to save the keys, and a pass-phrase:
|
25
|
+
|
26
|
+
Generating public/private rsa key pair.
|
27
|
+
Enter file in which to save the key (/.ssh/id_rsa):
|
28
|
+
Enter passphrase (empty for no passphrase):
|
29
|
+
Enter same passphrase again:
|
30
|
+
Your identification has been saved in .ssh/id_rsa
|
31
|
+
Your public key has been saved in .ssh/id_rsa.pub
|
32
|
+
|
33
|
+
To configure the webserver to login to the L/ML server using the key you just generated, paste the contents of .ssh/id_rsa.pub to .ssh/authorized_keys on your webserver (in the rails user's directory)
|
34
|
+
Next we want to configure L/ML server to run the serveradmin binary without prompting for a password:
|
35
|
+
|
36
|
+
$ sudo su root
|
37
|
+
$ chmod 640 /etc/sudoers
|
38
|
+
$ emacs /etc/sudoers
|
39
|
+
|
40
|
+
Add the following lines to /etc/sudoers
|
41
|
+
|
42
|
+
# run serveradmin without password
|
43
|
+
RUBY_USER ALL=NOPASSWD: /Applications/Server.app/Contents/ServerRoot/usr/sbin/serveradmin
|
44
|
+
|
45
|
+
Where RUBY_USER is the name of the user that is ssh-ing to the server.
|
46
|
+
|
47
|
+
|
48
|
+
## Usage
|
49
|
+
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
1. Fork it
|
54
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
55
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
56
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
57
|
+
5. Create new Pull Request
|
58
|
+
|
data/Rakefile
ADDED
data/lib/LionAdmin.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'plist'
|
2
|
+
module LionAdmin
|
3
|
+
class Base
|
4
|
+
SERVER_ADMIN="/Applications/Server.app/Contents/ServerRoot/usr/sbin/serveradmin"
|
5
|
+
def initialize(user)
|
6
|
+
@user_prefix = "ssh #{user} sudo"
|
7
|
+
exit unless File.exists?(SERVER_ADMIN)
|
8
|
+
end
|
9
|
+
|
10
|
+
def version
|
11
|
+
version = %x[#{@user_prefix} #{SERVER_ADMIN} -v]
|
12
|
+
end
|
13
|
+
def services
|
14
|
+
services = %x[#{@user_prefix} #{SERVER_ADMIN} list].split("\n")
|
15
|
+
end
|
16
|
+
|
17
|
+
def fullstatus(service)
|
18
|
+
fullstatus = Plist::parse_xml(%x[#{@user_prefix} #{SERVER_ADMIN} fullstatus -x #{service}])
|
19
|
+
end
|
20
|
+
|
21
|
+
def status(service)
|
22
|
+
status = Plist::parse_xml(%x[#{@user_prefix} #{SERVER_ADMIN} status -x #{service}])
|
23
|
+
end
|
24
|
+
|
25
|
+
def settings(service)
|
26
|
+
settings = Plist::parse_xml(%x[#{@user_prefix} #{SERVER_ADMIN} settings -x #{service}])
|
27
|
+
end
|
28
|
+
|
29
|
+
def start_service(service)
|
30
|
+
if check_if_running(service)
|
31
|
+
return "service is already running..."
|
32
|
+
else
|
33
|
+
puts "starting service: #{service}..."
|
34
|
+
%x[#{@user_prefix} #{SERVER_ADMIN} start #{service}]
|
35
|
+
puts "service: #{service} started!"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def stop_service(service)
|
40
|
+
if check_if_running(service)
|
41
|
+
puts "stopping service: #{service}..."
|
42
|
+
%x[#{@user_prefix} #{SERVER_ADMIN} stop #{service}]
|
43
|
+
puts "service: #{service} stopped!"
|
44
|
+
else
|
45
|
+
return "service is already stopped"
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def run_command(service,command)
|
50
|
+
output = Plist::parse_xml(%x[#{@user_prefix} #{SERVER_ADMIN} command #{service}:command = #{command}])
|
51
|
+
if output.match("UNEXPECTED_COMMAND")
|
52
|
+
return "received unexpected command"
|
53
|
+
else
|
54
|
+
return output
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def change_settings(service,pref,value)
|
59
|
+
output_plist = Plist::parse_xml(%x[#{@user_prefix} #{SERVER_ADMIN} settings #{service}:#{pref} = #{value} -x])
|
60
|
+
return output_plist[pref]
|
61
|
+
end
|
62
|
+
|
63
|
+
def check_if_running(service)
|
64
|
+
status = status(service)
|
65
|
+
state = status["state"]
|
66
|
+
if state.match(/RUNNING/)
|
67
|
+
return true
|
68
|
+
else
|
69
|
+
return false
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: LionAdmin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Anurag Mohanty
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-23 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: plist
|
16
|
+
requirement: &70269315801120 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *70269315801120
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rspec
|
27
|
+
requirement: &70269315800700 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70269315800700
|
36
|
+
description: ruby wrapper to the serveradmin binary
|
37
|
+
email:
|
38
|
+
- anurag@columbia.edu
|
39
|
+
executables: []
|
40
|
+
extensions: []
|
41
|
+
extra_rdoc_files: []
|
42
|
+
files:
|
43
|
+
- .gitignore
|
44
|
+
- Gemfile
|
45
|
+
- Gemfile.lock
|
46
|
+
- LICENSE
|
47
|
+
- LionAdmin.gemspec
|
48
|
+
- README.md
|
49
|
+
- Rakefile
|
50
|
+
- lib/LionAdmin.rb
|
51
|
+
- lib/LionAdmin/base.rb
|
52
|
+
- lib/LionAdmin/version.rb
|
53
|
+
- spec/LionAdmin_spec.rb
|
54
|
+
- spec/spec_helper.rb
|
55
|
+
homepage: https://github.com/tevren/LionAdmin
|
56
|
+
licenses: []
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ! '>='
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: '0'
|
73
|
+
requirements: []
|
74
|
+
rubyforge_project:
|
75
|
+
rubygems_version: 1.8.10
|
76
|
+
signing_key:
|
77
|
+
specification_version: 3
|
78
|
+
summary: ruby wrapper to the serveradmin binary
|
79
|
+
test_files:
|
80
|
+
- spec/LionAdmin_spec.rb
|
81
|
+
- spec/spec_helper.rb
|