Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#64) Allow service to be configured for non-Windows. #65

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ mcollective_agent_puppet::config:
windows_service: puppet
```

The service name can also be set using the `service` config. The `service` setting will be used instead of `windows_service` if `service` is defined.

```yaml
mcollective_agent_puppet::config:
service: puppet
```

The agent will by default invoke `command` to initiate a
run, passing through any applicable flags to adjust behavior. On
POSIX-compliant platforms where Puppet is already running in
Expand Down
3 changes: 2 additions & 1 deletion agent/puppet.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ def startup_hook
configfile = @config.pluginconf.fetch("puppet.config", nil)

@puppet_command = @config.pluginconf.fetch("puppet.command", default_agent_command)
@puppet_service = @config.pluginconf.fetch("puppet.windows_service", "puppet")
@windows_service = @config.pluginconf.fetch("puppet.windows_service", "puppet")
@puppet_service = @config.pluginconf.fetch("puppet.service", @windows_service)
@puppet_splaylimit = Integer(@config.pluginconf.fetch("puppet.splaylimit", 30))
@puppet_splay = Util.str_to_bool(@config.pluginconf.fetch("puppet.splay", "true"))
@puppet_agent = Util::PuppetAgentMgr.manager(configfile, @puppet_service)
Expand Down
10 changes: 9 additions & 1 deletion spec/agent/puppet_agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,21 @@
@agent.startup_hook
end

it "should set the service name based on the config" do
it "should set the windows service name based on the config" do
MCollective::Config.instance.stubs(:pluginconf).returns(
{"puppet.windows_service" => "not-puppet"})
MCollective::Util::PuppetAgentMgr.expects(:manager).with(nil, "not-puppet")

@agent.startup_hook
end

it "should set the service name based on the config" do
MCollective::Config.instance.stubs(:pluginconf).returns(
{"puppet.service" => "not-puppet"})
MCollective::Util::PuppetAgentMgr.expects(:manager).with(nil, "not-puppet")

@agent.startup_hook
end
end

describe "#default_agent_command" do
Expand Down
17 changes: 11 additions & 6 deletions spec/util/puppet_agent_mgr/mgr_v3_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,20 @@ module MCollective::Util
end

describe "#daemon_present?" do
it "should return false if the pidfile does not exist" do
File.expects(:exist?).with("pidfile").returns(false)
before :each do
@type = mock; @service = mock; @provider = mock
@service.stubs(:provider).returns(@provider)
@type.stubs(:new).returns(@service)
Puppet::Type.stubs(:type).returns(@type)
end

it "should return false if the service is not running" do
@provider.stubs(:status).returns(:stopped)
@manager.daemon_present?.should == false
end

it "should check the pid if the pidfile exist" do
File.expects(:exist?).with("pidfile").returns(true)
File.expects(:read).with("pidfile").returns(1)
@manager.expects(:has_process_for_pid?).with(1).returns(true)
it "should return true if the service is running" do
@provider.stubs(:status).returns(:running)
@manager.daemon_present?.should == true
end
end
Expand Down
7 changes: 7 additions & 0 deletions util/puppet_agent_mgr/mgr_v3.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ def disabled?
File.exist?(Puppet[:agent_disabled_lockfile])
end

# is the agent daemon currently running?
def daemon_present?
service = ::Puppet::Type.type(:service).new(name: @puppet_service)
status = service.provider.status
status.to_s == 'running'
end

private

def platform_applying?
Expand Down