Skip to content

Commit

Permalink
(misc) Manage a wrapper for running ruby on Windows
Browse files Browse the repository at this point in the history
Inspired by choria-io#145 (comment)

When the agent_shim filenamed ends with '.bat', install a wrapper batch
file that run the actual '.rb' file; otherwise, just install the '.rb'
file and run it directly as before.
  • Loading branch information
smortex committed Jan 17, 2020
1 parent 70361b0 commit 2c4a110
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion data/os/windows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ choria::server_config:
classesfile: "C:/ProgramData/PuppetLabs/puppet/cache/state/classes.txt"
plugin.rpcaudit.logfile: "C:/ProgramData/choria/var/log/choria-audit.log"
plugin.yaml: "C:/ProgramData/choria/etc/generated-facts.yaml"
plugin.choria.agent_provider.mcorpc.agent_shim: "C:/Program Files/choria/bin/choria_mcollective_agent_compat.rb"
plugin.choria.agent_provider.mcorpc.agent_shim: "C:/Program Files/choria/bin/choria_mcollective_agent_compat.bat"
plugin.choria.agent_provider.mcorpc.config: "C:/ProgramData/choria/etc/choria-shim.cfg"
plugin.choria.agent_provider.mcorpc.libdir: "C:/ProgramData/choria/lib/plugins"
choria::rubypath: "C:/Program Files/Puppet Labs/Puppet/puppet/bin/ruby.exe"
Expand Down
18 changes: 17 additions & 1 deletion manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,28 @@
}

if "plugin.choria.agent_provider.mcorpc.agent_shim" in $choria::server_config and "plugin.choria.agent_provider.mcorpc.config" in $choria::server_config {
file{$choria::server_config["plugin.choria.agent_provider.mcorpc.agent_shim"]:
if $choria::server_config["plugin.choria.agent_provider.mcorpc.agent_shim"] =~ /\.bat$/ {
$agent_shim = $choria::server_config["plugin.choria.agent_provider.mcorpc.agent_shim"].regsubst(/\.bat$/, '.rb')
$agent_shim_wrapper = $choria::server_config["plugin.choria.agent_provider.mcorpc.agent_shim"]
} else {
$agent_shim = $choria::server_config["plugin.choria.agent_provider.mcorpc.agent_shim"]
$agent_shim_wrapper = undef
}

file{$agent_shim:
owner => $choria::config_user,
group => $choria::config_group,
mode => "0755",
content => epp("choria/choria_mcollective_agent_compat.rb.epp")
}
if $agent_shim_wrapper {
file{$agent_shim_wrapper:
owner => $choria::config_user,
group => $choria::config_group,
mode => "0755",
content => epp("choria/choria_mcollective_agent_compat.bat.epp")
}
}
}

if $choria::manage_server_config {
Expand Down
3 changes: 3 additions & 0 deletions templates/choria_mcollective_agent_compat.bat.epp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@echo off
setlocal
"<%= $choria::rubypath %>" -S -- "<%= $choria::server_config["plugin.choria.agent_provider.mcorpc.agent_shim"].regsubst(/\.bat$/, '.rb') %>" --config "<%= $choria::server_config_file %>" %*

0 comments on commit 2c4a110

Please sign in to comment.