[英]How do I run GAE as a background-service
I found a init.d script template -- filled in the blanks and tried to invoke GAE using something like: 我找到了一个init.d脚本模板-填补了空白,并尝试使用以下方法调用GAE:
start-stop-daemon -S --background 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
This doesn't work...but if I run from the command line works fine but hangs the input... 这是行不通的...但是如果我从命令行运行可以正常运行,但是会挂起输入...
How do I invoke this command at startup using init.d and change to the user "gae" -- similar to Apache runs as www-data 如何在启动时使用init.d调用此命令并更改为用户“ gae”-类似于Apache作为www-data运行
I also (briefly) tried to use start-stop-daemon
to control Google App Engine (without any luck), so I ended up using /etc/rc.local
to launch the daemon. 我还(简短地)尝试使用start-stop-daemon
来控制Google App Engine(没有任何运气),因此我最终使用/etc/rc.local
启动了该守护程序。
Add the following to /etc/rc.local
(before any exit
command): 将以下内容添加到/etc/rc.local
(在任何exit
命令之前):
sudo -i -u gae python /opt/google_appengine/dev_appserver.py --host=0.0.0.0 \
--storage_path /var/cache/appengine/gae \
--admin_host=0.0.0.0 --php_executable_path=/usr/bin/php-cgi /var/www > /dev/null 2> /dev/null &
Note , I included a storage_path in the launch options. 注意 ,我在启动选项中包含了一个storage_path。 Make sure you do the following: 确保执行以下操作:
sudo mkdir -p /var/cache/appengine/gae
sudo chown gae: /var/cache/appengine/gae
To restart the process (after an update), I just kill python and manually execute rc.local: 要重启进程(更新后),我只是杀死python并手动执行rc.local:
sudo killall -9 python
sudo /etc/rc.local
I have finally figured out how and why the start-stop-daemon was not working...it all boiled down to some simple syntactical errors and a (still?) misunderstanding on my behalf: 我终于弄清楚了start-stop-daemon的工作方式和原因,以及为什么它们不起作用...所有这些都归结为一些简单的语法错误以及代表我的(还是?)误解:
https://unix.stackexchange.com/questions/154692/start-stop-daemon-wont-start-my-python-script-as-service https://unix.stackexchange.com/questions/154692/start-stop-daemon-wont-start-my-python-script-as-service
In brief, when I use this init.d script and register it accordingly, GAE starts and stops accordingly: 简而言之,当我使用此init.d脚本并进行相应注册时,GAE相应地启动和停止:
#!/bin/sh
### BEGIN INIT INFO
# Provides: Google App Engine daemon management
# Required-Start:
# Required-Stop:
# Default-Start:
# Default-Stop:
# Short-Description: Google App Engine initscript
# Description: Start/stop appengine web server
### END INIT INFO
# Author: Alex Barylski <alex.barylski@gmail.com>
. /lib/lsb/init-functions
#
# Initialize variables
#
name=appengine
desc="Google App Engine"
bind=0.0.0.0
docroot=/var/www
phpexec=/usr/bin/php-cgi
pidfile=/var/run/$name.pid
args="--host=$bind --admin_host=$bind --php_executable_path=$phpexec"
prog='/usr/bin/python /opt/google_appengine/dev_appserver.py'
#
# TODO: Figure out how to switch user (ie: --chuid www-data)
#
case "${1}" in
start)
echo "Starting...$desc"
start-stop-daemon --start --make-pidfile --background --oknodo \
--pidfile $pidfile \
--name $name \
--exec $prog \
-- $args $docroot
;;
stop)
echo "Stopping...$desc"
start-stop-daemon --stop --quiet --oknodo --retry=0/30/KILL/5 --exec $prog
;;
restart)
${0} stop
sleep 1
${0} start
;;
*)
echo "Usage: ${0} {start|stop|restart}"
exit 1
;;
esac
exit 0
I cannot figure out how to start the service as www-data and I am sure I could make this script more robust but for development purposes it is sufficient and runs as a daemon. 我无法弄清楚如何以www-data的形式启动服务,并且我确定可以使此脚本更健壮,但出于开发目的,它已足够并可以作为守护程序运行。
Hope this helps someone in the future, Alex 希望这对以后的人有所帮助,Alex
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.