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 [email protected]
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.
Environmentis the native mechanism in systemd, and the service unit file is intended to directly contain environment settings. The systemd people considerEnvironmentFileto have been a mistake, but converselyEnvironmentis the way to set environment variables, either directly or with drop-in "snippet" files. unix.stackexchange.com/a/557081/5132