Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/338.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何为python CGIHTTPServer创建linux服务?_Python_Linux_Shell_Service_Webserver - Fatal编程技术网

如何为python CGIHTTPServer创建linux服务?

如何为python CGIHTTPServer创建linux服务?,python,linux,shell,service,webserver,Python,Linux,Shell,Service,Webserver,我使用(server.py)运行python CGIHTTPServer 我尝试使用 #!/bin/sh case $1 in start) ./server.py ;; stop) # code to stop the service esac 问题1:当我启动服务时,它将在终端中运行;不返回到下一个bash命令行。因此,在关闭终端时,服务将停止。即使在关闭终端后,如何保持web服务器处于活动状态 问题2:如何停止此服务?(在通过问题1保持开启状态后)使用。这比滚动您自己的服务管理代码容

我使用(server.py)运行python CGIHTTPServer

我尝试使用

#!/bin/sh

case $1 in
start) 
./server.py
;;
stop) # code to stop the service
esac
问题1:当我启动服务时,它将在终端中运行;不返回到下一个bash命令行。因此,在关闭终端时,服务将停止。即使在关闭终端后,如何保持web服务器处于活动状态

问题2:如何停止此服务?(在通过问题1保持开启状态后)

使用。这比滚动您自己的服务管理代码容易得多。它包括监视、控制、有限重启、状态日志记录、自定义事件通知和用于以编程方式控制监控器的XML-RPC API


它还可以通过一次配置更改启动web服务器的多个实例(如果适合您的体系结构的话),甚至可以管理共享一个套接字的多个FastCGI实例。

在后台使用以下命令启动程序:

nohup./server.py&

停止服务的首选方法是使用服务的PID作为参数发出kill命令

#!/bin/sh
case $1 in
start) 
nohup ./server.py &
echo $! > ./server.pid
;;
stop) # code to stop the service
kill `cat ./server.pid`
esac
附言。
注释中使用的启动-停止守护程序更好,但稍微更复杂。

在superuser.com上可能会更好,但作为起点,请查找nohup、启动-停止守护程序和bash
&
操作符。
#!/bin/sh
case $1 in
start) 
nohup ./server.py &
echo $! > ./server.pid
;;
stop) # code to stop the service
kill `cat ./server.pid`
esac