我在ProcessRunner.conf
Ubuntu中创建了以下/etc/init/
。
# When to start the service
start on runlevel [2345]
# When to stop the service
stop on runlevel [016]
# Automatically restart process if crashed
respawn
# Essentially lets upstart know the process will detach itself to the background
expect fork
# Run before process
pre-start script
[ -d /var/run/ProcessRunner ] || mkdir -p /var/run/ProcessRunner
java -Dlog4j.configuration=log4j_process1.xml -classpath /home/devuser/apps/ProcessExecutor:/home/devuser/apps/ProcessExecutor/ProcessExecutor-1.0.jar com.process.ApplicationStartup &
echo $! > /var/run/ProcessRunner/ProcessRunner.pid;
end script
post-stop script
processid=$(cat /var/run/ProcessRunner/ProcessRunner.pid);
if ps -p $processid > /dev/null
then
sudo kill -9 $processid;
fi;
end script
我使用以下命令从命令行启动/停止此操作:
sudo start ProcessRunner
sudo stop ProcessRunner
工作正常。现在我需要安排这些。我这样做:
我使用以下命令从命令行启动/停止此操作:
$sudo crontab -e
0 0 * * * * start ProcessRunner
0 2 * * * * stop ProcessRunner
但这不起作用。请帮忙。 另外,我不希望这个过程在系统启动时开始。我该如何配置?
答案 0 :(得分:2)
Crontab环境不提供路径,因此命令(启动ProcessRunner)必须包含完整路径。
命令的完整路径"开始"并且"停止",而不是你的新贵配置文件!
因此,基本上,您的crontab应如下所示:
0 0 * * * * /sbin/start ProcessRunner
0 2 * * * * /sbin/stop ProcessRunner