Crond

From WebOS Internals
Revision as of 22:13, 3 February 2010 by Xorg (talk | contribs)
Jump to navigation Jump to search

Enabling Stock Cron

The Patch webOS GPS Tracking guide had a nice bit about enabling crond on the Pre. It looks like its already pre-installed, just not set up to start. You will need to edit /etc/event.d/mod-crond (don't modify the existing crond startup-script) to enable cron to start. The settings should look like this:

# -*- mode: conf; -*-

# jobfile for busybox crond, with pre-start commands to create the
# directory and files it wants by default.  That there's not 'start
# on' stanza is intentional: it's for development use only.  We can
# turn it on later if we need it, e.g. to keep the clock synced.  It
# does work.

start on stopped configure
stop on started start_update

# If the above do not work with WebOS above 1.3, try these...
# The above doesn't start service since webos 1.3
# start on stopped finish
# stop on runlevel [!2]

respawn

exec /usr/sbin/crond -f -L /var/log/crond

pre-start script
    mkdir -p /var/spool/cron/crontabs
    ln -sf /etc/cron/crontabs/root /var/spool/cron/crontabs/root
end script

A few notes here. Unlike the Dropbear and other scripts I make my upstart scripts so that essential services don't stop when the device exists runlevel 2. This seems to shutdown these services whenever the device locks. I prefer that my upstart services stop only when the updater runs. Also I have made cron log to a separate file under /var/log so that it can be monitored better.

One thing to note about the standard script for cron on the Pre is that the /var/spool/cron/crontabs directory is created every time the process runs and a symlink to /etc/cron/crontabs/root is created. To my surprise this file does not exist. So we need to create it:

sudo mkdir -p /etc/cron/crontabs
sudo sh -c 'echo > /etc/cron/crontabs/root'

Now to start up crond:

sudo -i initctl start crond
  • Note for clarification: I attempted this and it all works OK, but I can't figure out how to actually schedule jobs. I modified /etc/cron/crontabs/root, but nothing seems to happen. I also tried crontab -e, and that doesn't seem to do anything either. I suggest adding a note here clarifying what needs to be done to actually add a cron job. -irwinr
  • Clarification: Edit /etc/cron/crontabs/root with test content something like this:
# format:
# minute(0-59) hour(0-23) day(1-31) month(1-12) weekday(0-6) command
* * * * * echo "CronTest -" `date` >> /var/crondtest

Then restart crond like this:

sudo -i initctl stop crond
sudo -i initctl start crond

This test will result in a test file at /var/crondtest that grows at the rate of one line per minute. You can count the lines and output the end of the file with the following commands. Also try a reboot to make sure everything is starting up properly. If everything is working make sure to remove or comment out the CronTest task and restart crond.

grep -c "" /var/crondtest
tail /var/crondtest

Alternative (ipkg-opt) Method

  • Another request for clarification: It's not clear which of these two methods are preferred. This method appears to not work when the screen is off (rendering cron pretty useless), the above method appears to delete the cron entries every time the cron daemon starts. Has anyone worked out either of these issues? -irwinr.

crond is a system that allows command to be run at specified intervals.

Do not use the built in crontab -e as it is overwritten on each boot.

Optware has cron available as an installable package, and using /opt/etc/cron.d/ for cron files will not conflict with any Palm files.

sudo -i 
mount -o remount,rw /
ipkg-opt update
ipkg-opt install cron
/opt/bin/crontab -e
# Add script and intervals here
mount -o remount,ro /

This does not seem to work when the phone's screen turns off. I tried it plugged in for two minutes then unplugged, and turned the screen off for two minutes. I ran

echo `date` >> sleep.log

And got...

# cat sleep.log 
Wed Jul 1 18:27:01 CDT 2009
Wed Jul 1 18:28:01 CDT 2009
Wed Jul 1 18:30:16 CDT 2009  ## Turned the screen back on. It seems to play catch up.
Wed Jul 1 18:30:16 CDT 2009