#!/usr/bin/ruby # ace: ace startup script # # chkconfig: - 95 95 # # description: Provides start up time configuration and # refreshing of the appliance. The appliance is # installed if there is no file called installed # in /etc/sysconfig/ace. If the file exists, this # script will refresh the appliance. # # Copyright (C) 2008 Red Hat Inc. # fs # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. # # This library is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # Author: Bryan Kearney <bkearney@redhat.com> require "ace" require "fileutils" # Control for this script CONFIG_LOCATION="/etc/sysconfig/ace" CHECK_FILE_NAME=CONFIG_LOCATION+"/installed" APPLIANCE_NAME_FILE=CONFIG_LOCATION+"/appliancename" LOCK_FILE="/var/lock/subsys/ace" INSTALL_LOG_FILE="/var/log/ace/install.log" REFRESH_LOG_FILE="/var/log/ace/refresh-#{Time.now().to_i}.log" UPDATE_LOG_FILE="/var/log/ace/update-#{Time.now().to_i}.log" returnValue = 0 command = "install" def set_column(column = 60) print("\033[#{column}G") end def echo_success() set_column() puts(" [\033[1;32m OK \033[0;39m]") end def echo_failure() set_column() puts(" [\033[1;31m FAILED \033[0;39m]") end # # This method does all the work # def execute_ace(command, returnValue) # Check if we have an error. If not, lets keep going status = 0 if (status == 0) file = File.new(APPLIANCE_NAME_FILE) File.foreach(APPLIANCE_NAME_FILE) do |line| applianceName = line.chomp() FileUtils.touch(LOCK_FILE) ace = ACE.new() ace.appliance_name= applianceName ace.verbose = true ace.debug = true case command when "install" #do the install, and create the check file print("Installing appliance #{applianceName}") ace.log_file = INSTALL_LOG_FILE status = ace.install_appliance() FileUtils.touch(CHECK_FILE_NAME) when "refresh" print("Refreshing appliance #{applianceName}") ace.log_file = REFRESH_LOG_FILE status = ace.refresh_appliance() when "update" ace.log_file = UPDATE_LOG_FILE status = ace.update_appliance() end end FileUtils.rm(LOCK_FILE) end if (status == 0) echo_success() else echo_failure() end end #Global setup FileUtils.mkdir_p(CONFIG_LOCATION) unless (File.exist?(CONFIG_LOCATION)) FileUtils.mkdir_p("/var/log/ace/") unless (File.exist?("/var/log/ace/")) if (File.exist?(LOCK_FILE)) returnValue = 1 else if (!File.exist?(APPLIANCE_NAME_FILE)) returnValue = 1 print("No appliance name file at #{APPLIANCE_NAME_FILE}") else command = "refresh" if (File.exist?(CHECK_FILE_NAME)) end end # Grab the action, and get going. action = ARGV.first case action when "start" execute_ace(command, returnValue) when "update" execute_ace("update", returnValue) when "stop" FileUtils.rm(LOCK_FILE) if File.exist?(LOCK_FILE) when "status" File.exist?(LOCK_FILE) ? 1 : 0 when "reload" FileUtils.rm(LOCK_FILE) if File.exist?(LOCK_FILE) execute_ace("update", returnValue) else print("Usage: ace {start|stop|status|update}") returnValue = 3 end exit returnValue