Skip to main content
added 147 characters in body
Source Link
terdon
  • 252.2k
  • 69
  • 480
  • 718

If you want variables defined in a script file to be available to the parent environment running that script, you need to source the script, not execute it. Change your ExecStart line to:

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'log 2>&1 ' 

See What is the difference between sourcing ('.' or 'source') and executing a file in bash? for details on the difference between sourcing and executing a script.

Also note that I changed the order of redirections. To get both stderr and stdout to the same file, you need > file 2>&1 not 2>&1 > file.

If you want variables defined in a script file to be available to the parent environment running that script, you need to source the script, not execute it. Change your ExecStart line to:

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' 

See What is the difference between sourcing ('.' or 'source') and executing a file in bash? for details on the difference between sourcing and executing a script.

If you want variables defined in a script file to be available to the parent environment running that script, you need to source the script, not execute it. Change your ExecStart line to:

ExecStart=/bin/sh -c '. /home/ec2-user/myserver/config/myserverVars.sh ;/home/ec2-user/venv/bin/python  /home/ec2-user/myserver/myserver.py >> /home/ec2-user/myserver/logs/systemd_myserver.log 2>&1 ' 

See What is the difference between sourcing ('.' or 'source') and executing a file in bash? for details on the difference between sourcing and executing a script.

Also note that I changed the order of redirections. To get both stderr and stdout to the same file, you need > file 2>&1 not 2>&1 > file.

Source Link
terdon
  • 252.2k
  • 69
  • 480
  • 718

If you want variables defined in a script file to be available to the parent environment running that script, you need to source the script, not execute it. Change your ExecStart line to:

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' 

See What is the difference between sourcing ('.' or 'source') and executing a file in bash? for details on the difference between sourcing and executing a script.