[英]rc.local script runs manually but fails on startup…what gives?
我可以手動運行我的 /etc/rc.local 文件,它在啟動時運行(將字符串回顯到文件),但是永遠(npm 包)由於某種原因失敗了。 如果有幫助,我正在 EC2 實例上運行 Amazon Linux AMI。
我在哪里可以了解為什么它失敗了,或者你能告訴我我做錯了什么嗎?
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
echo "rc.local is running..." > /tmp/rc.local-output
touch /var/lock/subsys/local
exec /usr/local/bin/forever start -c /usr/local/bin/node /var/www/node/myapp/app.js &
exec /usr/local/bin/forever start -c /usr/local/bin/node /var/www/node/myapp/tools/push/push_service.js &
好的,事情似乎變得更好了,我將 rc.local 文件更新為:
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.
exec 2> /tmp/rc.local.log # send stderr from rc.local to a log file
exec 1>&2 # send stdout to the same log file
set -x # tell sh to display commands before execution
echo "rc.local is running..." >> /tmp/rc.local-output
touch /var/lock/subsys/local
/usr/local/bin/forever start /var/www/node/myapp/app.js &
/usr/local/bin/forever start /var/www/node/myapp/tools/push/push_service.js &
/tmp/rc.local.log 告訴我這個:
/usr/bin/env: node: 沒有那個文件或目錄
我想你仍然設置了執行位?
ls -l /etc/rc.local
-rwxr-xr-x 1 root root 306 Dec 26 2010 /etc/rc.local
此外,腳本或工具/usr/local/bin/forever
也必須是可執行的('x' 位設置適當),但您在手動測試時會檢測到。
我可以想象這在啟動時不起作用的唯一原因是它需要的東西到那時還沒有准備好,因此永遠工具的啟動失敗。 永遠是劇本嗎? 如果是這樣,也許你可以告訴我們里面有什么?
你可以通過在 /etc/rc.local su -c '/usr/local/node/bin/pm2 start /root/blog/hexo-start.sh' --login root 中設置來解決這個問題
因為 'use --login' 可以找到節點環境。 --login 表示Provide an environment similar to what the user would expect had the user logged in directly
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.