'use strict';

var _ = require('lodash'),
    path = require('path');

_.extend(exports, {
  envOverrides: {},

  supervisordConfigPath: function() {
    var config = require('api-umbrella-config').global();
    return path.join(config.get('etc_dir'), 'supervisord.conf');
  },

  env: function() {
    return _.merge({
      'PATH': [
        path.resolve(__dirname, '../bin'),
        path.resolve(__dirname, '../node_modules/.bin'),
        '/opt/api-umbrella/embedded/elasticsearch/bin',
        '/opt/api-umbrella/embedded/sbin',
        '/opt/api-umbrella/embedded/bin',
        '/opt/api-umbrella/embedded/jre/bin',
        '/usr/local/sbin',
        '/usr/local/bin',
        '/usr/sbin',
        '/usr/bin',
        '/sbin',
        '/bin',
      ].join(':'),
    }, this.envOverrides);
  },

  overrideEnv: function(overrides) {
    this.envOverrides = overrides;
  },
});

'use strict';

var _ = require('lodash'),
    path = require('path');

_.extend(exports, {
  envOverrides: {},

  supervisordConfigPath: function() {
    var config = require('api-umbrella-config').global();
    return path.join(config.get('etc_dir'), 'supervisord.conf');
  },

  env: function() {
    return _.merge({
      'PATH': [
        path.resolve(__dirname, '../bin'),
        path.resolve(__dirname, '../node_modules/.bin'),
        '/opt/api-umbrella/embedded/elasticsearch/bin',
        '/opt/api-umbrella/embedded/sbin',
        '/opt/api-umbrella/embedded/bin',
        '/opt/api-umbrella/embedded/jre/bin',
        '/usr/local/sbin',
        '/usr/local/bin',
        '/usr/sbin',
        '/usr/bin',
        '/sbin',
        '/bin',
      ].join(':'),

      // Reset Ruby related environment variables. This is in case the system
      // being installed onto has something like rvm/rbenv/chruby in place.
      // This ensures that we're using our API Umbrella bundled version of Ruby
      // on PATH rather than another version.
      'GEM_HOME': '',
      'GEM_PATH': '',
      'GEM_ROOT': '',
      'RUBYOPT': '',
      'RUBY_ENGINE': '',
      'RUBY_ROOT': '',
      'RUBY_VERSION': '',
    }, this.envOverrides);
  },

  overrideEnv: function(overrides) {
    this.envOverrides = overrides;
  },
});

Reset Ruby environment variables before launching.
Reset Ruby environment variables before launching.

This is to try to fix conflicts with systems that might have their own
version of Ruby already present, and we were therefore picking up their
gem paths, etc.
