clean up, tryna get idempotent

This commit is contained in:
Eric Hanko 2018-03-19 00:00:41 -07:00
Родитель f655acfb7a
Коммит fc6aeae1cf
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 6929ED641B928648
6 изменённых файлов: 6 добавлений и 83 удалений

Просмотреть файл

@ -18,12 +18,6 @@ Usage: `vsts_agent_macos::teardown`
Remove an existing agent from the specified VSTS server
### Service audit
Usage: `vsts_agent_macos::service_audit`
A during-converge test. Include this recipe to verify that the agent service is running. If it isn't, raise an exception.
Attributes
----------

Просмотреть файл

@ -1,39 +0,0 @@
module VstsAgentMacOS
class LaunchdService
def initialize(service_label)
@label = service_label
@enabled = false
@running = false
end
def service_needs_reinstall?
service_files = ["#{agent_home}/.service", "#{agent_home}/runsvc.sh", Agent.launchd_plist]
service_files.any? { |service_file| !::File.exist? service_file }
end
def enabled?
running_processes.any? { |process| process[:service_name] == Agent.service_name }
end
def process_id?(output)
output.match?(/^\d+$/i)
end
def process_map(command_output = nil)
command_output ||= launchctl_list_output
capture_pattern = /(?<pid>[\-\d]+)\t(?<exit_code>[\-\d]+)\t(?<service_name>.+)/
processes = command_output.lines
processes.map { |process| process.match(capture_pattern).named_captures }
end
private
def launchctl_command
'/bin/launchctl'
end
def launchctl_list_command
shell_out launchctl_command, 'list', @label, user: Agent.admin_user
end
end
end

Просмотреть файл

@ -65,7 +65,6 @@ end
file 'create path file' do
path ::File.join Agent.agent_home, '.path'
content ENV['PATH']
owner Agent.admin_user
group Agent.user_group
mode 0o644
@ -100,15 +99,6 @@ execute 'configure replacement agent' do
action :nothing
end
file 'service script' do
path ::File.join Agent.agent_home, 'runsvc.sh'
owner Agent.admin_user
group Agent.user_group
mode 0o775
content lazy { ::IO.read ::File.join(Agent.agent_home, 'bin', 'runsvc.sh') }
action :create
end
file 'create agent service file' do
path ::File.join Agent.agent_home, '.service'
owner Agent.admin_user

Просмотреть файл

@ -1,7 +0,0 @@
ruby_block 'service is up and running' do
block do
cmd = shell_out '/bin/launchctl', 'list', user: Agent.admin_user
agents = cmd.stdout.lines.map { |line| line.split("\t").last.strip }
raise Chef::Application.fatal!('VSTS agent service is not enabled!') unless agents.include? Agent.service_name
end
end

Просмотреть файл

@ -1,25 +1,19 @@
macosx_service 'stop-agent-service' do
macosx_service 'stop agent service' do
service_name Agent.service_name
user Agent.admin_user
action [:disable, :stop]
end
file 'delete-service-script' do
path "#{Agent.agent_home}/runsvc.sh"
action :nothing
subscribes :delete, 'macosx_service[stop-agent-service]', :immediately
end
file 'delete-service-name-file' do
file 'delete service name file' do
path "#{Agent.agent_home}/.service"
action :nothing
subscribes :delete, 'file[delete-service-script]', :immediately
subscribes :delete, 'file[delete service script]', :immediately
end
file 'delete-service-plist' do
file 'delete service plist' do
path Agent.launchd_plist
action :nothing
subscribes :delete, 'file[delete-service-name-file]', :immediately
subscribes :delete, 'file[delete service name file]', :immediately
end
execute 'unconfigure VSTS agent' do
@ -27,8 +21,7 @@ execute 'unconfigure VSTS agent' do
user Agent.admin_user
command ['./bin/Agent.Listener', 'remove']
environment Agent.vsts_environment
not_if { Agent.credentials? }
live_stream true
action :nothing
subscribes :delete, 'file[delete-service-name-file]', :immediately
subscribes :delete, 'file[delete service name file]', :immediately
end

Просмотреть файл

@ -1,8 +0,0 @@
include_recipe 'vsts_agent_macos::bootstrap'
log '================================================== WARNING! =================================================='
log '================================================== WARNING! =================================================='
log "\'#{cookbook_name}::#{recipe_name}\' has been renamed to \'#{cookbook_name}::bootstrap\' and will be removed in a later release."
log "Update any cookbooks that use \'#{cookbook_name}::#{recipe_name}\' and replace with \'#{cookbook_name}::bootstrap\'"
log '================================================== WARNING! =================================================='
log '================================================== WARNING! =================================================='