Catch 22 with processes and files

14 views
Skip to first unread message

Bob

unread,
Jun 22, 2015, 10:52:02 AM6/22/15
to help-c...@googlegroups.com
I have a dilemman and need some suggestions. I have a process where I need to send a signal when the configuration file is updated. However, I also have a process (xrdp) where I do not want to update the configuration file if a process is running (Xvnc) so I can restart without interrupting user sessions. So, I think I need:

processes:

files:

processes:

but this is not possible.

Is there a way I can save state between cf-agent runs so the xrdp processes can be restarted at a later time?

Neil Watson

unread,
Jun 22, 2015, 11:04:34 AM6/22/15
to help-c...@googlegroups.com
There are the three passes, so it may be possible, but we need more of
your requirements.

--
Neil H Watson
Sr. Partner, Architecture and Infrastructure
CFEngine reporting: https://github.com/evolvethinking/delta_reporting
CFEngine policy: https://github.com/evolvethinking/evolve_cfengine_freelib
CFEngine and vim: https://github.com/neilhwatson/vim_cf3
CFEngine support: http://evolvethinking.com

Brian Bennett

unread,
Jun 22, 2015, 11:34:41 AM6/22/15
to Bob, help-c...@googlegroups.com
I would drop a marker into /tmp then restart if the marker exists and Xvnc is not running.

E.g.:

classes:
  "restart_xrdp_needed" expression => fileexists("/tmp/xrdp_needs_restart");

files:
  "/my/xrdp.config"
    copy_from => secure_cp("/repo/path/xrdp.config","$(sys.policy_hub)"),
    classes => if_repaired("restart_xrdp_needed");

  restart_xrdp_needed::
    "/tmp/xrdp_needs_restart" create => "true";

processes:
  "Xvnc" process_stop => "/usr/bin/false",
    classes => if_notkept("xvnc_is_running");

  !xvnc_is_running.restart_xrdp_needed::
    "xrdp" signals => { "hup" };

I haven't tested running this, so it may not be quite right.

-- 
Brian Bennett
Looking for CFEngine training?
http://www.verticalsysadmin.com/

--
You received this message because you are subscribed to the Google Groups "help-cfengine" group.
To unsubscribe from this group and stop receiving emails from it, send an email to help-cfengin...@googlegroups.com.
To post to this group, send email to help-c...@googlegroups.com.
Visit this group at http://groups.google.com/group/help-cfengine.
For more options, visit https://groups.google.com/d/optout.

Neil Watson

unread,
Jun 22, 2015, 11:36:48 AM6/22/15
to help-c...@googlegroups.com
You can persist classes between runs. It's neater than a semaphore file.
https://docs.cfengine.com/latest/reference-promise-types-classes.html#persistence

Brian Bennett

unread,
Jun 22, 2015, 12:02:10 PM6/22/15
to Neil Watson, help-c...@googlegroups.com
A persistent class is still a semaphore, just a different kind. The persistence time needs to be long enough to guarantee there will be an interval period where restart is safe, and the class needs to be cancelled/negated after the restart happens.

--
Brian Bennett
Looking for CFEngine training?
http://www.verticalsysadmin.com/

Neil Watson

unread,
Jun 22, 2015, 12:10:14 PM6/22/15
to help-c...@googlegroups.com
On Mon, Jun 22, 2015 at 09:02:06AM -0700, Brian Bennett wrote:
>A persistent class is still a semaphore, just a different kind.

I said it was neater than a 'semaphore file'. But, yes logically they
are the same. I'm getting out of the pedantic end of the pool now :)
Reply all
Reply to author
Forward
0 new messages