• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

aws / aws-codedeploy-agent / 4600315001

pending completion
4600315001

push

github

GitHub
Updating latest version info for master branch

1129 of 2362 relevant lines covered (47.8%)

2.1 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

24.44
/lib/instance_agent/platform/linux_util.rb
1
module InstanceAgent
1✔
2
  class LinuxUtil
1✔
3
    def self.supported_versions()
1✔
4
      [0.0]
×
5
    end
6

7
    def self.supported_oses()
1✔
8
      ['linux']
×
9
    end
10

11
    def self.prepare_script_command(script, absolute_cmd_path)
1✔
12
      runas = !!script.runas
×
13
      sudo = !!script.sudo
×
14

15
      if runas && sudo
×
16
        return 'sudo su ' + script.runas + ' -c ' + absolute_cmd_path
×
17
      end
18

19
      if runas && !sudo
×
20
        return 'su ' + script.runas + ' -c ' + absolute_cmd_path
×
21
      end
22

23
      if !runas && sudo
×
24
        return 'sudo ' + absolute_cmd_path
×
25
      end
26

27
      # If neither sudo or runas is specified, execute the
28
      # command as the code deploy agent user 
29
      absolute_cmd_path
×
30
    end
31

32
    def self.quit()
1✔
33
      # Send kill signal to parent and exit
34
      Process.kill('TERM', Process.ppid)
×
35
    end
36

37
    def self.script_executable?(path)
1✔
38
      File.executable?(path)
×
39
    end
40

41
    def self.extract_tar(bundle_file, dst)
1✔
42
      log(:debug, "extract_tar - dst : #{dst}")
×
43
      FileUtils.mkdir_p(dst)
×
44
      working_dir = FileUtils.pwd()
×
45
      absolute_bundle_path = File.expand_path(bundle_file)
×
46
      FileUtils.cd(dst)
×
47
      execute_tar_command("/bin/tar -xpsf #{absolute_bundle_path}")
×
48
      FileUtils.cd(working_dir)
×
49
    end
50

51
    def self.extract_zip(bundle_file, dst)
1✔
52
      log(:debug, "extract_zip - dst : #{dst}")
×
53
      FileUtils.mkdir_p(dst)
×
54
      absolute_bundle_path = File.expand_path(bundle_file)
×
55
      execute_zip_command("unzip -qo #{absolute_bundle_path} -d #{dst}")
×
56
    end    
57

58
    def self.extract_tgz(bundle_file, dst)
1✔
59
      log(:debug, "extract_tgz - dst : #{dst}")
×
60
      FileUtils.mkdir_p(dst)
×
61
      working_dir = FileUtils.pwd()
×
62
      absolute_bundle_path = File.expand_path(bundle_file)
×
63
      FileUtils.cd(dst)
×
64
      execute_tar_command("/bin/tar -zxpsf #{absolute_bundle_path}")
×
65
      FileUtils.cd(working_dir)
×
66
    end
67

68
    def self.supports_process_groups?()
1✔
69
      true
×
70
    end
71

72
    def self.codedeploy_version_file
1✔
73
      File.join(ProcessManager::Config.config[:root_dir], '..')
×
74
    end
75

76
    def self.fallback_version_file
1✔
77
      "/opt/codedeploy-agent"
×
78
    end
79

80
     # shelling out the rm folder command to native os in this case linux.
81
    def self.delete_dirs_command(dirs_to_delete)
1✔
82
      log(:debug,"Dirs to delete: #{dirs_to_delete}");
×
83
      for dir in dirs_to_delete do
×
84
        log(:debug,"Deleting dir: #{dir}");
×
85
        delete_folder(dir);  
×
86
      end
87
    end
88
     
89
    private 
1✔
90
    def self.delete_folder (dir)
1✔
91
      if dir != nil && dir != "/"
×
92
        output = `rm -rf #{dir} 2>&1`
×
93
        exit_status = $?.exitstatus
×
94
        log(:debug, "Command status: #{$?}")
×
95
        log(:debug, "Command output: #{output}")
×
96
        unless exit_status == 0
×
97
          msg = "Error deleting directories: #{exit_status}"
×
98
          log(:error, msg)
×
99
          raise msg
×
100
        end 
101
      else
102
        log(:debug, "Empty directory or a wrong directory passed,#{dir}");  
×
103
      end
104
    end  
105
    
106
    private
1✔
107
    def self.execute_tar_command(cmd)
1✔
108
      log(:debug, "Executing #{cmd}")
×
109

110
      output = `#{cmd} 2>&1`
×
111
      exit_status = $?.exitstatus
×
112

113
      log(:debug, "Command status: #{$?}")
×
114
      log(:debug, "Command output: #{output}")
×
115

116
      if exit_status != 0
×
117
        msg = "Error extracting tar archive: #{exit_status}"
×
118
        log(:error, msg)
×
119
        raise msg
×
120
      end
121
    end
122

123
    private
1✔
124
    def self.execute_zip_command(cmd)
1✔
125
      log(:debug, "Executing #{cmd}")
×
126

127
      output = `#{cmd} 2>&1`
×
128
      exit_status = $?.exitstatus
×
129

130
      log(:debug, "Command status: #{$?}")
×
131
      log(:debug, "Command output: #{output}")
×
132

133
      if exit_status != 0
×
134
        msg = "Error extracting zip archive: #{exit_status}"
×
135
        log(:error, msg)
×
136
        raise msg
×
137
      end
138
    end
139
   
140
    private
1✔
141
    def self.log(severity, message)
1✔
142
      raise ArgumentError, "Unknown severity #{severity.inspect}" unless InstanceAgent::Log::SEVERITIES.include?(severity.to_s)
×
143
      InstanceAgent::Log.send(severity.to_sym, "#{self.to_s}: #{message}")
×
144
    end
145

146
  end
147
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc