Skip to content

Commit

Permalink
Add ability to define a custom service name when installing as a Wind…
Browse files Browse the repository at this point in the history
…ows service (influxdata#4753)
  • Loading branch information
Jaeyo authored and otherpirate committed Mar 15, 2019
1 parent a53d1e3 commit 0c31d31
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion cmd/telegraf/telegraf.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ var fUsage = flag.String("usage", "",
"print usage for a plugin, ie, 'telegraf --usage mysql'")
var fService = flag.String("service", "",
"operate on the service (windows only)")
var fServiceName = flag.String("service-name", "telegraf", "service name (windows only)")
var fRunAsConsole = flag.Bool("console", false, "run as console application (windows only)")

var (
Expand Down Expand Up @@ -327,7 +328,7 @@ func main() {

if runtime.GOOS == "windows" && !(*fRunAsConsole) {
svcConfig := &service.Config{
Name: "telegraf",
Name: *fServiceName,
DisplayName: "Telegraf Data Collector Service",
Description: "Collects data using a series of plugins and publishes it to" +
"another series of plugins.",
Expand Down
10 changes: 10 additions & 0 deletions docs/WINDOWS_SERVICE.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ Telegraf can manage its own service through the --service flag:
| `telegraf.exe --service start` | Start the telegraf service |
| `telegraf.exe --service stop` | Stop the telegraf service |

## Install multiple services

You can install multiple telegraf instances with --service-name flag:

```
> C:\"Program Files"\Telegraf\telegraf.exe --service install --service-name telegraf-1
> C:\"Program Files"\Telegraf\telegraf.exe --service install --service-name telegraf-2
> C:\"Program Files"\Telegraf\telegraf.exe --service uninstall --service-name telegraf-1
```

Troubleshooting common error #1067

When installing as service in Windows, always double check to specify full path of the config file, otherwise windows service will fail to start
Expand Down
4 changes: 4 additions & 0 deletions internal/usage_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ The commands & flags are:
--console run as console application (windows only)
--service <service> operate on the service (windows only)
--service-name service name (windows only)
Examples:
Expand All @@ -59,4 +60,7 @@ Examples:
# install telegraf service
telegraf --service install --config "C:\Program Files\Telegraf\telegraf.conf"
# install telegraf service with custom name
telegraf --service install --service-name=my-telegraf
`

0 comments on commit 0c31d31

Please sign in to comment.