【问题标题】:SimpleHTTPServer on system boot系统启动时的 SimpleHTTPServer
【发布时间】:2018-11-08 18:02:11
【问题描述】:

我正在尝试在系统启动时启动 SimpleHTTPServer。我正在使用基于 Linux 的 Raspbian OS。为此,我在 crontab 文件中添加了以下行:

@reboot serverfile.sh

现在在 serverfile.sh 中,我放了以下内容:

#!/bin/bash
python -m SimpleHTTPServer

已赋予文件执行权限,修改后可打印echo命令。但是服务器不会在引导时启动。 同样的命令,

python -m SimpleHTTPServer

在终端中运行时工作正常。 我在这里做错了什么?

以下是我的 CRON 日志

pi@raspberrypi:~ $ grep CRON /var/log/syslog
Oct 16 07:17:01 raspberrypi CRON[17192]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Oct 16 08:17:01 raspberrypi CRON[17230]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Oct 16 09:17:01 raspberrypi CRON[17265]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Oct 16 10:17:01 raspberrypi CRON[17301]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Oct 16 10:17:03 raspberrypi cron[319]: (CRON) INFO (pidfile fd = 3)
Oct 16 10:17:03 raspberrypi cron[319]: (CRON) INFO (Running @reboot jobs)
Oct 16 10:17:03 raspberrypi cron[298]: (CRON) INFO (pidfile fd = 3)
Oct 16 10:17:03 raspberrypi cron[298]: (CRON) INFO (Running @reboot jobs)
Oct 16 11:17:01 raspberrypi CRON[1718]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Oct 16 11:51:38 raspberrypi cron[276]: (CRON) INFO (pidfile fd = 3)
Oct 16 11:51:38 raspberrypi cron[276]: (CRON) INFO (Running @reboot jobs)
Oct 16 12:17:01 raspberrypi CRON[1019]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Oct 16 13:17:02 raspberrypi CRON[1051]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Oct 16 14:17:01 raspberrypi CRON[1171]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Oct 16 15:17:01 raspberrypi CRON[1283]: (root) CMD (   cd / && run-parts --report /etc/cron.hourly)
Binary file /var/log/syslog matches

【问题讨论】:

  • 你检查过你的 cron 日志吗?
  • 没有。让我一会儿回来。
  • 使用 Python 的完整路径:which python
  • 这是python 2.7。但它确实适用于有一些其他内容的python myfile.py
  • 这篇文章可能会有所帮助:unix.stackexchange.com/questions/109804/…

标签: python shell raspbian simplehttpserver


【解决方案1】:

您可以使用init.d 脚本(适用于较旧的操作系统)或systemd(适用于较新的操作系统)之类的东西,而不是使用cron。见这里:https://unix.stackexchange.com/questions/236084/how-do-i-create-a-service-for-a-shell-script-so-i-can-start-and-stop-it-like-a-d。我不确定 Rasbian 使用什么来启动服务;也许与其中任何一个都不同。我认为重新启动脚本通常用于在启动时清理资源,而不是运行服务。

【讨论】:

  • 如果服务器在启动时启动,这就是我所需要的。让我看看你的建议
猜你喜欢
  • 2020-10-10
  • 2015-03-30
  • 1970-01-01
  • 1970-01-01
  • 2015-06-08
  • 2013-06-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多