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

Windows Service #1543

Closed
wants to merge 19 commits into from
Closed

Conversation

butitsnotme
Copy link
Contributor

Windows Service

This pull requests adds the capability for Telegraf to run as a Windows service. This is accomplished by integrating the library kardianos/service. This, once accepted, should close issue #860.

Brief summary of changes

  • New main function (for implementing service support)
    • Old main function has been renamed to reloadLoop
  • Additional option (for installing/uninstalling the service)
  • Removed common dependencies from the windows specific file

Required for all PRs:

  • CHANGELOG.md updated
  • Sign CLA (if not already signed)

butitsnotme and others added 11 commits July 15, 2016 17:00
Updated the windows dependencies so that the versions matched the
dependencies for Mac OS and Linux. Additionally added some that were
complained about being missing at compile time.
Incorporated the library github.com/kardianos/service to manage the
service on the various platforms (including Windows). This required an
alternate main function.

The original main function was renamed to reloadLoop (as that is what
the main loop in it does) (it also got a couple of parameters). The
service management library calls it as the main body of the program.
Due to compilation issues on Windows, moved the code from service.go
into telegraf.go and removed service.go entirely.
Updated the dependencies so that it builds properly on Windows,
additionally, fixed the registered command for starting it as
a service (needed to add the config file option). This currently
standardizes it as a C:\telegraf\telegraf.conf on Windows.
Removed all the common dependencies from the Godeps_windows file and
modified Makefile to load Godeps and then Godeps_windows when building
for Windows. This should reduce problems caused by the Godeps_windows
file being forgotten when updating dependencies.
type program struct{}

func reloadLoop(stop chan struct{}, s service.Service) {
defer func() {
Copy link
Contributor

@sparrc sparrc Jul 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you explain what this does? (the defer function and service.Interactive())

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

service.Interactive() is a boolean function which detects if the program is being run interactively (as opposed to as a service). The purpose of the defer function is to cause the program to exit when the main function does if it is being run interactively. It was added in response to a bug where the program would never exit if you simply asked it to provide information (ie telegraf -help).

@sparrc
Copy link
Contributor

sparrc commented Jul 25, 2016

thanks @butitsnotme!

The service library [kardianos/service](github.com/kardianos/service)
has been disabled on all platforms but windows, as there is already
existing infrastructure for other platforms.
@sparrc
Copy link
Contributor

sparrc commented Jul 25, 2016

excellent, can you also edit this document: https://github.com/influxdata/telegraf/blob/master/docs/WINDOWS_SERVICE.md

to reflect the changes? I believe now we only need to do a > telegraf --service install on Windows now? And users also need to copy a config file to C:\telegraf\telegraf.conf?

@sparrc
Copy link
Contributor

sparrc commented Jul 25, 2016

@butitsnotme I haven't been able to get this running properly. The "telegraf -service install" works but then I can't get it to start via net start telegraf:

image

This is on Windows Server 2012

It appears that gdm accidentally added the project itself to the
dependency list. This caused the dependency restoration to select an
earlier version of the project during build.

This only affected windows.
This only affected builds after 020b2c7
@butitsnotme
Copy link
Contributor Author

@sparrc This happened because the start command was wrong, it didn't have the config file in it. The regression occurred because in commit 020b2c7 the telegraf repository itself got added as a dependency, causing the code base to be rolled back during compile. I have removed the dependency manually, however there may be a bug with gdm...

The latest commit should compile and run (I just tested it against a clean GO directory and it is running on Windows 8.1 now)

Removed the documentation about using NSSM and added documentation on
installing telegraf directly as a Windows Service.
Added the license information for github.com/kardianos/service which is
licensed under the ZLib license, although that name is never mentioned
the license text matches word for word.
@@ -45,6 +47,8 @@ var fOutputFiltersLegacy = flag.String("outputfilter", "",
"filter the outputs to enable, separator is :")
var fConfigDirectoryLegacy = flag.String("configdirectory", "",
"directory containing additional *.conf files")
var fService = flag.String("service", "",
"operate on the service")
Copy link
Contributor

@phemmer phemmer Jul 26, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should also be in a if windows {} conditional (or equivalent behavior). Otherwise we have this flag which will be present, but does nothing on other OSs.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it'll still show up in the --help output though. I would just leave it and put in a (windows only) blurb in the doc.

@sparrc
Copy link
Contributor

sparrc commented Jul 26, 2016

@butitsnotme should we change the default install location to C:\Program Files\Telegraf? I'm no windows expert but this seems to be more idiomatic.

butitsnotme and others added 3 commits July 26, 2016 11:46
Updated the default location of the configuration file on Windows from
C:\telegraf\telegraf.conf to C:\Program Files\Telegraf\telegraf.conf.
With this change includes updating the directions, including directing
that the executable be put into that same directory. Additionally, as
noted in the instructions, the location of the config file for the
service may be changed by specifying the location with the `-config`
flag at install time.
svcConfig service.Config => svcConfig *service.Config
(It needed to be a pointer)
@willemdh
Copy link

Nice work @butitsnotme . Installation location C:\Program Files\Telegraf is perfect. This pr implies we will no longer need nssm. Looking forward to this!!

@steverweber
Copy link

like to see this in the v1.0 milestone.
also would be nice if the repo owners used milestones :)

sparrc added a commit that referenced this pull request Aug 8, 2016
this will now be the default config file location on windows, basically
it is the windows equivalent of /etc/telegraf/telegraf.conf

also updating the changelog

closes #1543
sparrc added a commit that referenced this pull request Aug 8, 2016
this will now be the default config file location on windows, basically
it is the windows equivalent of /etc/telegraf/telegraf.conf

also updating the changelog

closes #1543
sparrc added a commit that referenced this pull request Aug 8, 2016
this will now be the default config file location on windows, basically
it is the windows equivalent of /etc/telegraf/telegraf.conf

also updating the changelog

closes #1543
sparrc added a commit that referenced this pull request Aug 8, 2016
this will now be the default config file location on windows, basically
it is the windows equivalent of /etc/telegraf/telegraf.conf

also updating the changelog

closes #1543
@sparrc
Copy link
Contributor

sparrc commented Aug 8, 2016

thank you very much @butitsnotme!

@sparrc sparrc closed this in 8e22526 Aug 8, 2016
aurrelhebert pushed a commit to aurrelhebert/telegraf that referenced this pull request Aug 9, 2016
this will now be the default config file location on windows, basically
it is the windows equivalent of /etc/telegraf/telegraf.conf

also updating the changelog

closes influxdata#1543
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants