Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have set up cron jobs which stop services at 2:00 AM and then restarts them at 8:00 AM. However, my enterprising users (my family; securing the box isn't a possibility) have determined that if they reboot the box, the services come back online as part of the default boot process.

The best solution I was able to come up with was to modify the start/stop scripts to examine the time as a condition, or to have the cron jobs place a flag file on disk that the services start jobs look for prior to allowing startup. (The second decouples the schedule so I'm only entering it in one place and allows me to easily override it.)

Is this the best technical way to approach the problem? Is there another way to link the shutdown via cron that I'm unfamiliar with?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

OK, the service I wanted to control has been converted to Upstart. Per the Upstart Cookbook, temporarily disabling a service so that it doesn't start on the next boot is done via the following:

# echo "manual" >> /etc/init/myjob.override

So I created the following start up and shutdown script to be called from cron:

PMSStop:

#!/bin/bash
OverrideFile="/etc/init/plexmediaserver.override"

# Create the override file if it doesn't already exist.
if [ ! -f $OverrideFile ]
then
    echo Creating flag file $OverrideFile.
    echo "manual" >> $OverrideFile
else
    echo Flag file $OverrideFile exists.
fi

# Stop the plexmediaserver service.
/sbin/stop plexmediaserver

PMSStart:

#!/bin/bash
OverrideFile="/etc/init/plexmediaserver.override"

# Remove the override file if exists.
if [ -f $OverrideFile ]
then
    rm $OverrideFile
fi

# Start the plexmediaserver service.
/sbin/start plexmediaserver

I then modified the cron jobs to use the newly created batch files and it appears to be working.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.