Delete all files when change

21 views
Skip to first unread message

bofh...@gmail.com

unread,
Dec 20, 2016, 7:03:53 PM12/20/16
to help-cfengine
I hope I can explain clearly what I am looking to accomplish.

I am trying to generate Xvnc setups into /etc/xinetd.d using templates.  I am creating an slist with the specifics on how the files are generated.  I already know how to complete this part of the promise.   But we change these Xvnc setups often to move/remove users.  What I want to do is when I update the slist is delete all files /etc/xinetd.d/Xvnc.* and regenerate them from the slist/template.  Best I have been able to do is completely delete and rebuild on each run.  I really only want to delete/rebuild when the slist changes.

Thank you in advance,
Robin Friedrich

Aleksey Tsalolikhin

unread,
Dec 20, 2016, 8:54:35 PM12/20/16
to bofh...@gmail.com, help-cfengine
Hi Robin,

Does each user have its own /etc/xinetd.d/Xvnc.* file?

Best,
-at


-- 
Need training on CFEngine, Git or Time Management?  Email trai...@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-cfengine+unsubscribe@googlegroups.com.
To post to this group, send email to help-c...@googlegroups.com.
Visit this group at https://groups.google.com/group/help-cfengine.
For more options, visit https://groups.google.com/d/optout.

Nick Anderson

unread,
Dec 20, 2016, 11:02:39 PM12/20/16
to bofh...@gmail.com, help-cfengine

If I understand correctly, you have a list of managed files that should
exist in a directory. That directory potentially contains a bunch other
files that you don't want to exist. If this is the case, I think that
you can use difference() to figure out which files should be absent.

Here is a small self contained example that shows how /tmp/example/ is
maintained so that only the list of wanted files exists.

bundle agent main
{
  vars:
      # mkdir /tmp/example && cd /tmp/example && touch this directory contains many files but only some do we want to keep
      "files" slist => { "special", "files", "we", "want", "to", "exist" };

      # Find all files that are not '.' and '..'
      "found" slist => lsdir("/tmp/example/", "[^.]{1,2}.*", "no");

      # Figure out which files exist that are not in the list of files we explicitly want.
      "extras" slist => difference( found, files );

  files:
      "/tmp/$(extras)" -> { "jira:1235" }
        delete => tidy,
        comment => "Only explictly managed files should exist";

      "/tmp/$(files)" -> { "jira:1234" }
        create => "true",
        comment => "We need these files to exist or something dosn't work well";

}

If you really only wanted to purge the extras when a change was made, then you
could define a class based on the result of the promise to manage the files.

body file control
{
  include => { "$(sys.libdir)/stdlib.cf" };
}

bundle agent main
{
  vars:
      # mkdir /tmp/example && cd /tmp/example && touch this directory contains many files but only some do we want to keep
      "files" slist => { "special", "files", "we", "want", "to", "exist" };

      # Find all files that are not '.' and '..'
      "found" slist => lsdir("/tmp/example/", "[^.]{1,2}.*", "no");

      # Figure out which files exist that are not in the list of files we explicitly want.
      "extras" slist => difference( found, files );

  files:
      "/tmp/$(files)" -> { "jira:1234" }
        create => "true",
        classes => results("bundle", "file_$(files)"),
        comment => "We need these files to exist or something dosn't work well";

       "/tmp/$(extras)" -> { "jira:1235" }
        if => classify("file_$(files)_repaired"),
        delete => tidy,
        comment => "Only explictly managed files should exist";

}


Nick Anderson
Doer of things, CFEngine

bofh...@gmail.com

unread,
Dec 22, 2016, 1:24:29 AM12/22/16
to help-cfengine
Thank you for the help.  I was able to get what I needed from Nicks comments.  Thank you Nick.

But I have another issue but I will post a new topic since it is unrelated.


Reply all
Reply to author
Forward
0 new messages