I am using Ubuntu 14.04 and 16.10; so my init system can be either upstart or systemd.
Things like How to set an environment variable in Amazon EC2 over on Stack Overflow show how one fetches an instance ID using
curl, then fetches instance tags using
aws ec2 describe-tags, then imports them as environment variables into an interactive shell, or a shell script. One of the answers also shows how one runs those data though
This is all well and good, but I don't need variables set in a shell script, or in an interactive shell. Having a shell script that is
sourced as in those answers is no good to me, as there isn't a shell involved in where I need these things set.
I need them set in the environments of dæmon processes that are started from systemd or upstart. In the systemd case, in particular, service unit files are not shell scripts at all. To set environment variables one puts things like
Environment= in the unit file.
So how can I create the last link in the chain? With what's on Stack Overflow I can get as far as reading the data and making environment-like
var=val strings out of them. (I am actually reading instance metadata and user data but the principle is the same — I pull stuff with
curl and then do the
jq and other post-processing to make
var=val out of it.)
How do I forge the final link in the chain and get these strings into the environments of specific services run by upstart and systemd?