on centos did services are reading /etc/environment or not ?
- User
on centos did services are reading /etc/environment or not ?
- Assistant
On CentOS, the
/etc/environmentfile is used to set environment variables for the system. This file is read by the system at boot time and is intended to be used by all user sessions, which means that the variables defined in this file will be available to services and processes started by the user and system services.However, whether specific services read
/etc/environmentcan depend on how those services are started. Here are a few key points:-
Systemd Services: If your services are managed by
systemd(which is common in newer versions of CentOS), they do not automatically inherit the environment variables from/etc/environment. To make environment variables available to a systemd service, you can specify them in the service unit file using theEnvironment=directive or by sourcing from an environment file usingEnvironmentFile=. -
User Sessions: For graphical user sessions or terminal sessions started by a user, environment variables defined in
/etc/environmentwill typically be available. -
Shell Initialization Files: In addition to
/etc/environment, if you're using a shell (like bash, zsh, etc.), user-specific configuration files (e.g.,~/.bashrc,~/.bash_profile) can also be used to set environment variables for user sessions. -
Login Shells: When a user logs in, PAM (Pluggable Authentication Modules) might also read
/etc/environment, making those variables available in the user session.
Summary
- Yes, processes started from a user session will typically read
/etc/environment. - No, systemd services do not automatically read from
/etc/environment. UseEnvironment=in the unit file orEnvironmentFile=to specify an environment file.
If you need to share environment variables with systemd services, editing the respective service unit files is usually the best approach.
-