Set environment variable globally

J Fernyhough j.fernyhough at gmail.com
Thu Apr 6 17:42:05 UTC 2017


On 06/04/17 16:36, Andrew Martin wrote:
> 
> It seems like that would have some performance impact. Setting TZ in the
> /etc/environment file doesn't appear to be used by upstart or systemd, and
> therefore apache2 doesn't use it either. How can I make it be used for services
> started by either init system?
> 

Not sure about upstart, but systemd should be straightforward enough.
You can add environment variables through editing the unit file
directly, or possibly better by:

1) Adding a conf file, e.g. in
/etc/systemd/system/apache2.service.d/tz.conf:

[Service]
Environment="TZ=:/etc/localtime"

2) globally for all units in /etc/systemd/system.conf, or e.g.
/etc/systemd/system.conf.d/tz.conf:

[Manager]
DefaultEnvironment="TZ=:/etc/localtime"


You'll need to do a daemon-reload and a service restart to pick up the
changes, but it should be there. Terrible, hacky, one-liner to check:

for p in $(pgrep -d" " apache2); do echo -e "$p:\n$(cat
/proc/$p/environ)\n"; done

J


https://www.freedesktop.org/software/systemd/man/systemd-system.conf.html

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 866 bytes
Desc: OpenPGP digital signature
URL: <https://lists.ubuntu.com/archives/ubuntu-devel-discuss/attachments/20170406/7c6d948c/attachment.sig>


More information about the Ubuntu-devel-discuss mailing list