upstart starts python script but it behaves unexpectedly

134 views Asked by At

The program works when started by cron or from the shell. But when started by upstart, it seems to loop indefinitely.

The scripts and the files they use are in the /home/user/ directory, and are owned by user, and all have 777 permissions.

The upstart .conf file:

start on runlevel [2345]
stop on runlevel [!2345]

kill signal SIGHUP
# reload signal SIGHUP
respawn

exec python /home/user/Documents/init.py -b 600
1

There are 1 answers

0
user193661 On BEST ANSWER

upstart executes commands as root by default. But the user can be specified: https://askubuntu.com/questions/87671/how-do-i-start-jobs-as-a-non-privileged-user-in-upstart.

But the script was programmed with user specific variables and a dependency to a specific directory.

init.py had this line:

self.d_root = os.path.join(os.path.expanduser('~'),'Documents','records')

I changed it to this and it worked:

self.d_root = os.path.dirname(os.path.realpath(__file__))

But I think the proper fix is to add this line to the .conf file:

setuid username