Improved service removal.

master
Luka Vandervelden 2019-11-08 15:54:44 +01:00
parent 87929be026
commit c2730bdd71
3 changed files with 28 additions and 9 deletions

View File

@ -171,6 +171,7 @@ commands.push "del", "Removes a service from an environment." do |args|
end end
revdeps.reverse.each do |service| revdeps.reverse.each do |service|
puts "removing #{service.to_s}"
service.remove RC_DIRECTORY service.remove RC_DIRECTORY
end end
end end

View File

@ -21,13 +21,6 @@ class Environment
@type = Type.parse type @type = Type.parse type
@files = Array(ServiceDefinition::FileDefinition).new @files = Array(ServiceDefinition::FileDefinition).new
# FIXME: Should this *really* be here?
# FIXME: $ENVIRONMENT_ROOT
@files << ServiceDefinition::FileDefinition.new "/srv/${ENVIRONMENT}",
"environment root",
creation_command: "mkdir -p /srv/${ENVIRONMENT} && chmod a+rwt /srv/${ENVIRONMENT}",
deletion_command: "rmdir /srv/${ENVIRONMENT}"
end end
def initialize(@name, specs : SpecParser) def initialize(@name, specs : SpecParser)

View File

@ -273,8 +273,8 @@ class Service
env: build_environment env: build_environment
end.wait end.wait
if child.exit_status != 0 unless child.success?
raise Service::Exception.new "Child process exited with status “#{child.exit_status}”." raise Service::Exception.new "Child process exited with status “#{(child.exit_status/256).to_i}”."
break break
end end
end end
@ -458,6 +458,31 @@ class Service
end end
def remove(path) def remove(path)
files.reverse.each do |file|
puts " - removing '#{file.file_path}'"
command = file.deletion_command
child = Process.fork do
Dir.cd root
exit 0 unless File.exists? file.file_path
if command
Process.exec "sh", ["-c", command],
output: Process::Redirect::Inherit,
error: Process::Redirect::Inherit,
env: build_environment
else
FileUtils.rm_rf file.file_path
end
end.wait
unless child.success?
raise Service::Exception.new "Child process exited with status “#{(child.exit_status/256).to_i}”."
break
end
end
File.delete "#{path}/#{name}.#{@environment.name}.spec" File.delete "#{path}/#{name}.#{@environment.name}.spec"
end end