I am setting up a Linux service for my Python app using Upstart. Here is the conf
file in /etc/init/
description "AAE client app"
start on runlevel [2345]
stop on runlevel [!2345]
respawn
env PATH=/home/ec2-user/aae_client/env/bin
env PROGRAM_NAME="aae"
env USERNAME="ec2-user"
# Main script to be run
script
echo "[`date -u +%Y-%m-%dT%T.%3NZ`] (sys) Ready to run..." >> /var/log/$PROGRAM_NAME.sys.log
export HOME="/home/ec2-user"
echo $$ > /var/run/$PROGRAM_NAME.pid
cd /home/ec2-user/aae_client
exec python -m app.run >> /var/log/$PROGRAM_NAME.sys.log 2>&1
end script
I already set the USERNAME
to ec2-user
. However when I run the service, it shows it is run by root
. Apparently other variables such as PATH
are set correctly. Why does it still run as root when USERNAME is specified?
Changing USERNAME
or even the canonical USER
variable does not change the context the processes run in. Have a look at the solutions over at SuperUser.