Learn More
Learn More

Reputation: 1561

Scheduling an UpStart init script via crontab

I have created following ProcessRunner.conf in /etc/init/ Ubuntu.

# 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

I use following commands to start / stop this from command line:

sudo start ProcessRunner
sudo stop ProcessRunner

It works fine. Now I need to schedule these. I doing following to do so:

I use following commands to start / stop this from command line:

$sudo crontab -e

0 0 * * * * start ProcessRunner
0 2 * * * * stop ProcessRunner

But this is not working. Please help. Also, I do not want this process to get started on system start up. How can I configure that ?

Upvotes: 0

Views: 278

Answers (1)

RodneyZ
RodneyZ

Reputation: 94

Crontab environment doesn't provide path, so commands (start ProcessRunner) must include full path.

Full path to commands "start" and "stop", not to your upstart config file!

So, essentially, your crontab shall look like:

0 0 * * * * /sbin/start ProcessRunner
0 2 * * * * /sbin/stop ProcessRunner

Upvotes: 2

Related Questions