# constant
SERVER_ROOT = "#{PackageServerConfig::CONFIG_ROOT}/pkg_server"
- LOCK_FILE = "#{SERVER_ROOT}/.server_loc"
- AUTO_SYNC_CHK_FILE = "#{SERVER_ROOT}/auto_sync"
+ DIBS_LOCK_FILE_PATH = "#{SERVER_ROOT}/.server_loc"
# initialize
def initialize (id)
end
# create
- def create (id, dist_name, server_url, loc = nil )
+ def create( id, dist_name, server_url, loc = nil )
update_config_information(id)
if loc.nil? or loc.empty? then
end
# create locking file
- @lock_file = Utils.file_lock(LOCK_FILE)
+ lock_file = Utils.file_lock(DIBS_LOCK_FILE_PATH)
# create server config directory
FileUtils.mkdir_p @config_dir
FileUtils.mkdir_p "#{@location}"
create_distribution_struct( dist_name, server_url )
- Utils.file_unlock(@lock_file)
+ Utils.file_unlock(lock_file)
@log.output( "package server [#{@id}] created successfully", Log::LV_USER )
end
end
def add_distribution( dist_name, server_url, clone )
- @lock_file = Utils.file_lock(LOCK_FILE)
+ lock_file = Utils.file_lock(@server_lock_file_path)
# error check : check for already exist in server directory
if @dist_to_server_url.keys.include? dist_name.strip then
add_dist_for_config_file(dist_name, server_url, clone)
create_distribution_struct( dist_name, server_url )
- Utils.file_unlock(@lock_file)
+ Utils.file_unlock(lock_file)
@log.output( "distribution [#{dist_name}] added successfully", Log::LV_USER )
end
def remove_server()
@log.info( "Package server [#{@id}] will be removed and all server information delete", Log::LV_USER)
- @lock_file = Utils.file_lock(LOCK_FILE)
+ lock_file = Utils.file_lock(DIBS_LOCK_FILE_PATH)
if File.exist? @config_file_path then
File.open @config_file_path do |f|
f.each_line do |l|
FileUtils.rm_rf @config_dir
FileUtils.rm_rf @log_file_path
- Utils.file_unlock(@lock_file)
+ Utils.file_unlock(lock_file)
@log.output( "package server [#{@id}] removed successfully", Log::LV_USER )
end
@log.info "remove distribution in server"
distribution = get_distribution( dist_name )
- @lock_file = Utils.file_lock(LOCK_FILE)
+ lock_file = Utils.file_lock(@server_lock_file_path)
# modify config file
config_file = File.readlines(@config_file_path)
# remove distribution struct
@distribution_list.delete distribution
- Utils.file_unlock(@lock_file)
+ Utils.file_unlock(lock_file)
end
def remove_pkg( dist_name, pkg_name_list, os )
@log.info "package remove in server"
distribution = get_distribution( dist_name )
- @lock_file = Utils.file_lock(LOCK_FILE)
+ lock_file = Utils.file_lock(@server_lock_file_path)
distribution.remove_pkg(pkg_name_list, os)
@log.info "generaging snapshot"
distribution.generate_snapshot("", "", false)
- Utils.file_unlock(@lock_file)
+ Utils.file_unlock(lock_file)
@log.output( "package removed successfully", Log::LV_USER )
end
@log.info "remove snapshot in server"
distribution = get_distribution( dist_name )
- @lock_file = Utils.file_lock(LOCK_FILE)
+ lock_file = Utils.file_lock(@server_lock_file_path)
distribution.remove_snapshot(snapshot_list)
- Utils.file_unlock(@lock_file)
+ Utils.file_unlock(lock_file)
end
def clean( dist_name, snapshot_list )
@log.info "pakcage server clean"
distribution = get_distribution( dist_name )
- @lock_file = Utils.file_lock(LOCK_FILE)
+ lock_file = Utils.file_lock(@server_lock_file_path)
distribution.clean( snapshot_list )
FileUtils.rm_rf incoming_path
FileUtils.mkdir incoming_path
- Utils.file_unlock(@lock_file)
+ Utils.file_unlock(lock_file)
end
# start server daemon
end
def self.list_id
- lock_file = Utils.file_lock(LOCK_FILE)
@@log = PackageServerLog.new("#{SERVER_ROOT}/.log")
d = Dir.new( SERVER_ROOT )
s = d.select {|f| not f.start_with?(".") }
s.sort!
+ server_list = []
@@log.output( "=== server ID list ===", Log::LV_USER)
s.each do |id|
if File.extname(id).eql?(".log") then next end
+ server_list.push id
@@log.output( id, Log::LV_USER)
end
@@log.close
FileUtils.rm_rf("#{SERVER_ROOT}/.log")
- Utils.file_unlock(lock_file)
+
+ return server_list
end
def self.list_dist( id )
- lock_file = Utils.file_lock(LOCK_FILE)
@@log = PackageServerLog.new( "#{SERVER_ROOT}/.log" )
@@log.output( "=== ID [#{id}]'s distribution list ===", Log::LV_USER)
+ dist_list = []
+
# read package id information
config_file_path = "#{SERVER_ROOT}/#{id}/config"
if not File.exist? config_file_path
File.open config_file_path do |f|
f.each_line do |l|
if l.start_with?( "server_url : ") and l.include?( "->" ) then
- @@log.output( l.split(" : ")[1].split("->")[0], Log::LV_USER)
+ dist_name = l.split(" : ")[1].split("->")[0]
+
+ dist_list.push dist_name
+ @@log.output( dist_name, Log::LV_USER)
end
end
end
@@log.close
FileUtils.rm_rf("#{SERVER_ROOT}/.log")
- Utils.file_unlock(lock_file)
+
+ return dist_list
end
def get_default_dist_name()
def reload_dist_package()
# create locking file
- @lock_file = Utils.file_lock(LOCK_FILE)
+ lock_file = Utils.file_lock(@server_lock_file_path)
@distribution_list.each do |dist|
dist.initialize_pkg_list
end
- Utils.file_unlock(@lock_file)
+ Utils.file_unlock(lock_file)
end
def release_lock_file
FileUtils.mkdir "#{@location}/#{dist_name}/source"
FileUtils.mkdir "#{@location}/#{dist_name}/temp"
FileUtils.mkdir "#{@location}/#{dist_name}/snapshots"
- File.open("#{@location}/#{dist_name}/snapshot.info", "w") do |f| end
-
+ File.open("#{@location}/#{dist_name}/#{Distribution::SNAPSHOT_INFO_FILE}", "w") {}
+ File.open("#{@location}/#{dist_name}/#{Distribution::OS_INFO_FILE}", "w") {}
+ File.open("#{@location}/#{dist_name}/#{Distribution::ARCHIVE_PKG_FILE}", "w") {}
+
# generate distribution
distribution = Distribution.new( dist_name, "#{@location}/#{dist_name}", server_url, self )
else
@log.info "[#{dist_name}] distribution creation. using local server [#{server_url}]"
end
-
- ret = distribution.sync(false)
- if ret then
- distribution.generate_snapshot("", "", false)
- end
+
+ distribution.sync(false)
+ distribution.generate_snapshot("", "", false)
else
@log.info "generate package server do not using remote package server"
@log_file_path = "#{SERVER_ROOT}/#{@id}.log"
@config_file_path = "#{@config_dir}/config"
@incoming_path = "#{@config_dir}/incoming"
+ @server_lock_file_path = "#{@config_dir}/.server_lock"
end
end