Skip to content

Commit

Permalink
Adding first stage of support for upgrade/downgrade via url
Browse files Browse the repository at this point in the history
Support looks like it should work for upgrade/downgrade via URL.
I have not finished the web_ui part yet.
  • Loading branch information
asasfu committed Aug 8, 2015
1 parent 9354524 commit 8fbbf44
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
6 changes: 4 additions & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@
$acls = {},
) inherits consul::params {

$real_download_url = pick($download_url, "${download_url_base}${version}_${os}_${arch}.${download_extension}")
$real_ui_download_url = pick($ui_download_url, "${ui_download_url_base}${version}_web_ui.${ui_download_extension}")
$real_download_file = "${version}_${os}_${arch}.${download_extension}"
$real_ui_download_file = "${version}_web_ui.${ui_download_extension}"
$real_download_url = pick($download_url, "${download_url_base}${real_download_file}")
$real_ui_download_url = pick($ui_download_url, "${ui_download_url_base}${real_ui_download_file}")

validate_bool($purge_config_dir)
validate_bool($manage_user)
Expand Down
15 changes: 9 additions & 6 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,21 @@
if $::operatingsystem != 'darwin' {
ensure_packages(['unzip'])
}
staging::file { 'consul.zip':
Exec {
provider => shell
}
staging::file { "${consul::real_download_file}":
source => $consul::real_download_url
} ->
staging::extract { 'consul.zip':
target => $consul::bin_dir,
creates => "${consul::bin_dir}/consul",
staging::extract { "${consul::real_download_file}":
target => $consul::bin_dir,
onlyif => "test `consul version | grep -m1 -o [0-9\\.] | tr -d '\\n'` != ${consul::version}; unlessval=$?; if [ \$unlessval = 0 ]; then rm -f ${consul::bin_dir}/consul; fi; test \$unlessval = 0",

This comment has been minimized.

Copy link
@aj-jester

aj-jester Aug 8, 2015

We need to think about 2 things here:

  1. What if this is the very first consul install (consul has NEVER been installed before)? Would consul version error? what would happen then?
  2. If there is an existing installation of consul, we first need to ensure its stopped before deleting the binary.

This comment has been minimized.

Copy link
@asasfu

asasfu Aug 8, 2015

Author
  1. you're definitely right, that's why I asked you to look at it. It fails :( I'll fix that.
  2. I can actually delete it, unzip and then restart the service, no errors seem to be had.
} ->
file { "${consul::bin_dir}/consul":
owner => 'root',
group => 0, # 0 instead of root because OS X uses "wheel".
mode => '0555',
}
} ~> Service['consul']

This comment has been minimized.

Copy link
@aj-jester

aj-jester Aug 8, 2015

Notify the whole class } ~> Class['consul::run_service'] because if $consul::manage_service is false this would throw an exception during puppet run.

This comment has been minimized.

Copy link
@asasfu

asasfu Aug 8, 2015

Author

That's true as well. If I notify the class and manage_service is false then it will continue to run as a systemd (unmanaged) service until stopped or next boot. Though, I wonder if deleting the file while the service is running is bad for init systems other than systemd. So maybe in my onlyif line I will stop the service just before the rm...

This comment has been minimized.

Copy link
@aj-jester

aj-jester Aug 8, 2015

My vote is for stopping the service, it'll prevent weird edge cases and its just good practice 👍

This comment has been minimized.

Copy link
@asasfu

asasfu Aug 8, 2015

Author

That brings me to that unfortunate case where i'm in a shell prompt... and serializing puppet isn't in there, It's getting really ugly really quickly. before RM I would have to put a compiled version of a systemctl or service or whatever command depending on OS.... like
$system_stop_cmd = ? {
'systemd' => 'systemctl stop consul'
'sysv' => 'service consul stop'
etc.
}

This comment has been minimized.

Copy link
@aj-jester

aj-jester Aug 8, 2015

Thats a very good point. Then I guess we have no choice but to delete the binary without stopping the service, its not ideal but we don't really have another option here.

This comment has been minimized.

Copy link
@asasfu

asasfu Aug 8, 2015

Author

Ok, updated commit working for if it's not installed as well as new/old versions.
2b21d92


if ($consul::ui_dir and $consul::data_dir) {
file { "${consul::data_dir}/${consul::version}_web_ui":
Expand All @@ -38,7 +41,7 @@
group => 0, # 0 instead of root because OS X uses "wheel".
mode => '0755',
} ->
staging::deploy { 'consul_web_ui.zip':
staging::deploy { "${consul::real_ui_download_file}":
source => $consul::real_ui_download_url,
target => "${consul::data_dir}/${consul::version}_web_ui",
creates => "${consul::data_dir}/${consul::version}_web_ui/dist",
Expand Down

5 comments on commit 8fbbf44

@asasfu
Copy link
Author

@asasfu asasfu commented on 8fbbf44 Aug 8, 2015

Choose a reason for hiding this comment

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

The other option is to begin moving to the module that replaces staging which is archive or something, currently only version 0.3.0 and may not be stable.

@aj-jester
Copy link

Choose a reason for hiding this comment

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

@asasfu Honestly, if we can use archive that would be super awesome because Kyle (solarkennedy) and I spoke about this feature lots and we decided on archive because it makes things so much easier 😄

I will help you with this if you'd like, don't feel like you have to do all the work

@asasfu
Copy link
Author

@asasfu asasfu commented on 8fbbf44 Aug 8, 2015

Choose a reason for hiding this comment

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

Hehe :) That's good to hear. I actually only started working on Linux (other than some consulting requirements from time to time) about 5 months ago, same with Puppet. So this is me just going head down into it. I've done lots of puppet code in those 5 months too. I also just started programming as a job 5 months ago.

So I can look into converting to archive but it'll take some commit iterations to pull it off. I like this current module, it just had a few improvements :)

@aj-jester
Copy link

Choose a reason for hiding this comment

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

@asasfu Were you looking at https://forge.puppetlabs.com/camptocamp/archive? Their version seems to be 0.8.0 and it looks pretty stable https://github.com/camptocamp/puppet-archive

@asasfu
Copy link
Author

@asasfu asasfu commented on 8fbbf44 Aug 8, 2015

Choose a reason for hiding this comment

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

No I didn’t actually see that one. I saw puppet-community/puppet-archive

Please sign in to comment.