Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancements to Windows service install/uninstall. #831

Merged
merged 1 commit into from
Mar 15, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions lib/fluent/command/fluentd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@
opts[:regwinsvc] = s
}

op.on('--[no-]reg-winsvc-auto-start', "Automatically start the Windows Service at boot. (only effective with '--reg-winsvc i') (Windows only)") {|s|
opts[:regwinsvcautostart] = s
}

op.on('--reg-winsvc-fluentdopt OPTION', "specify fluentd option paramters for Windows Service. (Windows only)") {|s|
opts[:fluentdopt] = s
}
Expand Down Expand Up @@ -192,6 +196,8 @@
exit 0
end

early_exit = false
start_service = false
if winsvcinstmode = opts[:regwinsvc]
FLUENTD_WINSVC_NAME="fluentdwinsvc"
FLUENTD_WINSVC_DISPLAYNAME="Fluentd Windows Service"
Expand All @@ -207,33 +213,51 @@
ruby_path = "\0" * 256
GetModuleFileName.call(0,ruby_path,256)
ruby_path = ruby_path.rstrip.gsub(/\\/, '/')
start_type = Service::DEMAND_START
if opts[:regwinsvcautostart]
start_type = Service::AUTO_START
start_service = true
end

Service.create(
service_name: FLUENTD_WINSVC_NAME,
host: nil,
service_type: Service::WIN32_OWN_PROCESS,
description: FLUENTD_WINSVC_DESC,
start_type: Service::DEMAND_START,
start_type: start_type,
error_control: Service::ERROR_NORMAL,
binary_path_name: ruby_path+" -C "+binary_path+" winsvc.rb",
load_order_group: "",
dependencies: [""],
display_name: FLUENTD_WINSVC_DISPLAYNAME
)
when 'u'
if Service.status(FLUENTD_WINSVC_NAME).current_state != 'stopped'
begin
Service.stop(FLUENTD_WINSVC_NAME)
rescue => ex
puts "Warning: Failed to stop service: ", ex
end
end
Service.delete(FLUENTD_WINSVC_NAME)
else
# none
end
exit 0
early_exit = true
end

if fluentdopt = opts[:fluentdopt]
Win32::Registry::HKEY_LOCAL_MACHINE.open("SYSTEM\\CurrentControlSet\\Services\\fluentdwinsvc", Win32::Registry::KEY_ALL_ACCESS) do |reg|
reg['fluentdopt', Win32::Registry::REG_SZ] = fluentdopt
end
exit 0
early_exit = true
end

if start_service
Service.start(FLUENTD_WINSVC_NAME)
end

exit 0 if early_exit

require 'fluent/supervisor'
Fluent::Supervisor.new(opts).start