4

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

2
  • On what distribution? Commented Jun 30, 2017 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
    Commented Jun 30, 2017 at 22:28

1 Answer 1

4

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.

8
  • disregarding LD_PRELOAD, for common variables : can I set them using a fake demon script in /etc/init.d ?
    – Massimo
    Commented Jul 4, 2017 at 16:32
  • does yor cron example set the variable system wide or only for the same line job ?
    – Massimo
    Commented Jul 4, 2017 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���. Commented Jul 5, 2017 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
    Commented Jul 5, 2017 at 17:21
  • what about, as universal solution, a script in /etc/profile.d/ ?
    – Massimo
    Commented Jul 19, 2017 at 22:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .