lib/kameleon/shell.rb in kameleon-builder-2.1.0 vs lib/kameleon/shell.rb in kameleon-builder-2.1.1
- old
+ new
@@ -6,11 +6,13 @@
class Shell
ECHO_CMD = "echo"
READ_CHUNK_SIZE = 1048576
EXIT_TIMEOUT = 60
- attr :exit_status, :process, :shell_cmd
+ attr :exit_status
+ attr :process
+ attr :shell_cmd
def initialize(context_name, cmd, shell_workdir, local_workdir, kwargs = {})
@logger = Log4r::Logger.new("kameleon::[kameleon]")
@cmd = cmd.chomp
@context_name = context_name
@@ -28,20 +30,10 @@
@bash_env_file = File.join(@shell_workdir, @bash_env_file)
end
## Changing the default bashrc if the cache is activated
@cache = Kameleon::Persistent_cache.instance
- if @cache.activated? then
- new_kameleon_bashrc = Tempfile.new('kameleon_bashrc').path
- FileUtils.cp @default_bashrc_file, new_kameleon_bashrc
- tpl = ERB.new(File.read(@cache.polipo_env))
- polipo_env_content = tpl.result(binding)
- File.open(new_kameleon_bashrc,'a') do |f|
- f.puts(polipo_env_content)
- end
- @default_bashrc_file = new_kameleon_bashrc
- end
@shell_cmd = "source #{@default_bashrc_file} 2> /dev/null; "\
"#{@cmd} --rcfile #{@bashrc_file}"
@logger.debug("Initialize shell (#{self})")
# Injecting all variables of the options and assign the variables
@@ -54,19 +46,22 @@
@sent_first_cmd = false
@process, @stdout, @stderr = fork("pipe")
end
def stop
- @process.stop(0) unless @process.nil?
+ unless @process.nil?
+ @process.stop(0)
+ @process = nil
+ end
end
def started?
return !@process.nil?
end
def exited?
- @process.exited?
+ return !@process.nil? && @process.exited?
end
def restart
stop
start
@@ -96,9 +91,13 @@
@logger.info(init_stdout) unless init_stdout.empty?
bashrc_content = ""
if File.file?(@default_bashrc_file)
tpl = ERB.new(File.read(@default_bashrc_file))
bashrc_content = tpl.result(binding)
+ if @cache.activated? then
+ tpl = ERB.new(File.read(@cache.polipo_env))
+ bashrc_content << "\n" + ERB.new(File.read(@cache.polipo_env)).result(binding)
+ end
end
bashrc = Shellwords.escape(bashrc_content)
if @shell_workdir
unless @shell_workdir.eql? "/"
change_dir_cmd = "mkdir -p #{@shell_workdir} &&"