summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerdar Sutay <serdar@opscode.com>2014-03-21 14:14:37 -0700
committerSerdar Sutay <serdar@opscode.com>2014-03-21 14:14:37 -0700
commitb5c8ec3ea1fc826bd3935bda782fac810c825255 (patch)
tree8cf58a8e2eda459c4837d30e2fdcd05671a6d512
parented87bfe381e0c7ee6304cbfc551624ff34a6f3d2 (diff)
parent9ae81c74054418bb4319d9c7b07be641c485015d (diff)
downloadohai-b5c8ec3ea1fc826bd3935bda782fac810c825255.tar.gz
Merge pull request #301 from opscode/OHAI-420-2
OHAI-420: Add support for determining which package is running as init
-rw-r--r--CHANGELOG.md1
-rw-r--r--CONTRIBUTIONS.md1
-rw-r--r--lib/ohai/plugins/init_package.rb31
-rw-r--r--spec/unit/plugins/init_package_spec.rb50
4 files changed, 83 insertions, 0 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7974b4cc..fa347a0b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,7 @@
* ip6address detection failure logging is turned down to :debug.
* fe80:: link-local address is not reported as ip6addresses anymore.
* Private network information is now available as [:rackspace][:private_networks] on Rackspace nodes.
+* System init mechanism is now reported at [:init_package] on linux.
## Last Release: 7.0.0.rc.0 (01/20/2014)
diff --git a/CONTRIBUTIONS.md b/CONTRIBUTIONS.md
index 10a617f4..4f30f584 100644
--- a/CONTRIBUTIONS.md
+++ b/CONTRIBUTIONS.md
@@ -10,3 +10,4 @@ Example Contribution:
* **tas50**: Added additional cpu information to darwin platform.
* **mpasternacki**: Removed fe80:: link-local address from reported ip6addresses.
* **paulczar**: Added private network information for Rackspace nodes.
+* **ctennis**: Added init_package plugin which reports the init mechanism of the system on linux.
diff --git a/lib/ohai/plugins/init_package.rb b/lib/ohai/plugins/init_package.rb
new file mode 100644
index 00000000..ec7dc1ac
--- /dev/null
+++ b/lib/ohai/plugins/init_package.rb
@@ -0,0 +1,31 @@
+#
+# Author:: Caleb Tennis (<caleb.tennis@gmail.com>)
+# Copyright:: Copyright (c) 2012 Opscode, Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+Ohai.plugin(:InitPackage) do
+ provides "init_package"
+
+ collect_data(:linux) do
+ package_name = nil
+
+ if File.exists?("/proc/1/comm")
+ package_name = File.open("/proc/1/comm").gets.chomp
+ end
+
+ init_package package_name
+ end
+end
diff --git a/spec/unit/plugins/init_package_spec.rb b/spec/unit/plugins/init_package_spec.rb
new file mode 100644
index 00000000..0b19a664
--- /dev/null
+++ b/spec/unit/plugins/init_package_spec.rb
@@ -0,0 +1,50 @@
+#
+# Author:: Caleb Tennis (<caleb.tennis@gmail.com>)
+# Copyright:: Copyright (c) 2012 Opscode, Inc.
+# License:: Apache License, Version 2.0
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '/spec_helper.rb'))
+
+describe Ohai::System, "Init package" do
+ let(:plugin) {
+ p = get_plugin("init_package")
+ p.stub(:collect_os).and_return("linux")
+ p
+ }
+
+ let(:proc1_content) { "init\n" }
+ let(:proc_1_file_path) { "/proc/1/comm" }
+ let(:proc_1_file) { double(proc_1_file_path, :gets => proc1_content) }
+
+ before(:each) do
+ File.stub(:exists?).with(proc_1_file_path).and_return(true)
+ File.stub(:open).with(proc_1_file_path).and_return(proc_1_file)
+ end
+
+ it "should set init_package to init" do
+ plugin.run
+ plugin[:init_package].should == "init"
+ end
+
+ describe "when init_package is systemd" do
+ let(:proc1_content) { "systemd\n" }
+
+ it "should set init_package to systemd" do
+ plugin.run
+ plugin[:init_package].should == "systemd"
+ end
+ end
+end