I have processes started as daemons or from cron.

They can run under users account without a shell.

  1. how can I set system wide environment variables ? I mean the environment sourced to all processes, prior to user logins.

  2. have I to account for special considerations, tricks, side effects ? specifically about the variable LD_PRELOAD

  • On what distribution? – Gilles 'SO- stop being evil' Jun 30 '17 at 21:18
  • unfortunately our farm has centos debian and ubuntu servers, from 2.4 to 3.x kernels (running legacy software and providers don't help to update, their policy is 'the server is in LAN and it is running ...') – Massimo Jun 30 '17 at 22:28

There is no universal method to set system-wide environment variables.

With systemd, add Environment= statements to the service configuration.

With Upstart, add env statements to the job configuration.

With SysVinit, add export statements to the service startup script.

For cron jobs, add VAR=VALUE lines to the crontab.

LD_PRELOAD changes the behavior of a program in ways that were not intended by the author of the program, so you should set it only for the programs that really need it. Even if there was a way to set a system-wide environment variable, LD_PRELOAD should not be set so broadly.

| improve this answer | |
  • disregarding LD_PRELOAD, for common variables : can I set them using a fake demon script in /etc/init.d ? – Massimo Jul 4 '17 at 16:32
  • does yor cron example set the variable system wide or only for the same line job ? – Massimo Jul 4 '17 at 16:34
  • @Massimo A variable that is set in a crontab is set for the jobs in that crontab. Cron has no way to influence the environment of things other than cron jobs. I don't know what you mean by “fake demon script”. – Gilles 'SO- stop being evil' Jul 5 '17 at 12:16
  • I found in the past daemons that don't launch forever living processes, but just make some actions and "quit" ( no process left running ). So they have only a "start" action and the "stop" is really a NOP. – Massimo Jul 5 '17 at 17:21
  • what about, as universal solution, a script in /etc/profile.d/ ? – Massimo Jul 19 '17 at 22:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.