----- Original Message ----- > From: "J Fernyhough" <j.fernyho...@gmail.com> > To: "amartin" <amar...@xes-inc.com> > Cc: "ubuntu-devel-discuss" <ubuntu-devel-discuss@lists.ubuntu.com> > Sent: Thursday, April 6, 2017 12:42:05 PM > Subject: Re: Set environment variable globally
> 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 Thanks, this looks like it should work well. I can over most cases with the following: add this to /etc/systemd/system.conf.d/tz.conf for services: [Manager] DefaultEnvironment="TZ=:/etc/localtime" add this to /etc/profile.d/tz.sh for login shells: export TZ=:/etc/localtime add this to /etc/bash.bashrc for interactive non-login shells: export TZ=:/etc/localtime add this to /etc/environment as a catch-all: TZ=:/etc/localtime Andrew -- Ubuntu-devel-discuss mailing list Ubuntu-devel-discuss@lists.ubuntu.com Modify settings or unsubscribe at: https://lists.ubuntu.com/mailman/listinfo/ubuntu-devel-discuss