# Custom beat based on metric doesn't run in the background when started via inet.d

**URL:** <https://discuss.elastic.co/t/custom-beat-based-on-metric-doesnt-run-in-the-background-when-started-via-inet-d/123215>\
**Category:** Beats\
**Tags:** beats-development\
**Created:** [March 9, 2018, 7:56am UTC](https://discuss.elastic.co/t/custom-beat-based-on-metric-doesnt-run-in-the-background-when-started-via-inet-d/123215 "2018-03-09T07:56:35Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![dcroonen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dcroonen/32/27450_2.png) [@dcroonen](https://discuss.elastic.co/u/dcroonen)\
**Post date:** [March 9, 2018, 7:56am UTC](https://discuss.elastic.co/t/custom-beat-based-on-metric-doesnt-run-in-the-background-when-started-via-inet-d/123215/1 "2018-03-09T07:56:35Z")

</div>

Hi all

When I package my beat based on metricbeat like [this](https://discuss.elastic.co/t/unable-to-compile-custom-beat-based-on-metricbeat/123085/2) and I install this beat on debian 7 (wheezy) the beat starts and works like expected but it refuses to run in the background when started via inet.d. If I install metricbeat on the same system metricbeat run perfectly in background when started via inet.d. I compared the inet.d startup scripts of both beats and these are exactly the same.

Does anybody has an explanation for this? Has this something to do the way I package my beat (without CGO support)? All thoughts are welcome.

Kind regards  
Davy

---

<div class="post-metadata">

**Author:** ![ruflin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ruflin/32/3116_2.png) [@ruflin](https://discuss.elastic.co/u/ruflin)\
**Post date:** [March 12, 2018, 10:27am UTC](https://discuss.elastic.co/t/custom-beat-based-on-metric-doesnt-run-in-the-background-when-started-via-inet-d/123215/2 "2018-03-12T10:27:28Z")

</div>

CGO should not have any affect here. Do you see anything in the logs which is different?

@andrewkroh might have some thoughts here.

---

<div class="post-metadata">

**Author:** ![dcroonen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dcroonen/32/27450_2.png) [@dcroonen](https://discuss.elastic.co/u/dcroonen)\
**Post date:** [March 12, 2018, 11:13am UTC](https://discuss.elastic.co/t/custom-beat-based-on-metric-doesnt-run-in-the-background-when-started-via-inet-d/123215/3 "2018-03-12T11:13:33Z")

</div>

Hi @ruflin

This is a log file entry from the startup of my own developed beat based on metricbeat:

```
2018-03-08T16:53:33.980+0100	INFO	instance/beat.go:468	Home path: [/usr/share/smartbeat] Config path: [/etc/smartbeat] Data path: [/var/lib/smartbeat] Logs path: [/var/log/smartbeat]
2018-03-08T16:53:33.982+0100	DEBUG	[beat]	instance/beat.go:495	Beat metadata path: /var/lib/smartbeat/meta.json
2018-03-08T16:53:33.982+0100	INFO	instance/beat.go:475	Beat UUID: 2cfe4c09-2176-43e7-864c-506f3034d966
2018-03-08T16:53:33.982+0100	INFO	instance/beat.go:213	Setup Beat: smartbeat; Version: 6.2.3
2018-03-08T16:53:33.982+0100	WARN	instance/metrics_other.go:8	Metrics not implemented for this OS.
2018-03-08T16:53:33.982+0100	DEBUG	[beat]	instance/beat.go:230	Initializing output plugins
2018-03-08T16:53:33.982+0100	DEBUG	[processors]	processors/processor.go:49	Processors:
2018-03-08T16:53:33.983+0100	INFO	pipeline/module.go:76	Beat name: puppetwheezy

```

and this is one from metricbeat:

```
|2018-03-12T11:56:51.502+0100|INFO|instance/beat.go:468|Home path: [/usr/share/metricbeat] Config path: [/etc/metricbeat] Data path: [/var/lib/metricbeat] Logs path: [/var/log/metricbeat]
|2018-03-12T11:56:51.502+0100|INFO|instance/beat.go:475|Beat UUID: d21c660c-c508-4ab0-bb88-ebe5f1c5661f|
|2018-03-12T11:56:51.502+0100|INFO|instance/beat.go:213|Setup Beat: metricbeat; Version: 6.2.2|
|2018-03-12T11:56:51.504+0100|INFO|pipeline/module.go:76|Beat name: puppetwheezy|
|2018-03-12T11:56:51.505+0100|INFO|instance/beat.go:301|metricbeat start running.|

```

As you can see they are quite similar except from the fact that in the log entries of my beat there are showing up DEBUG messages. This makes me suspecting that there is some kind of flag to be set at compile time so that the beat will run as a daemon instead of running in the foreground. I searched the code but could not find any such flag or something similar. Any comments?

Regards  
Davy

---

<div class="post-metadata">

**Author:** ![ruflin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ruflin/32/3116_2.png) [@ruflin](https://discuss.elastic.co/u/ruflin)\
**Post date:** [March 13, 2018, 8:29am UTC](https://discuss.elastic.co/t/custom-beat-based-on-metric-doesnt-run-in-the-background-when-started-via-inet-d/123215/4 "2018-03-13T08:29:31Z")

</div>

Did you install both beats the same way, meaning with the `deb` package?

There is a difference between the "raw" binaries and the one installed through the packages. They are wrapped into a `god` (go-deamon) to be running in the background.

---

<div class="post-metadata">

**Author:** ![dcroonen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dcroonen/32/27450_2.png) [@dcroonen](https://discuss.elastic.co/u/dcroonen)\
**Post date:** [March 13, 2018, 3:19pm UTC](https://discuss.elastic.co/t/custom-beat-based-on-metric-doesnt-run-in-the-background-when-started-via-inet-d/123215/5 "2018-03-13T15:19:08Z")

</div>

Yes, they are both installed the same way, via the .deb packages. The only difference is that metricbeat is build by you guys and smartbeat by us.

---

<div class="post-metadata">

**Author:** ![andrewkroh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrewkroh/32/3784_2.png) [@andrewkroh](https://discuss.elastic.co/u/andrewkroh)\
**Post date:** [March 14, 2018, 1:55pm UTC](https://discuss.elastic.co/t/custom-beat-based-on-metric-doesnt-run-in-the-background-when-started-via-inet-d/123215/6 "2018-03-14T13:55:30Z")

</div>

> [@dcroonen](#):
>
> but it refuses to run in the background when started via inet.d

Do you get some kind of error? The daemonizing is handled by [go-daemon](https://github.com/tsg/go-daemon) when using SysV (inet.d). You'll see that the init script [calls](https://github.com/elastic/beats/blob/master/dev-tools/packer/platforms/debian/init.j2#L23) a {{beatname}}-god binary.

> [@dcroonen](#):
>
> 2018-03-08T16:53:33.982+0100 WARN instance/metrics\_other.go:8 Metrics not implemented for this OS.

On a side note, that should be fixed now in master by [https://github.com/elastic/beats/pull/6501](https://github.com/elastic/beats/pull/6501).

---

<div class="post-metadata">

**Author:** ![dcroonen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dcroonen/32/27450_2.png) [@dcroonen](https://discuss.elastic.co/u/dcroonen)\
**Post date:** [March 15, 2018, 9:36am UTC](https://discuss.elastic.co/t/custom-beat-based-on-metric-doesnt-run-in-the-background-when-started-via-inet-d/123215/7 "2018-03-15T09:36:54Z")

</div>

Hi @andrewkroh, hi @ruflin

I found the cause of the problem or at least a part of it. Running `/usr/share/smartbeat/bin/smartbeat -h` reveals this output:

```
Usage of /usr/share/smartbeat/bin/smartbeat:
  -E value
    	Configuration overwrite
  -N	Disable actual publishing for testing
  -c value
    	Configuration file, relative to path.config (default beat.yml)
  -configtest
    	Test configuration and exit.
  -cpuprofile string
    	Write cpu profile to file
  -d value
    	Enable certain debug selectors
  -e	Log to stderr and disable syslog/file output
  -httpprof string
    	Start pprof http server
  -httptest.serve string
    	if non-empty, httptest.NewServer serves on this address and blocks
  -memprofile string
    	Write memory profile to this file
  -path.config value
    	Configuration path
  -path.data value
    	Data path
  -path.home value
    	Home path
  -path.logs value
    	Logs path
  -setup
    	Load the sample Kibana dashboards
  -strict.perms
    	Strict permission checking on config files (default true)
  -system.hostfs string
    	mountpoint of the host's filesystem for use in monitoring a host from within a container
  -v	Log at INFO level
  -version
    	Print the version and exit

```

there are no `test` and `config` options available like in `$TEST_ARGS` in the init.d script of smartbeat. Replacing `test` and `config` in the init.d script by `-configtest` resolves the issue.

But.... Starting my own beat this way outputs:

```
 /etc/init.d/smartbeat start
2018-03-15T10:20:13.610+0100	INFO	instance/beat.go:468	Home path: [/usr/share/smartbeat/bin] Config path: [/usr/share/smartbeat/bin] Data path: [/usr/share/smartbeat/bin/data] Logs path: [/usr/share/smartbeat/bin/logs]
2018-03-15T10:20:13.611+0100	INFO	instance/beat.go:475	Beat UUID: d647fa4d-b908-4d0e-ba31-703cb82a2cd9
2018-03-15T10:20:13.615+0100	INFO	instance/beat.go:213	Setup Beat: smartbeat; Version: 6.2.3
2018-03-15T10:20:13.615+0100	WARN	instance/metrics_other.go:8	Metrics not implemented for this OS.
2018-03-15T10:20:13.617+0100	INFO	pipeline/module.go:76	Beat name: puppetwheezy
2018-03-15T10:20:13.618+0100	WARN	status/status.go:49	EXPERIMENTAL: The gearmand status metricset is experimental
2018-03-15T10:20:13.618+0100	WARN	[cfgwarn]	instance/beat.go:283	DEPRECATED: -configtest flag has been deprecated, use configtest subcommand Will be removed in version: 6.0
Config OK
2018-03-15T10:20:13.618+0100	INFO	[monitoring]	log/log.go:97	Starting metrics logging every 30s
2018-03-15T10:20:13.618+0100	INFO	[monitoring]	log/log.go:132	Total non-zero metrics	{"monitoring": {"metrics": {"libbeat":{"config":{"module":{"running":0}},"output":{"type":"redis"},"pipeline":{"clients":0,"events":{"active":0}}}}}}
2018-03-15T10:20:13.619+0100	INFO	[monitoring]	log/log.go:133	Uptime: 20.734141ms
2018-03-15T10:20:13.619+0100	INFO	[monitoring]	log/log.go:110	Stopping metrics logging.

```

There is a **contradiction** in it as you can see the version of my beat is `6.2.3` while there's a message saying:

`2018-03-15T10:20:13.618+0100	WARN	[cfgwarn]	instance/beat.go:283	DEPRECATED: -configtest flag has been deprecated, use configtest subcommand Will be removed in version: 6.0`

As far as I know I started building my beat against version 6.0 of the metricbeat library, in the mean time I upgraded towards version 6.2 of the metricbeat library but I looks like there were libraries used from before version 6.0 of the metricbeat library. Any clues of what could be (went) wrong???

Regards

---

<div class="post-metadata">

**Author:** ![ruflin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ruflin/32/3116_2.png) [@ruflin](https://discuss.elastic.co/u/ruflin)\
**Post date:** [March 15, 2018, 10:37am UTC](https://discuss.elastic.co/t/custom-beat-based-on-metric-doesnt-run-in-the-background-when-started-via-inet-d/123215/8 "2018-03-15T10:37:12Z")

</div>

The first thing that popped up in my head is that there could be potentially a different version of libbeat/metricbeat under `GOPATH/src/github.com/elastic/beats` and `GOPATH/src/yourbeat/vendor/github.com/elastic/beats`. And for some parts it uses the code in vendor and for some parts the code outside?

---

<div class="post-metadata">

**Author:** ![dcroonen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dcroonen/32/27450_2.png) [@dcroonen](https://discuss.elastic.co/u/dcroonen)\
**Post date:** [March 16, 2018, 2:53pm UTC](https://discuss.elastic.co/t/custom-beat-based-on-metric-doesnt-run-in-the-background-when-started-via-inet-d/123215/9 "2018-03-16T14:53:31Z")

</div>

Hi @ruflin

I now took a whole new virtual machine, followed exactly [this](https://www.elastic.co/guide/en/beats/devguide/6.2/creating-beat-from-metricbeat.html) guide, generated the examplebeat and packaged this beat with `make package`. I took the file `examplebeat-6.2.3-SNAPSHOT-amd64.deb` and installed it on a Debian Wheezy OS, running `/usr/share/examplebeat/bin/examplebeat -h` gave this output:

```
/usr/share/examplebeat/bin/examplebeat -h
Usage of /usr/share/examplebeat/bin/examplebeat:
  -E value
    	Configuration overwrite
  -N	Disable actual publishing for testing
  -c value
    	Configuration file, relative to path.config (default beat.yml)
  -configtest
    	Test configuration and exit.
  -cpuprofile string
    	Write cpu profile to file
  -d value
    	Enable certain debug selectors
  -e	Log to stderr and disable syslog/file output
  -httpprof string
    	Start pprof http server
  -httptest.serve string
    	if non-empty, httptest.NewServer serves on this address and blocks
  -memprofile string
    	Write memory profile to this file
  -path.config value
    	Configuration path
  -path.data value
    	Data path
  -path.home value
    	Home path
  -path.logs value
    	Logs path
  -plugin value
    	Load additional plugins
  -setup
    	Load the sample Kibana dashboards
  -strict.perms
    	Strict permission checking on config files (default true)
  -system.hostfs string
    	mountpoint of the host's filesystem for use in monitoring a host from within a container
  -v	Log at INFO level
  -version
    	Print the version and exit

```

Running the command `/etc/init.d/examplebeat start` also did not make the beat running in the background. Can you have a look if you can reproduce this?

---

<div class="post-metadata">

**Author:** ![ruflin](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ruflin/32/3116_2.png) [@ruflin](https://discuss.elastic.co/u/ruflin)\
**Post date:** [March 21, 2018, 7:26am UTC](https://discuss.elastic.co/t/custom-beat-based-on-metric-doesnt-run-in-the-background-when-started-via-inet-d/123215/10 "2018-03-21T07:26:52Z")

</div>

Hi dcroonen

I can definitively try to reproduce this on my end but will probably not get to it this week. Did you still see the version mismatch in the logs?

---

<div class="post-metadata">

**Author:** ![dcroonen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dcroonen/32/27450_2.png) [@dcroonen](https://discuss.elastic.co/u/dcroonen)\
**Post date:** [March 23, 2018, 2:25pm UTC](https://discuss.elastic.co/t/custom-beat-based-on-metric-doesnt-run-in-the-background-when-started-via-inet-d/123215/11 "2018-03-23T14:25:25Z")

</div>

Hi @ruflin

I think you can stop searching. The explanation can be found in [this](https://discuss.elastic.co/t/export-template-from-custom-beat-based-on-metricbeat/119250/6) topic.

To summarize the `init.d` script of my beat (as compiled with the make scripts provided in the beat library) uses the subcommand `config test` to test the config at startup, but as explained in the referenced topic the subcommands aren't available in custom generated beats because the generator doesn't take them into account.

As a workaround I modified the `/etc/init.d` startup script to use `-configtest` instead of `test config`. But anyway this is some kind of a bug. Or the subcommands need to be available in custom generated beats or the `inet.d` startup scripts need to use the 'old' parameters instead of the subcommands to test the configfile at startup.

Regards  
Davy

---

<div class="post-metadata">

**Author:** ![andrewkroh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrewkroh/32/3784_2.png) [@andrewkroh](https://discuss.elastic.co/u/andrewkroh)\
**Post date:** [March 23, 2018, 2:41pm UTC](https://discuss.elastic.co/t/custom-beat-based-on-metric-doesnt-run-in-the-background-when-started-via-inet-d/123215/12 "2018-03-23T14:41:30Z")

</div>

FYI There's a bug open for the code generator issue.

> <https://github.com/elastic/beats/issues/6550>

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [April 20, 2018, 2:41pm UTC](https://discuss.elastic.co/t/custom-beat-based-on-metric-doesnt-run-in-the-background-when-started-via-inet-d/123215/13 "2018-04-20T14:41:35Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
