【问题标题】:python script to share directory, added to startup via update-rd.c, hangs boot共享目录的python脚本,通过update-rd.c添加到启动,挂起启动
【发布时间】:2013-01-03 20:36:41
【问题描述】:

好的,我从高处和低处搜索,找到了我的难题,但没有解决方案。

我想通过 http 共享一个目录,而不必担心 apache 等。python 是最简单的答案。所以我把简单的脚本放在一起(称为 tftp-www.py):

#!/usr/bin/env python
import SimpleHTTPServer
import SocketServer
import os
os.chdir("/var/lib/tftproot")
PORT = 8000
Handler = SimpleHTTPServer.SimpleHTTPRequestHandler
httpd = SocketServer.TCPServer(("", PORT), Handler)
print "Server running on port ", PORT
httpd.serve_forever()

chmod 到 755,运行它,无论我从哪里运行它,它都能完美运行。 现在我希望它在启动时运行,在任何人登录之前,所以这个目录将始终被共享。 因此,我将文件复制到 /etc/init.d 并按照有关如何将脚本添加到启动的说明运行以下操作:

update-rc.d -f tftp-www.py start 99 2 3 4 5 .

此时我重新启动进行测试,服务器(Ubuntu 10.10)在启动过程中挂起。一旦我进入恢复模式并删除了脚本

update-rc.d -f tftp-www.py remove

服务器正常启动。

那么,我做错了什么? 谢谢!

【问题讨论】:

    标签: python simplehttpserver


    【解决方案1】:

    Debian/ubuntu 风格的 update-rc.d 和启动脚本是为 shell 脚本设计的,需要元数据部分:

    #! /bin/sh
    ### BEGIN INIT INFO
    # Provides:          rc.local
    # Required-Start:    $remote_fs
    # Required-Stop:
    # Default-Start:     2 3 4 5
    # Default-Stop:
    # Short-Description: Run /etc/rc.local if it exist
    ### END INIT INFO
    

    查看 /etc/init.d/skeleton(至少存在于 Debian 上,不确定 Ubuntu)。为您的程序创建 shell 启动脚本,然后在 do_start() 函数中运行它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-05
      • 2013-01-11
      • 1970-01-01
      相关资源
      最近更新 更多