hws_configure #3

  • //
  • guest/
  • doug_scheirer/
  • helix-web-services/
  • main/
  • source/
  • helix_web_services/
  • bin/
  • hws_configure
  • View
  • Commits
  • Open Download .zip Download (3 KB)
#!/usr/bin/env ruby
#
# After installation, this script is used to configure the system.
#
# This is really a basic script intended to get the ball rolling in the early
# stages of the project.
#
# Run this script with elevated privileges.
#

# This is really set by the installation system
INSTALL_DIR = ENV['install_dir']
raise 'install_dir not defined' if INSTALL_DIR.nil?

require 'hws_settings'

#=============================================================================
# Helper Methods
#=============================================================================

require 'ohai'

def node
  @node ||= init_system
end

def init_system
  puts 'collecting system data'
  s = Ohai::System.new
  s.all_plugins
  s
end

def centos?
  node['platform'] == 'centos'
end

def ubuntu?
  node['platform'] == 'ubuntu'
end

def centos_major_version
  node['platform_version'][/\d+/]
end

def user_exists?(username)
  system("getent passwd #{username} > /dev/null")
end

def create_user(username)
  puts "creating system user #{username}"

  home_dir = File.join(INSTALL_DIR, 'home', username)

  if centos?
    system(%W(
           useradd -r
               --shell /bin/bash
               --home #{home_dir}
               #{username}
      ).join(' '))
  else
    system(%W(adduser --system
             --group
             --home #{home_dir}
               --shell /bin/bash
             #{username}).join(' '))
  end
end

def ensure_dir_exists(dir, user)
  unless Dir.exist?(dir)
    puts "creating directory for user #{user}: #{dir}"
    FileUtils.mkpath(dir)
    FileUtils.chown(user, user, dir)
  end
end

# Make sure that the Upstart configuration file has been linked
def ensure_startup_config_exists
  unless File.exist?('/etc/init.d/helix_web_services')
    puts 'linking init.d script to /etc/init.d/helix_web_services'
    FileUtils.ln_sf("#{INSTALL_DIR}/sbin/helix_web_services", '/etc/init.d/helix_web_services')
    # TODO this is probably update-rc.d on debian, chkconfig on centos?
    # system('sudo initctl reload-configuration')
    if ubuntu?
      system('sudo update-rc.d helix_web_services defaults')
    end
  end
end

#=============================================================================
# Execution
#=============================================================================

unless user_exists?(HWSSettings.system.SYSTEM_USER)
  create_user(HWSSettings.system.SYSTEM_USER)
end

require 'fileutils'

ensure_dir_exists(HWSSettings.system.DATA_DIR, HWSSettings.system.SYSTEM_USER)
ensure_dir_exists(HWSSettings.system.LOG_DIR, HWSSettings.system.SYSTEM_USER)
ensure_dir_exists(HWSSettings.system.RUN_DIR, HWSSettings.system.SYSTEM_USER)

ensure_startup_config_exists unless ENV.key?('NO_STARTUP_CONFIG')
# Change User Description Committed
#3 16318 Doug Scheirer merge from main
#2 16289 Doug Scheirer merge from main
#1 15688 Doug Scheirer Populate -o //guest/perforce_software/helix-web-services/...
//guest/doug_scheirer/helix-web-services/....
//guest/perforce_software/helix-web-services/main/source/helix_web_services/bin/hws_configure
#1 15622 tjuricek Move source code to 'source/' subdirectory of branch.

build/ will remain where it is.
//guest/perforce_software/helix-web-services/main/helix_web_services/bin/hws_configure
#10 15111 tjuricek Remove references to actually using the SQLite DB in the installation

Still depending on it to avoid shared library dependencies to system packages
#9 14976 tjuricek Bind on port 9000 instead of a local unix socket.

For whatever reason, the CentOS 6 system configuration does not like the local unix socket permissions, even though it seems like it should be allowable.
#8 14932 tjuricek CentOS 6 deployment support.

I need a reliable way of detecting platform information. So I'm installing ohai, which comes from Chef, and seems to be a stable way of determing things like "I'm running on CentOS 6.5".
#7 14877 tjuricek Fix whitespace in generated nginx.conf
#6 14876 tjuricek Add default Helix Sync depots to our default p4d setup.
#5 14873 tjuricek Added default nginx and p4d setup to hws_configure

This should give users that run hws_configure the first time... something... that could be used for testing a basic setup. How we configure the system from here isn't ironed out yet.
#4 14870 tjuricek Add an upstart configuration for helix_web_services.
#3 14842 tjuricek Add helixwebservices user setup to hws_configure
#2 14841 tjuricek Add *very basic* shell script wrappers to configure and launch the unicorn server.

hws_configure: post-install script to setup or migrate the DB

helix_web_services: bash script to point out the embedded Ruby setup

This is far from complete, just the next step in getting to a basic package-based deployment.
#1 13799 tjuricek Start with branch specs hosting in a new monolithic 'helix web services' project.

Converting from a microservice to a monolithic architecture due to resource constraints at getting a deployable system running. Additionally, since it's not expected that people will upgrade often, the major benefit of microservices - being able to add services individually without affecting others - is not really a major benefit.

The Ruby SDK will be consolidated into a single 'helix web services client' project. It may end up being distributed via Rubygems.

This only runs branch specs at the moment. I want to get a CD pipeline setup for the monolithic server before revising more methods.