Please check the status of this specification in Launchpad before editing it. If it is Approved, contact the Assignee or another knowledgeable person before making changes.

Summary

This long-term goal of "upstart" is to act as a replacement for _nearly_ all job control services (e.g. init, inetd, cron, anacron, at). This specification proposes how the cron/anacron replacement functionality will work.

Rationale

This will permit jobs (aka services) to be run at a specific time or date.

Use cases

Scope

This scope of this specification is limited to job definition and events.

Design

Initial version:

Cron compatibility

End version:

Implementation

Code

events.h

Added:

   1 /**
   2  * TIME_EVENT:
   3  *
   4  * Name of the event we generate every minute, which includes arguments and
   5  * environment indictating when the event was generated.
   6  **/
   7 #define TIME_EVENT "time"
   8 

main.c main()

Modified:

   1         /* Process the event queue each time through the main loop */
   2         NIH_MUST (nih_main_loop_add_func (NULL, (NihMainLoopCb)event_poll,
   3                                           NULL));
   4 
   5 +       /* Initialize the timers */
   6 +       nih_timer_init();
   7 
   8         /* Read configuration */
   9         NIH_MUST (conf_source_new (NULL, CONFFILE, CONF_FILE));
  10         NIH_MUST (conf_source_new (NULL, CONFDIR, CONF_JOB_DIR));
  11 

   1 m       /* Generate and run the startup and time event or read the state from the
   2          * init daemon that exec'd us
   3          */
   4         if (! restart) {
   5                 NIH_MUST (event_new (NULL, STARTUP_EVENT, NULL));
   6 +               timer_handler(NULL,NULL);
   7         } else {
   8                 sigset_t mask;
   9 
  10                 /* We're ok to receive signals again */
  11                 sigemptyset (&mask);
  12                 sigprocmask (SIG_SETMASK, &mask, NULL);
  13         }
  14 

Added:

   1 /**
   2  * timer_handler:
   3  * @data: an integer which specifies the timer phase: initial, next minute, every minute,
   4  * @timer: timer that called this handler.
   5  *
   6  * Handle having recieved the minute-wise timer event, which we use to
   7  * generate a TIME event.
   8  **/
   9 static void
  10 timer_handler (void     *data,
  11                NihTimer *timer)
  12 {
  13         nih_local char **env = NULL;
  14         size_t           len;
  15         time_t           rawtime;
  16         struct tm       *timeinfo;
  17 
  18         /* Get the current time and splice it */
  19         time ( &rawtime );
  20         timeinfo = localtime ( &rawtime );
  21 
  22         len = 0;
  23         env = NIH_MUST (nih_str_array_new (NULL));
  24 
  25         /* Add the fields in the correct order: TIME DOW DATE */
  26         NIH_MUST (environ_set (&env, NULL, &len, TRUE,
  27                                "TIME=%.2d:%.2d", timeinfo->tm_hour,timeinfo->tm_min));
  28         NIH_MUST (environ_set (&env, NULL, &len, TRUE,
  29                                "DAY_OF_WEEK=%.1d", timeinfo->tm_wday+1));
  30         NIH_MUST (environ_set (&env, NULL, &len, TRUE,
  31                                "DATE=%.2d/%.2d/%.4d", timeinfo->tm_mon+1,timeinfo->tm_mday,timeinfo->tm_year+1900));
  32 
  33         NIH_MUST (event_new (NULL, TIME_EVENT, env));
  34 
  35         /* Check the run cycle */
  36         if(data == (void*)0)
  37         {
  38         /* Start at next minute a new time event */
  39         NihTimer *timer = nih_timer_add_timeout(NULL, 61 - (rawtime % 60), timer_handler,
  40                                (void*)1);
  41         }
  42         if(data == (void*)1)
  43         {
  44         /* Every minute a new time event */
  45         NihTimer *timer = nih_timer_add_periodic(NULL, 60, timer_handler,
  46                                (void*)2);
  47         }
  48         /* if(data == (void*)2) Do nothing */
  49 }
  50 

Data preservation and migration

These changes are backwards compatible with the previous behaviour

Unresolved issues


ReplaceCron (last edited 2011-08-26 04:10:17 by localhost)