Skip to content

Commit

Permalink
[sup] Honor HAB_RING for start subcommand.
Browse files Browse the repository at this point in the history
This change introduces an optional way to set the Ring name when a
Supervisor starts via setting a `HAB_RING` environment variable. The
environment variable will always be overrident if the user uses an
explicit `--ring` option on start, meaning that a CLI arugment is always
first priority and environment variable is secondary.

Current explicit behavior:

    hab-sup start --ring possums core/redis

New, alternative use with an environment variable:

    env HAB_RING=possums hab-sup start core/redis

Signed-off-by: Fletcher Nichol <[email protected]>

Pull request: #485
Approved by: reset
  • Loading branch information
fnichol authored and jtimberman committed Jun 12, 2016
1 parent d7a5fe6 commit 98107bc
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions components/sup/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ const VERSION: &'static str = include_str!(concat!(env!("OUT_DIR"), "/VERSION"))
static DEFAULT_GROUP: &'static str = "default";
static DEFAULT_GOSSIP_LISTEN: &'static str = "0.0.0.0:9634";

static RING_ENVVAR: &'static str = "HAB_RING";

/// Creates a [Config](config/struct.Config.html) from global args
/// and subcommand args.
fn config_from_args(args: &ArgMatches, subcommand: &str, sub_args: &ArgMatches) -> Result<Config> {
Expand Down Expand Up @@ -133,8 +135,17 @@ fn config_from_args(args: &ArgMatches, subcommand: &str, sub_args: &ArgMatches)
config.set_file_path(fp.to_string());
}
config.set_version_number(value_t!(sub_args, "version-number", u64).unwrap_or(0));
if let Some(ring) = sub_args.value_of("ring") {
config.set_ring(ring.to_string());
let ring = match sub_args.value_of("ring") {
Some(val) => Some(val.to_string()),
None => {
match henv::var(RING_ENVVAR) {
Ok(val) => Some(val),
Err(_) => None,
}
}
};
if let Some(ring) = ring {
config.set_ring(ring);
}
if args.value_of("verbose").is_some() {
sup::output::set_verbose(true);
Expand Down

0 comments on commit 98107bc

Please sign in to comment.