5

I am trying to run Google AppEngine on my Debian machine, I created a file init.d/gae:

. /lib/lsb/init-functions

#
# Initialize variables
#

name=gae
user=$name

pid=/var/run/$name.pid
prog="python /opt/google_appengine/dev_appserver.py --host=0.0.0.0 --admin_host=0.0.0.0 --php_executable_path=/usr/bin/php-cgi /var/www"


case "${1}" in
   start)
      echo "Starting...Google App Engine"
      start-stop-daemon --start --make-pidfile --background --oknodo --user "$user" --name "$name" --pidfile "$pid" --startas "$prog" 

      ;;

   stop)
      echo "Stopping...Google App Engine"

      ;;

   restart)
      ${0} stop
      sleep 1
      ${0} start
      ;;

   *)
      echo "Usage: ${0} {start|stop|restart}"
      exit 1
      ;;
esac

exit 0

# End scriptname

I am testing the script by manually invoking, and the script runs but not as a daemon or at least it doesn't detach from terminal. I am expecting/looking for similar functionality to Apache.

What switch am I missing?


EDIT

I should note that no PID file is being written or created despite the switch indicating it should be created

  • Does User gae have opermission to write to /var/run? – eyoung100 Sep 09 '14 at 23:39
  • You don't have a #! definition defined. I think that will cause an issue. What do you want this to run as? bash, sh, ksh? Putting a #!/bin/bash will tell the system which shell to run this as. – Warwick Sep 09 '14 at 23:40
  • 2
    The prog=python /opt/google_appengine/dev_appserver.py... line is missing quotes, causing it to get started there, not inside the start-stop-daemon code. – Mikel Sep 10 '14 at 02:41
  • It's not related to your answer : your script is not standard, add LSB header to head of your script. – PersianGulf Sep 10 '14 at 04:17
  • 1
    Where is python located and is that in the PATH when the init.d files are started. – Anthon Sep 10 '14 at 05:47
  • If you are more familiar with python why not write your init.d script in python? :) – Red Cricket Sep 10 '14 at 07:25
  • Adding the quotes seems to allow the start-stop-daemon to work as I am now getting a gae.pid file created but the process seems to terminate immediately?!? Any ideas why? – Alex.Barylski Sep 10 '14 at 14:41
  • @Anthon how do I check to see if the paths are available or correct? How would I add the Python path (what is the path even)? I've been reading all morning and this sounds likely to be the candidate to finally get this working :) – Alex.Barylski Sep 10 '14 at 15:15
  • @Alex.Barylski To check the path the script is using I would add a line echo $PATH > /var/tmp/path.tmp restart the service and see what the path is. In your case I would just do type python from the commandline and hardcode the full path in the init.d instead of just python – Anthon Sep 10 '14 at 16:16
  • /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/bin:/sbin...no mention of python...ugh why does Python invoke when I call it "python" from CLI? What path do I use? – Alex.Barylski Sep 10 '14 at 17:17
  • /usr/bin/python XYZ did not work either...ugh any other ideas? – Alex.Barylski Sep 10 '14 at 17:19

2 Answers2

5

You have two problems I can see:

prog=python /opt/google_appengine/dev_appserver.py --host=0.0.0.0 --admin_host=0.0.0.0 --php_executable_path=/usr/bin/php-cgi /var/www

Will start /opt/google_appengine/dev_appserver.py with prog=python in the environment. This is before your start block, so start-stop-daemon isn't even getting involved.

The quick fix is to quote the entire assignment like this:

prog='python /opt/google_appengine/dev_appserver.py --host=0.0.0.0 --admin_host=0.0.0.0 --php_executable_path=/usr/bin/php-cgi /var/www'

But a better fix is to use the style from /etc/init.d/skeleton, and do

DAEMON='python /opt/google/appengine/dev_appserver.py'
DAEMON_ARGS='--host=0.0.0.0 --admin_host=0.0.0.0 --php_executable_path=/usr/bin/php-cgi /var/www'

The second problem is that you're wrongly quoting $prog.

start-stop-daemon --start --make-pidfile --background --oknodo --user "$user" --name "$name" --pidfile "$pid" --startas "$prog"

tells start-stop-daemon to try to start a program called python /opt/google_appengine/dev_appserver.py --host=0.0.0.0 --admin_host=0.0.0.0 --php_executable_path=/usr/bin/php-cgi /var/www.

But clearly there is no program called that. You want to start python with arguments. Removing the double quotes there is the quick fix, but a better one, again following /etc/init.d/skeleton, would be

start-stop-daemon --start --quiet --chuid $CHUID --pidfile $PIDFILE --exec $DAEMON -- $DAEMON_ARGS

Mikel
  • 57,299
  • 15
  • 134
  • 153
  • Damn, was just about to post this :-). Your final command though is missing --background, --make-pidfile, and --oknodo. Any particular reason? – phemmer Sep 11 '14 at 02:39
  • Well, I identified the problem 23 hours ago, so figured I might as well get the points. ;) – Mikel Sep 11 '14 at 02:49
  • I was just copying the flags from the skeleton file. You're right that in this case it looks like --background and friends can be re-added. – Mikel Sep 11 '14 at 02:51
  • I did end up quoting the prog value (I edited original post) and that didn't work. If it was the double quotes causing this issue...I will carp my pants -- late though so I will test first thing tomorrow. – Alex.Barylski Sep 11 '14 at 03:12
  • DAEMON_ARGS made all the difference...jeepers crepes...thank you so much...I tried so many combinations...an entire day troubleshooting python, start-stop-daemon, etc...and the solution was a simple syntactical fix...man I can't thank you enough :) – Alex.Barylski Sep 11 '14 at 03:37
  • https://unix.stackexchange.com/a/480897/5132 /etc/init.d/skeleton has been superseded. – JdeBP Nov 10 '18 at 04:51
0

For the life of me I could not figure out why start-stop-daemon was not working...I am running Debian 7.6 wheezy and I can only assume the feature has been disabled.

I change the like to use /dev/null and the & and voila -- sciprt starts and stays running as expected...I stole the code from mysql:

$prog > /dev/null 2>&1 &

I would be very interested if someone could explain why this works and the original solution does not...in anycase I figured I would share my experience in hopes of:

  1. Saving someone else the headache of mucking around with the solution
  2. Prompting someone to step up and explain how to get this working as I originally wanted :)

EDIT | Here are the two lines of interest now

prog='/usr/bin/python /opt/google_appengine/dev_appserver.py --host=0.0.0.0 --admin_host=0.0.0.0 --php_executable_path=/usr/bin/php-cgi /var/www'

start-stop-daemon --start --make-pidfile --background --oknodo --user $user --name $name --pidfile $pid --exec $prog
  • I think it's because you removed the quotes from "$prog". Remove the >/dev/null 2>&1 & part and see what happens. – Mikel Sep 11 '14 at 02:53
  • OK I edited the answer I provided with the changes I made and now i'm getting an error (start-stop-daemon: unrecognized option '--host=0.0.0.0' – Alex.Barylski Sep 11 '14 at 03:24
  • 1
    You need the -- like in $DAEMON -- $DAEMON_ARGS. – Mikel Sep 11 '14 at 03:33