Re: Set environment variable globally

2017-04-06 Thread Andrew Martin
- Original Message -
> From: "J Fernyhough" 
> To: "amartin" 
> Cc: "ubuntu-devel-discuss" 
> 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


Re: Set environment variable globally

2017-04-06 Thread J Fernyhough
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



signature.asc
Description: OpenPGP digital signature
-- 
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


Re: Set environment variable globally

2017-04-06 Thread Andrew Martin
- Original Message -
> From: "J Fernyhough" 
> To: "ubuntu-devel-discuss" 
> Sent: Wednesday, April 5, 2017 2:01:26 PM
> Subject: Re: Set environment variable globally

> On 24/03/17 21:19, Andrew Martin wrote:
>> Hello,
>> 
>> I recently saw this blog post regarding performance when the TZ environment
>> variable is not set:
>> https://blog.packagecloud.io/eng/2017/02/21/set-environment-variable-save-thousands-of-system-calls/
>> 
> 
> There's also a good deal of discussion on the HN thread:
> https://news.ycombinator.com/item?id=13697555

Thanks, I had not seen this!

> 
>> I tried defining TZ in /etc/environment and in /etc/profile.d/test.sh, but I
>> cannot get this environment variable to be available in all cases (e.g. if I
>> just execute bash without --login or if I run the sample c program provided 
>> in
>> the above article). How can I make the TZ environment variable defined
>> completely system-wide?
> 
> Before you go too far with that, is there a specific reason you want to
> do this? For example, there's not generally a lot of advantage unless
> you have a process that does a lot of timezone-based processing.
> 
> However, all you should need in /etc/environment is:
> 
> TZ=:/etc/localtime
> 
> or an equivalent TZ value, e.g.:
> 
> TZ=:Europe/London
> 

I've noticed apache2 reading /etc/localtime a lot when running; this is also
mentioned in the HN thread:
http://mail-archives.apache.org/mod_mbox/httpd-dev/20.mbox/%3CCAMDeyhzRAZ4eyz%3D%2BstA%3DwoTibM-W6QL8TqT%2BaPio07UddCz7Tg%40mail.gmail.com%3E

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?

Thanks,

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


Re: Set environment variable globally

2017-04-05 Thread J Fernyhough
On 24/03/17 21:19, Andrew Martin wrote:
> Hello,
> 
> I recently saw this blog post regarding performance when the TZ environment
> variable is not set:
> https://blog.packagecloud.io/eng/2017/02/21/set-environment-variable-save-thousands-of-system-calls/
> 

There's also a good deal of discussion on the HN thread:
https://news.ycombinator.com/item?id=13697555

> I tried defining TZ in /etc/environment and in /etc/profile.d/test.sh, but I
> cannot get this environment variable to be available in all cases (e.g. if I
> just execute bash without --login or if I run the sample c program provided in
> the above article). How can I make the TZ environment variable defined
> completely system-wide?

Before you go too far with that, is there a specific reason you want to
do this? For example, there's not generally a lot of advantage unless
you have a process that does a lot of timezone-based processing.

However, all you should need in /etc/environment is:

TZ=:/etc/localtime

or an equivalent TZ value, e.g.:

TZ=:Europe/London


J




signature.asc
Description: OpenPGP digital signature
-- 
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


Re: Set environment variable globally

2017-04-05 Thread Gunnar Hjalmarsson

On 2017-04-05 20:30, Andrew Martin wrote:

From: "Gérard BIGOT" 


I added this line in /etc/environment since a long time :

TZ="Europe/Paris"

It gives me satisfaction.


I can't seem to get this to work on 16.04. Which shell are you
using? Have you customized your /etc/bash.bashrc or /etc/profile to
source /etc/environment? I don't see any mention of /etc/environment
in the bash manpage, so it seems like this file isn't being used.
Also, how can I make this environment variable available to all
processes started by upstart (14.04) and systemd (16.04)? I am
concerned not only about interactive processes but also scripts (e.g.
started via cron) and services (started via upstart or systemd).


/etc/environment is not a script file; it's read by PAM. But I don't 
think that happens early enough for services etc.


