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

set "HOME" after switching to netdata user #16548

Merged
merged 3 commits into from Dec 7, 2023
Merged

Conversation

ilyam8
Copy link
Member

@ilyam8 ilyam8 commented Dec 5, 2023

Summary

Fixes: #16511

I installed Netdata on FreeBSD using netdata-installer.sh and it failed to start service netdata start:

time=2023-12-05T15:15:26.079+02:00 comm=netdata source=daemon level=alert errno="21, Is a directory" tid=100760  msg="Cannot create required directory '/'"
0x4684bc <netdata_logger_fatal+0x1ec> at /opt/netdata/usr/sbin/netdata
0x41ece3 <set_global_environment+0x1423> at /opt/netdata/usr/sbin/netdata

The problem is:

  • main.c: on this line we set the home directory to the value of the “HOME” env var.
  • analytics.c: on this line we “verify” the value by creating/opening the dir and fatal on fail.

This happens before switching to the netdata user, so we are the root user. This means the value is incorrect, it is not "HOME" netdata. If you check [directory] home = in netdata.conf on your instances, you will see that it is /root. The "HOME" environment value is /root on Linux and / on FreeBSD. And the check function fails in FreeBSD => fatal.


The fix is:

  • do not use "HOME" env variable because it points to root's home (Netdata starts as root).
  • get the home directory of the user that Netdata is configured to run as and set "HOME" to it after switching to the new user.
Test Plan

Install on FreeBSD using netdata-installer.sh and make sure:

  • service netdata status/stop/start/restart works.
  • [directories] home in netdata.conf is set to the home directory of the user that Netdata is configured to run as (default: netdata).
Additional Information
For users: How does this change affect me?

@github-actions github-actions bot added area/packaging Packaging and operating systems support area/build Build system (autotools and cmake). labels Dec 5, 2023
@ilyam8 ilyam8 marked this pull request as ready for review December 6, 2023 11:37
vkalintiris
vkalintiris previously approved these changes Dec 6, 2023
daemon/main.c Show resolved Hide resolved
Copy link
Contributor

@thiagoftsm thiagoftsm left a comment

Choose a reason for hiding this comment

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

On FreeBSD 13.2-RELEASE-p7 everything worked as expected, LGTM!

@thiagoftsm thiagoftsm mentioned this pull request Dec 6, 2023
@ilyam8 ilyam8 merged commit 9fdf1c9 into netdata:master Dec 7, 2023
146 checks passed
@ilyam8 ilyam8 deleted the test-home branch December 7, 2023 13:25
stelfrag pushed a commit to stelfrag/netdata that referenced this pull request Dec 11, 2023
@stelfrag stelfrag mentioned this pull request Dec 11, 2023
stelfrag pushed a commit to stelfrag/netdata that referenced this pull request Dec 11, 2023
tkatsoulas pushed a commit that referenced this pull request Dec 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/build Build system (autotools and cmake). area/daemon area/packaging Packaging and operating systems support
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Netdata on FreeBSD 14 does not start or shutdown by system service
3 participants