APICe: Servizi e Progetti » ESXi 5 Job Scheduling

Job scheduling under ESXi 5

It’s necessary, in order to schedule a job, to modify manually root’s crontab and make changes durable after a reboot auto-generating the change on the crontab.

Every time the cron job change, update /etc/rc.local as well and run the "auto-backup.sh" command to backup the new /etc/rc.local file.

  1. change cron job 
  2. update /etc/rc.local
  3. run auto-backup.sh

1- To modify root’s crontab file:
ESXi 5.0 does not allow any direct cron changes, it’s shell is a minimal shell designed to run "esxcli" commands and the utility "busybox" that allows to access to many useful UNIX commands does not include the "crontab" command.

  • Edit the /var/spool/cron/crontabs/root file adding the scheduled job as the normal crontab sintax suggest.
  • Run the command ps | grep crond or cat /var/run/crond.pid to identify cron daemon’s PID.
  • Run the command kill <pid> using crond’s PID to kill the process.
  • Run the command crond or busybox crond to load again the cron daemon, causing to install automatically the new crontab.

2- To make changes durable after a reboot:

   It’s necessary to make this changes just once for each crontab new entry, they cause the system to automatically make root crontab’s changes when the system starts up.

If you’re running ESXi 5.1 then edit /etc/rc.local.d/local.sh file with vi or nano adding at the end of the file the following 3 lines:
/bin/kill $(cat /var/run/crond.pid)
/bin/echo YOUR CRONTAB JOB LINE HERE >> /var/spool/cron/crontabs/root
crond

If you’re running ESXi 5.1

  • Edit /etc/rc.local file with vi or nano adding at the end of the file the following 3 lines:
    /bin/kill $(cat /var/run/crond.pid)
    /bin/echo YOUR CRONTAB JOB LINE HERE >> /var/spool/cron/crontabs/root
    /bin/busybox crond

    My SERVER:
    ~ # diff -r /ghettoVCB /vmfs/volumes/datastoreAcer/ghettoVCB/

    cat /etc/rc.local.d/local.sh
    #!/bin/sh
    # local configuration options
    # ghettoVCB backup sheduling via crontab
    sh /vmfs/volumes/datastoreAcer/ghettoVCB/restoreGhettoService.sh
    exit 0

    cat /vmfs/volumes/datastoreAcer/ghettoVCB/restoreGhettoService.sh
    #!bin/sh
    /bin/cp -r /vmfs/volumes/datastoreAcer/ghettoVCB /
    chmod ug+x /ghettoVCB/automaticGhetto22.sh
    /bin/kill $(cat var/run/crond.pid)
    /bin/echo '0   3   *   *   *   /ghettoVCB/automaticGhetto22.sh' >> /var/spool/cron/crontabs/root
    crond

In simple words after the system startup, restoreGhettoService.sh

  • copies script folder from datastore to root dir, 
  • ensure execution rights for script
  • automatically kills crond, 
  • adds the line to /var/spool/cron/crontabs/root 
  • then restarts crond to install the new crontab. 

RESOURCES
http://www.jules.fm/Logbook/files/add_cron_job_vmware.html

cat /var/spool/cron/crontabs/root
#min hour day mon dow command
1    1    *   *   *   /sbin/tmpwatch.py
1    *    *   *   *   /sbin/auto-backup.sh
0    *    *   *   *   /usr/lib/vmware/vmksummary/log-heartbeat.py
*/5  *    *   *   *   /sbin/hostd-probe
0   3   *   *   *   /ghettoVCB/automaticGhetto22.sh

Contact Info

Address:
APICe Laboratory
Via Venezia, 52
47023, Cesena (FC)
Italy

Phone:
+39 0547 339 205
Fax:
+39 0547 339 208

Email:
Send Mail