2

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

我想通过 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

服务器正常启动。

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

4

1 回答 1

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()函数中运行它。

于 2013-01-18T18:12:14.943 回答