Sha256: c8c81856d66ca072a93cc899634fb3881fc102518550339775cda393de78f7b0

Contents?: true

Size: 1.75 KB

Versions: 1

Compression:

Stored size: 1.75 KB

Contents

require_relative '../modules/applet_helper'
require_relative '../modules/paths'
require_relative '../modules/exceptions'

class MasterStarter
    include AppletHelper
    include Paths
    
    private
    def kill_proc(name)
        `pids=$(ps -fu $USER | grep "#{name}" | grep -v "grep" | awk '{print $2}'); for pid in ${pids[@]}; do kill -9 $pid; done`
    end

    def add_to_autorun
      `osascript -e 'tell application "System Events" to make login item at end with properties {path:"#{__dir__}/iJenkins_autorun", hidden:true, name:"iJenkins Master"}'`
    end

    public
    def start
        raise NotInitialized unless should_start_slave

        add_to_autorun

        # Applet
        start_master
        
        # Start Unity cache server
        start_cache_server
        
        # Start provisioning updater
        start_pu

        true
    end

    def start_pu(on_production = true)
      fork do
        Dir.chdir(path_to_provisioning_updater) do
          if on_production
            `./run -e production -p 3000`
          else
            `./run`
          end
        end
      end
    end

    def start_cache_server
      stop_cache_server

      fork do
        FileUtils::mkdir_p("#{path_to_unity_cache}/Cache5.0")
        FileUtils::mkdir_p("#{path_to_unity_cache}/Cache")
        `#{path_to_environment}/CacheServer/RunOSX.command --path #{path_to_unity_cache}/Cache5.0 --legacypath #{path_to_unity_cache}/Cache`
      end
    end

    def stop
        stop_applets
        stop_pu
        stop_cache_server
        kill_proc("rails")
    end

    def stop_pu
      `kill -9 "$(cat #{path_to_provisioning_updater}/tmp/pids/server.pid)" 2>/dev/null`
    end

    def stop_cache_server
      kill_proc("#{path_to_environment}/CacheServer/")
    end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
nixenvironment-0.0.80 lib/nixenvironment/jenkins/master/master_starter.rb