#!/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. # #============================================================================= # Configuration #============================================================================= # Do not change these values without also editing the "helix_web_services" # script in the bin/ directory. INSTALL_DIR = ENV['install_dir'] raise 'install_dir not defined' if INSTALL_DIR.nil? HWS_USER = 'helixwebservices' DATA_DIR = '/var/lib/perforce/helix_web_services' LOG_DIR = '/var/log/perforce/helix_web_services' UPSTART_FILE = '/etc/init/helix_web_services.conf' P4PORT = '1666' P4ROOT = '/var/lib/perforce/p4d' P4SUPER = 'super' P4SUPERPASS = 'superuser1A!' #============================================================================= # 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 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) 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?(UPSTART_FILE) FileUtils.ln_sf("#{INSTALL_DIR}#{UPSTART_FILE}", UPSTART_FILE) system('sudo initctl reload-configuration') end end def package_installed?(package) if centos? system("yum list installed #{package} > /dev/null 2>&1") else `sudo dpkg -l | awk '{print $2}'`.include?(package) end end def add_packaging_key if centos? system('sudo rpm --import http://package.perforce.com/perforce.pubkey') else system('wget -q http://package.perforce.com/perforce.pubkey -O - | sudo apt-key add -') end end def configure_repo if centos? IO.write('/etc/yum.repos.d/perforce.repo', <<-END.gsub(/^[ ]{6}/, '') [perforce] name=Perforce baseurl=http://package.perforce.com/yum/rhel/#{centos_major_version}/#{node["kernel"]["machine"]} enabled=1 gpgcheck=1 END ) else IO.write('/etc/apt/sources.list.d/perforce.sources.list', 'deb http://package.perforce.com/apt/ubuntu precise release') end end def configure_package_repo add_packaging_key configure_repo if ubuntu? system('sudo apt-get update') end end def create_projects_stream(p4) depot = p4.fetch_depot('projects') depot._depot = 'projects' depot._type = 'stream' p4.save_depot(depot) end def create_projects_meta_depot(p4) depot = p4.fetch_depot('.projects') depot._depot = '.projects' p4.save_depot(depot) end # When setting up the default p4d instance, this will create the //projects # stream depot and //.projects standard depot for Helix Sync. def configure_project_depots require 'P4' p4 = P4.new p4.exception_level = P4::RAISE_ERRORS p4.port = ':1666' p4.charset = 'auto' p4.user = P4SUPER p4.password = P4SUPERPASS p4.connect p4.run_login create_projects_stream(p4) create_projects_meta_depot(p4) p4.run_logout p4.disconnect end # Install and configure a p4d instance with a default superuser and password. # This will generate a couple of depots for Helix Sync usage. def install_default_p4d puts 'Installing default perforce-server' configure_package_repo if centos? system('sudo yum -y install perforce-server') else system('sudo apt-get install -y perforce-server') end system('/opt/perforce/sbin/configure-perforce-server.sh helix-evaluation ' + "-n -p #{P4PORT} -r #{P4ROOT} " + "-u #{P4SUPER} " + "-P #{P4SUPERPASS} " + '--unicode') configure_project_depots end def install_nginx if centos? system('sudo yum -y install epel-release') system('sudo yum -y install nginx') # CentOS doesn't have the 'snakeoil' cert by default system('mkdir -p /etc/ssl/private') system("#{INSTALL_DIR}/bin/make-dummy-cert") else system('sudo apt-get update') system('sudo apt-get install -y nginx ssl-cert') end end def configure_default_nginx IO.write('/etc/nginx/nginx.conf', <<-END.gsub(/^[ ]{4}/, '') error_log /var/log/nginx/error.log info; worker_processes 10; events { worker_connections 1024; } http { log_format main '$remote_addr - $remote_user [$time_local] $status ' '"$request" $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log; map $http_upgrade $connection_upgrade { default Upgrade; '' close; } upstream unicorn_server { server 127.0.0.1:9000; } server { listen 443; ssl on; ssl_certificate /etc/ssl/certs/ssl-cert-snakeoil.pem; ssl_certificate_key /etc/ssl/private/ssl-cert-snakeoil.key; location /hws/ { rewrite /hws/(.*) /$1 break; proxy_pass http://unicorn_server; } } } END ) end #============================================================================= # Execution #============================================================================= unless user_exists?(HWS_USER) create_user(HWS_USER) end require 'fileutils' ensure_dir_exists(DATA_DIR, HWS_USER) ensure_dir_exists(LOG_DIR, HWS_USER) ensure_startup_config_exists unless package_installed?('nginx') install_nginx configure_default_nginx end unless package_installed?('perforce-server') # This seems to trigger a script exit install_default_p4d end puts 'helix_web_services ready to be started'
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 15741 | ptomiak | Branch HWS for my use. | ||
//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. |