好吧,我到处搜索,找到了我的拼图,但没有解决方案。
我想通过 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
服务器正常启动。
那么,我做错了什么? 谢谢!
请您参考如下方法:
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() 函数中运行它。
