3

Normally I do this:

cd /home/ubuntu/project/beta
python default.py -dev

In order to start the web.py server

I would prefer to do this:

sudo start beta

Here is my /etc/init/beta.conf

setuid alex
setgid alex
script
  export HOME=/home/ubuntu/project
  cd $HOME/beta
  python default.py -dev
end script

When I do sudo start beta it starts, but doing sudo status beta a few seconds later shows that it is stopped. tail /var/log/syslog shows kernel: [58023.somenumbers] init: beta main process (5460) terminated with status 134

Now if I do python default.py -dev and then echo $? it shows 0 - so I don't understand why the above exit code is occurring. The beta folder and contents are owned by alex:alex

Any help is appreciated!

Alex Waters
  • 177
  • 10
  • May be this link will help you : (http://askubuntu.com/questions/175751/how-do-i-run-a-python-script-in-the-background-and-restart-it-after-a-crash) – Suku Jan 03 '13 at 02:24

2 Answers2

1

The *.conf scripts aren't shell scripts, so an interpreter directive of #!/bin/sh is ONLY a nonfunctional comment in that context.

Be sure there isn't a system job with the same name, "beta". I'm assuming the .conf is in

/home/alex/.init/beta.conf

User jobs really shouldn't need the setuid/setgid part, unless you need to switch the GID to one which isn't the primary GID for the user (but is in the list as seen in output from id(1)).

The suggested "cd /home/alex/" should, according to the docs, be "chdir /home/alex", also omitting the superfluous trailing slash. It might help, but the script section will probably be enough, although seeing output would be nice - perhaps focusing on capturing the output from the (real) cd and the script might help, with:

script
  export HOME=/home/ubuntu/project
  {
     cd $HOME/beta
     python default.py -dev
  } > $HOME/beta/log 2>&1
end script

Many problems related to system-managed starts of jobs like this show up in output from either id(1) or env(1), so you might add this line right before the python line:

id ; env | sort

Users' personal accounts often have modified PATH variable, extra customization scripts and dotfiles they forget about, and so on, or rely upon environment settings from .bashrc and the like which only happen during fully interactive logins (.bashrc vs .bash_login and kin, and so forth).

Note the if your system has a truly retro /bin/sh (unlikely), the export line would have to be written as:

HOME=/home/ubuntu/project ; export HOME

:-)

Alex North-Keys
  • 541
  • 4
  • 6
0

2 potential issues

  1. The script doesn't have a shell line
  2. Directory is not changed when starting script. So it is possible script is trying to write to some place need root permission.

Try following

#!/bin/sh
setuid alex
setgid alex

#CD to alex home directory first so script can write output
cd /home/alex/

script
  export HOME=/home/ubuntu/project
  cd $HOME/beta
  python default.py -dev
end script
John Siu
  • 3,667
  • 2
  • 17
  • 23