【发布时间】:2020-01-01 06:08:48
【问题描述】:
在系统重启时init 6 我想为我的 rails 项目启动服务,脚本包含从 git 拉取更改,运行 bundle install 并运行延迟的工作人员
脚本在/etc/init.d/app-startup-script
#!/bin/sh
cd /home/deploy/source/myapp
git pull origin development
bundle install
bundle exec cap staging deploy
touch /home/deploy/hello.txt (added this to test if it will create file on reboot)
我在重启时在crontab -e 中运行这个脚本
@reboot /etc/init.d/app-startup-script
我通过手动运行确认 app-startup-script 正在运行
/etc/init.d/app-startup-script
但是当我使用
重新启动系统时sudo su -
init 6
然后再次 ssh 到我的服务器,它只会在 /home/deploy 中创建 hello.txt 文件,但没有启动我的 rails 服务
【问题讨论】:
-
/etc/init.d用于init启动脚本;你想为这个找到一个更好的地方。也许/usr/local/bin/app-startup-script -
这可能会意外修复脚本,使其仅在网络启动且稳定等情况下运行。
-
@tripleee 我将脚本从 /etc/init.d 移动到 /usr/local/bin/ 它创建 hello.txt 文件但不运行 rails 服务
-
运行它并将错误输出到一个文件,这样你就可以看到出了什么问题。我猜它会在您的系统日志中产生错误,但确切的位置取决于平台。
@reboot /usr/local/bin/app-startup-script >>/home/you/app-startup.log 2>&1应该让它们在你的主目录中可见(显然调整路径)。 -
在你的 shell 脚本顶部添加一个
set -e。这会导致它因错误而中止。另外,检查现有的输出。