If by 'atomic' you mean 'do things all in one go, or not at all', then no, it isnt. To me it sounds like you want some sort of all-or-nothing transaction, in which either all the commands are complete, or none at all.

I'm not sure quite what those commands are doing, but what happens if you update the hostgroup, but fail to update the host, do you have an inconsistent system then? In which case you need to code some sort of 'undo' sub, which you can pass a value which indicates how far the script got before it encountered an error, and proceeds to undo the previous steps to return to the state the system was in before you started. And *then* it can die, or exit, or whatever..

Eg:

chdir("$staging_directory") or undo(1); system("svn", "update", "base") or undo(2); ... sub undo { my $state = shift; if($state >= .. ) # highest one first .. if($state >= 2) { system("svn" .. ) # undo svn/update/base command } if($state >= 1) { chdir("-"); # undo chdir command } die "Got to level X: $!\n"; }
.. or something.. but maybe I misunderstood what you wanted. C.

In reply to Re: Is "die" the best way to be atomic? by castaway
in thread Is "die" the best way to be atomic? by BuddhaNature

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.