--
Gunnar Hjalmarsson
https://launchpad.net/~gunnarhj

--
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


Re: Set environment variable globally

2017-04-05 Thread Andrew Martin
- Original Message -
> From: "Gérard BIGOT" 
> To: "amartin" 
> Cc: "ubuntu-devel-discuss" 
> Sent: Friday, March 31, 2017 8:41:36 AM
> Subject: Re: Set environment variable globally

> Hi,
> 
> I added this line in /etc/environment since a long time :
> 
> TZ="Europe/Paris"
> 
> It gives me satisfaction.
> 
> With this line, upon reboot, I have :
> 
> ~$ echo $TZ
> Europe/Paris
> 
> Without TZ doesn't exist.
> 
Gérard,

I can't seem to get this to work on 16.04. Which shell are you using?
Have you customized your /etc/bash.bashrc or /etc/profile to source
/etc/environment? I don't see any mention of /etc/environment in the
bash manpage, so it seems like this file isn't being used. Also, how
can I make this environment variable available to all processes started
by upstart (14.04) and systemd (16.04)? I am concerned not only about
interactive processes but also scripts (e.g. started via cron) and
services (started via upstart or systemd).

Thanks,

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


Re: Set environment variable globally

2017-03-31 Thread Gunnar Hjalmarsson

On 2017-03-24 22:19, Andrew Martin wrote:

I recently saw this blog post regarding performance when the TZ
environment variable is not set:
https://blog.packagecloud.io/eng/2017/02/21/set-environment-variable-save-thousands-of-system-calls/

I have noticed this problem when stracing running daemons on my
systems and would like to fix it. I reviewed the official Ubuntu
documentation for where to define environment variables:
https://help.ubuntu.com/community/EnvironmentVariables

I tried defining TZ in /etc/environment and in
/etc/profile.d/test.sh, but I cannot get this environment variable to
be available in all cases (e.g. if I just execute bash without
--login or if I run the sample c program provided in the above
article). How can I make the TZ environment variable defined
completely system-wide?


Also asked at .

--
Gunnar Hjalmarsson
https://launchpad.net/~gunnarhj

--
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


Re: Set environment variable globally

2017-03-31 Thread Gérard BIGOT
Hi,

I added this line in /etc/environment since a long time :

TZ="Europe/Paris"

It gives me satisfaction.

With this line, upon reboot, I have :

~$ echo $TZ
Europe/Paris

Without TZ doesn't exist.

G.
PS: You don't have to live in Paris for this to work, I guess.
It should work with whatever lines in 'timedatectl list-timezones'

2017-03-24 22:19 GMT+01:00 Andrew Martin :

> Hello,
>
> I recently saw this blog post regarding performance when the TZ environment
> variable is not set:
> https://blog.packagecloud.io/eng/2017/02/21/set-environment-variable-save-
> thousands-of-system-calls/
>
> I have noticed this problem when stracing running daemons on my systems and
> would like to fix it. I reviewed the official Ubuntu documentation for
> where to
> define environment variables:
> https://help.ubuntu.com/community/EnvironmentVariables
>
> I tried defining TZ in /etc/environment and in /etc/profile.d/test.sh, but
> I
> cannot get this environment variable to be available in all cases (e.g. if
> I
> just execute bash without --login or if I run the sample c program
> provided in
> the above article). How can I make the TZ environment variable defined
> completely system-wide?
>
> Thanks,
>
> 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
>
-- 
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


Set environment variable globally

2017-03-24 Thread Andrew Martin
Hello,

I recently saw this blog post regarding performance when the TZ environment
variable is not set:
https://blog.packagecloud.io/eng/2017/02/21/set-environment-variable-save-thousands-of-system-calls/

I have noticed this problem when stracing running daemons on my systems and
would like to fix it. I reviewed the official Ubuntu documentation for where to
define environment variables:
https://help.ubuntu.com/community/EnvironmentVariables

I tried defining TZ in /etc/environment and in /etc/profile.d/test.sh, but I
cannot get this environment variable to be available in all cases (e.g. if I
just execute bash without --login or if I run the sample c program provided in
the above article). How can I make the TZ environment variable defined
completely system-wide?

Thanks,

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