Repository: vectordotdev/vector (language: rust)

Issue:
Systemctl reload wont work when using splunk_hec source
### A note for the community

<!-- Please keep this note for the community -->
* Please vote on this issue by adding a 👍 [reaction](https://blog.github.com/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/) to the original issue to help the community and maintainers prioritize this request
* If you are interested in working on this issue or have submitted a pull request, please leave a comment
<!-- Thank you for keeping this note for the community -->


### Problem

Because of #20589 and https://github.com/vectordotdev/vector/blob/a60b8bb9b84e7f70a2fe58c3b01d79f8542ef91b/distribution/systemd/vector.service#L12

If you have a configuration using splunk_hec source, and you try to run a systemctl reload vector, it will fail because validate is not running with `--no-environment` as explained in https://github.com/vectordotdev/vector/issues/20589#issuecomment-2145685782.


### Configuration

```text

```

### Version

vector 0.44.0 (x86_64-unknown-linux-gnu 3cdc7c3 2025-01-13 21:26:04.735691656)

### Debug Output

```text

```

### Example Data

_No response_

### Additional Context

_No response_

### References

_No response_


Discussion / hints:
Thanks for raising this issue. It would be helpful if you added a config and sample output demonstrating the error.
Based on https://github.com/vectordotdev/vector/issues/20589#issuecomment-2145685782, the `splunk_hec` works correctly with `validate`. You should pass `--no-environment` on reload. We should update the `vector` and `socket` sources to  be consistent with `splunk_hec`. cc @jszwedko (in case I misunderstood something here)     
> Based on [#20589 (comment)](https://github.com/vectordotdev/vector/issues/20589#issuecomment-2145685782), the `splunk_hec` works correctly with `validate`. You should pass `--no-environment` on reload. We should update the `vector` and `socket` sources to be consistent with `splunk_hec`. cc [@jszwedko](https://github.com/jszwedko) (in case I misunderstood something here)

My take on it is that (1) we should be consistent across components that bind to ports whether or not they bind with `vector validate` and (2) with `--no-environment` components shouldn't try to bind and without `--no-environment` components should try to bind.

I could be persuaded on the 2nd point. I haven't thought deeply about all of the implications.

Here the unit file we ship doesn't use `--no-environment` and so it is expected (in my opinion) that it should try to bind. Perhaps the systemd unit file should specify `--no-environment` though 🤔 
> My take on it is that (1) we should be consistent across components that bind to ports whether or not they bind with vector validate 

+1. I need to follow up to validate this but I was under the impression the `socket` source (at the very least) tries to bind to the specified address.

> Perhaps the systemd unit file should specify --no-environment though

I agree with the above, basically:

```
ExecStartPre=/usr/bin/vector validate
...
ExecReload=/usr/bin/vector validate --no-environment
```

The first validates that Vector can acquire the resources e.g. ports. If the Vector instance starts then we know that those resources are probably taken so we should not assert that they are free. 

I am going to close this issue based on the above recommendation. @rsrdesarrollo you are welcome to follow-up if you want further discussions.
> I agree with the above, basically:
> 
> ```
> ExecStartPre=/usr/bin/vector validate
> ...
> ExecReload=/usr/bin/vector validate --no-environment
> ```
> 
> The first validates that Vector can acquire the resources e.g. ports. If the Vector instance starts then we know that those resources are probably taken so we should not assert that they are free.

👍 I think this makes sense and should fix the issue here.
> I agree with the above, basically:
> 
> ```
> ExecStartPre=/usr/bin/vector validate
> ...
> ExecReload=/usr/bin/vector validate --no-environment
> ```
> 
> The first validates that Vector can acquire the resources e.g. ports. If the Vector instance starts then we know that those resources are probably taken so we should not assert that they are free.

@pront yes, that's all that is needed. Shall I create a PR with this?
> > I agree with the above, basically:
> > ```
> > ExecStartPre=/usr/bin/vector validate
> > ...
> > ExecReload=/usr/bin/vector validate --no-environment
> > ```
> > 
> > 
> >     
> >       
> >     
> > 
> >       
> >     
> > 
> >     
> >   
> > The first validates that Vector can acquire the resources e.g. ports. If the Vector instance starts then we know that those resources are probably taken so we should not assert that they are free.
> 
> [@pront](https://github.com/pront) yes, that's all that is needed. Shall I create a PR with this?

Yes, thank you!

Fix patch:
diff --git a/changelog.d/22279_systemd_service_reload.fix.md b/changelog.d/22279_systemd_service_reload.fix.md
new file mode 100644
index 0000000000000..1d9c1febb7e05
--- /dev/null
+++ b/changelog.d/22279_systemd_service_reload.fix.md
@@ -0,0 +1,3 @@
+The systemd service now validates the config with parameter `--no-environment` on service reload.
+
+authors: rsrdesarrollo
diff --git a/distribution/systemd/vector.service b/distribution/systemd/vector.service
index d9c6e78431aa4..b78ff3131e3cf 100644
--- a/distribution/systemd/vector.service
+++ b/distribution/systemd/vector.service
@@ -9,7 +9,7 @@ User=vector
 Group=vector
 ExecStartPre=/usr/bin/vector validate
 ExecStart=/usr/bin/vector
-ExecReload=/usr/bin/vector validate
+ExecReload=/usr/bin/vector validate --no-environment
 ExecReload=/bin/kill -HUP $MAINPID
 Restart=always
 AmbientCapabilities=CAP_NET_BIND_SERVICE


Test patch: