영원히 node.js를 제어하는 스크립트를 만들었습니다.하지만 수동으로 실행할 때 원하는대로 작동합니다. 크론 작업 @reboot 아무 일도 일어나지 않는다. 나는 cron을 stderr와 stdout을 로그 파일로 리디렉션하도록 설정 했으므로 알아낼 수는 있지만 파일은 절대로 변경되지 않는다.cron 작업은 수동으로 실행될 때 작동하지만 crontab에서는 작동하지 않습니다
크론 작업 : 스크립트의 @reboot /sbin/ghost boot &> /home/mary/.ghost.log
내용 : 어떤 도움에 감사드립니다
#!/bin/bash
###########################################################
# This script is made to control Ghost using forever as #
# if it were a service running on your system. Place in #
# your path ie /usr/bin/ #
# #
# This script was created/tested on a Rasberry Pi #
# running Raspbian, however it should be *NIX independent #
# #
# This script must be run as root, sudo will not work #
# with forever #
# #
# Make sure you alter the GhostDIR variable to your #
# ghost directory, ie mine is /opt/ghost #
# #
# Created by Paul Williams #
# www.infinitepercent.com #
###########################################################
# Variables:
GhostDIR=/opt/ghost #BE SURE TO ADJUST THIS TO YOUR GHOST DIRECTORY
# Functions:
# start function will test if Ghost is running, if not it will start it with forever
start()
{
PID=$(ps -ef | grep monitor\ index.js | grep -v grep | grep -v ps | awk '{print $2}')
if [ "$PID" = "" ]; then
NODE_ENV=production forever start index.js
else
echo "Ghost is already running!"
fi
}
# stop function will test if Ghost is running, it if is it will stop it with forever
stop()
{
PID=$(ps -ef | grep monitor\ index.js | grep -v grep | grep -v ps | awk '{print $2}')
if [ "$PID" = "" ]; then
echo "Ghost isn't running!"
else
forever stop index.js
fi
}
# restart function calls stop function and then calls start function
restart()
{
stop
start
}
# WARNING, DO NOT EVER MANUALLY ENTER BOOT
# YOU MAY END UP WITH MULTIPLE INSTANCES OF GHOST
# THIS OPTION IS MEANT TO BE USED FOR A CRON @REBOOT
boot()
{
NODE_ENV=production forever start index.js
}
# status function is used to check on the status of Ghost
status()
{
forever list
}
cd $GhostDIR
if [ "$1" = "start" ]; then
start
elif [ "$1" = "stop" ]; then
stop
elif [ "$1" = "restart" ]; then
restart
elif [ "$1" = "status" ]; then
status
elif [ "$1" = "boot" ]; then
boot
else
echo "$0 {start|stop|restart|status}"
fi
!
* face palm * 글쎄 나는 절대 경로를 추가했지만 여전히 작동하지 않을 것이다. 나는 영원히 cron 작업을 사용하여 시작할 수없는 것처럼 보이기 때문에 영원히 사용하지 않고 index.js를 시작하는 다른 방법을 사용했다. 귀하의 도움에 감사드립니다! – user2994661