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

Fix windows_service so it works correctly #266

Merged
merged 1 commit into from
Jun 20, 2016
Merged
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
9 changes: 5 additions & 4 deletions manifests/windows_service.pp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@

$app_dir = regsubst($consul::bin_dir, '\/', '\\', 'G')
$app_exec = "${app_dir}\\consul.exe"
$agent_args = regsubst($consul::config_dir, '\/', '\\', 'G')
$app_args = "agent -config-dir=${agent_args}"
$configdir_args = regsubst($consul::config_dir, '\/', '\\', 'G')
$datadir_args = regsubst($consul::data_dir, '\/', '\\', 'G')
$app_args = "agent -config-dir=${configdir_args} -data-dir=${datadir_args}"
$app_log = "${app_dir}\\logs\\consul.log"

include '::archive'
Expand All @@ -39,7 +40,7 @@
}->
exec { 'consul_service_install':
cwd => $consul::bin_dir,
command => "${nssm_exec} install Consul ${app_exec}",
command => "${nssm_exec} install Consul \"${app_exec}\"",
unless => 'get-service -name consul',
logoutput => true,
provider => 'powershell',
Expand All @@ -52,7 +53,7 @@
} ->
exec { 'consul_service_set_parameters':
cwd => $consul::bin_dir,
command => "${consul::bin_dir}/set_service_parameters.ps1",
command => "& \"${consul::bin_dir}/set_service_parameters.ps1\"",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you describe the "&" prepend thing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ampersand (the 'and' sign) here tells PowerShell to execute that command, instead of treating it as a cmdlet or a string. The backticks (the funny looking single-quotes) are there to escape the following character, similar to the " in C-based languages, or double-double-quotes ("") in VB. Otherwise the " character will end the string and the parser will cry when it can't understand what you're trying to say after that. (You can alternatively use single-quotes instead in this case, as I have in the previous example.)
http://edgylogic.com/blog/powershell-and-external-commands-done-right/
Just want to ensure this is executed as a command inside powershell, this is the way to force it to do so

refreshonly => true,
logoutput => true,
provider => 'powershell',
Expand Down