Uploaded image for project: 'CFEngine Community'
  1. CFEngine Community
  2. CFE-88

Please add feature to start cf-execd from init, upstart or systemd with respawn option

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Done
    • Priority: Medium
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 3.4.0
    • Component/s: cf-execd
    • Labels:
      None

      Description

      Please add feature to start cf-execd from init, upstart or systemd with respawn option to make sure that cf-execd is always running.

      Example for init
      <pre>
      ce:2345:respawn:/var/cfengine/bin/cf-execd --no-fork
      </pre>

      For respawn to work correctly, processes should not fork themselves. The respawn attribute is associated with the parent process that is started, not the forked child processes.

      Just looked at the source code of cfengine-3.3.5\src\cf-execd.c

      When starting cf-execd with --nofork or -F option ONCE flag is set to true
      <pre>
      case 'F':
      ONCE = true;
      NO_FORK = true;
      break;
      </pre>

      So, cf-execd does not start an infinite loop and exit after every execution.
      <pre>
      if (ONCE)

      { CfOut(cf_verbose, "", "Sleeping for splaytime %d seconds\n\n", SPLAYTIME); sleep(SPLAYTIME); LocalExec(&config); CloseLog(); }

      else
      {
      while (true)
      {
      if (ScheduleRun())
      {
      CfOut(cf_verbose, "", "Sleeping for splaytime %d seconds\n\n", SPLAYTIME);
      sleep(SPLAYTIME);

      #if defined(HAVE_PTHREAD)
      if (!LocalExecInThread(&config))

      { CfOut(cf_inform, "", "Unable to run agent in thread, falling back to blocking execution"); #endif LocalExec(&config); #if defined(HAVE_PTHREAD) }

      #endif
      }
      }
      }
      <pre>

      Of course init restarts the process but it is disrupts the normal cycle of the program. Therefore at the moment it is not possible to use respawn.

      Seems like it is possible to make small changes to cf-execd.c to support running from respawn. For example, separate option --once or -O.

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            aleksey.chudov@gmail.com Aleksey Chudov (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: