I am trying to use a ready-made bash script that sets env. This is the service that I'm trying to use:
[Unit]
Description=myserver service
After=multi-user.target
[Service]
Type=simple
User=ec2-user
Group=ec2-user
WorkingDirectory=/home/ec2-user/myserver/
ExecStart=/bin/sh -c '/home/ec2-user/myserver/config/myserverVars.sh ;/home/ec2-user/venv/bin/python /home/ec2-user/myserver/myserver.py 2>&1 >> /home/ec2-user/myserver/logs/systemd_myserver.log'
StandardOutput=append:/home/ec2-user/myserver/logs/systemd_stdout.log
StandardError=append:/home/ec2-user/myserver/logs/systemd_stderr.log
[Install]
WantedBy=multi-user.target
The myserverVars.sh
:
#!/bin/bash
export APP1=foo@gmail.com
export APP2_BIND_PASS=xxxxxx
export APP3=xxxxxx
the variables in /home/ec2-user/myserver/config/myserverVars.sh
are never set, and the server is started without the variables and this is wrong. I am trying to avoid using Environment key or Environment File.
Environment
is the native mechanism in systemd, and the service unit file is intended to directly contain environment settings. The systemd people considerEnvironmentFile
to have been a mistake, but converselyEnvironment
is the way to set environment variables, either directly or with drop-in "snippet" files. https://unix.stackexchange.com/a/557081/5132 – JdeBP Jun 12 '20 at 13:10