![在 Ubuntu 12.04 x64 服务器启动时运行脚本](https://linux22.com/image/837779/%E5%9C%A8%20Ubuntu%2012.04%20x64%20%E6%9C%8D%E5%8A%A1%E5%99%A8%E5%90%AF%E5%8A%A8%E6%97%B6%E8%BF%90%E8%A1%8C%E8%84%9A%E6%9C%AC.png)
我正在尝试启动名为 fedena 的 RoR 应用程序。
我通常的做法是 SSH 登录root
并输入以下命令
root@cloud:~# cd fedena
root@cloud:~/fedena# script/server
=> Booting WEBrick
=> Rails 2.3.5 application starting on http://0.0.0.0:7800
and so on...meaning the app server is running
然后,当我关闭 SSH 会话时,应用程序就结束。
现在,我想到让它保持活动状态的方法是运行这个 shell 脚本网页管理工具界面,它幸存了下来。但是,我想在每次启动/重启时自动运行此脚本。我尝试添加
./fedena/script/server
在exit 0
/etc/rc.local
唉!没用。我不明白为什么。
答案1
假设你的脚本是 bash 并且路径是/root/fedina/server/script
你可以拥有:
##!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
bash /root/fedina/server/script
exit 0
笔记:不要忘记执行位(例如chmod a+x /etc/rc.local
)