This file is indexed.

/usr/share/doc/libvirt-doc/hooks.html is in libvirt-doc 1.3.1-1ubuntu10.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!--
        This file is autogenerated from hooks.html.in
        Do not edit this file. Changes will be lost.
      -->
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" type="text/css" href="main.css" />
    <link rel="SHORTCUT ICON" href="32favicon.png" />
    <title>libvirt: Hooks for specific system management</title>
    <meta name="description" content="libvirt, virtualization, virtualization API" />
  </head>
  <body>
    <div id="header">
      <div id="headerLogo"></div>
      <div id="headerSearch">
        <form action="search.php" enctype="application/x-www-form-urlencoded" method="get"><div>
            <input id="query" name="query" type="text" size="12" value="" />
            <input id="submit" name="submit" type="submit" value="Search" />
          </div></form>
      </div>
    </div>
    <div id="body">
      <div id="menu">
        <ul class="l0"><li>
            <div>
              <a title="Front page of the libvirt website" class="inactive" href="index.html">Home</a>
            </div>
          </li><li>
            <div>
              <a title="Details of new features and bugs fixed in each release" class="inactive" href="news.html">News</a>
            </div>
          </li><li>
            <div>
              <a title="Applications known to use libvirt" class="inactive" href="apps.html">Applications</a>
            </div>
          </li><li>
            <div>
              <a title="Get the latest source releases, binary builds and get access to the source repository" class="inactive" href="downloads.html">Downloads</a>
            </div>
          </li><li>
            <div>
              <a title="Information for users, administrators and developers" class="active" href="docs.html">Documentation</a>
              <ul class="l1"><li>
                  <div>
                    <a title="How to compile libvirt" class="inactive" href="compiling.html">Compiling</a>
                  </div>
                </li><li>
                  <div>
                    <a title="Information about deploying and using libvirt" class="active" href="deployment.html">Deployment</a>
                    <ul class="l2"><li>
                        <div>
                          <a title="The URI formats used for connecting to libvirt" class="inactive" href="uri.html">URI format</a>
                        </div>
                      </li><li>
                        <div>
                          <a title="Enable remote access over TCP" class="inactive" href="remote.html">Remote access</a>
                        </div>
                      </li><li>
                        <div>
                          <a title="Configure authentication for the libvirt daemon" class="inactive" href="auth.html">Authentication</a>
                        </div>
                      </li><li>
                        <div>
                          <a title="Configure access control libvirt APIs" class="inactive" href="acl.html">Access control</a>
                        </div>
                      </li><li>
                        <div>
                          <a title="Migrating guests between machines" class="inactive" href="migration.html">Migration</a>
                        </div>
                      </li><li>
                        <div>
                          <a title="Access the libvirt daemon from a native Windows client" class="inactive" href="windows.html">Windows port</a>
                        </div>
                      </li><li>
                        <div>
                          <a title="The library and the daemon logging support" class="inactive" href="logging.html">Logging</a>
                        </div>
                      </li><li>
                        <div>
                          <a title="Audit trail logs for host operations" class="inactive" href="auditlog.html">Audit log</a>
                        </div>
                      </li><li>
                        <div>
                          <a title="Firewall and network filter configuration" class="inactive" href="firewall.html">Firewall</a>
                        </div>
                      </li><li>
                        <div>
                          <a title="Ensuring exclusive guest access to disks" class="inactive" href="locking.html">Disk locking</a>
                        </div>
                      </li><li>
                        <div>
                          <a title="Control groups integration" class="inactive" href="cgroups.html">CGroups</a>
                        </div>
                      </li><li>
                        <div>
                          <span class="active">Hooks</span>
                        </div>
                      </li></ul>
                  </div>
                </li><li>
                  <div>
                    <a title="Overview of the logical subsystems in the libvirt API" class="inactive" href="intro.html">Architecture</a>
                  </div>
                </li><li>
                  <div>
                    <a title="Description of the XML formats used in libvirt" class="inactive" href="format.html">XML format</a>
                  </div>
                </li><li>
                  <div>
                    <a title="Hypervisor specific driver information" class="inactive" href="drivers.html">Drivers</a>
                  </div>
                </li><li>
                  <div>
                    <a title="Reference manual for the C public API" class="inactive" href="html/index.html">API reference</a>
                  </div>
                </li><li>
                  <div>
                    <a title="Bindings of the libvirt API for other languages" class="inactive" href="bindings.html">Language bindings</a>
                  </div>
                </li><li>
                  <div>
                    <a title="Working on the internals of libvirt API, driver and daemon code" class="inactive" href="internals.html">Internals</a>
                  </div>
                </li><li>
                  <div>
                    <a title="A guide and reference for developing with libvirt" class="inactive" href="devguide.html">Development Guide</a>
                  </div>
                </li><li>
                  <div>
                    <a title="Command reference for virsh" class="inactive" href="virshcmdref.html">Virsh Commands</a>
                  </div>
                </li><li>
                  <div>
                    <a title="Project governance and code of conduct" class="inactive" href="governance.html">Governance</a>
                  </div>
                </li></ul>
            </div>
          </li><li>
            <div>
              <a title="User contributed content" class="inactive" href="http://wiki.libvirt.org">Wiki</a>
            </div>
          </li><li>
            <div>
              <a title="Frequently asked questions" class="inactive" href="http://wiki.libvirt.org/page/FAQ">FAQ</a>
            </div>
          </li><li>
            <div>
              <a title="How and where to report bugs and request features" class="inactive" href="bugs.html">Bug reports</a>
            </div>
          </li><li>
            <div>
              <a title="How to contact the developers via email and IRC" class="inactive" href="contact.html">Contact</a>
            </div>
          </li><li>
            <div>
              <a title="Available test suites for libvirt" class="inactive" href="testsuites.html">Test suites</a>
            </div>
          </li><li>
            <div>
              <a title="Miscellaneous links of interest related to libvirt" class="inactive" href="relatedlinks.html">Related Links</a>
            </div>
          </li><li>
            <div>
              <a title="Overview of all content on the website" class="inactive" href="sitemap.html">Sitemap</a>
            </div>
          </li></ul>
      </div>
      <div id="content">
        <h1>Hooks for specific system management</h1>
        <ul><li>
            <a href="#intro">Custom event scripts</a>
          </li><li>
            <a href="#location">Script location</a>
          </li><li>
            <a href="#names">Script names</a>
          </li><li>
            <a href="#structure">Script structure</a>
          </li><li>
            <a href="#arguments">Script arguments</a>
          </li><li>
            <a href="#execution">Script execution</a>
          </li><li>
            <a href="#qemu_migration">QEMU guest migration</a>
          </li><li>
            <a href="#recursive">Calling libvirt functions from within a hook script</a>
          </li><li>
            <a href="#return_codes">Return codes and logging</a>
          </li></ul>
        <h2>
          <a name="intro" shape="rect" id="intro">Custom event scripts</a>
          <a class="headerlink" href="#intro" title="Permalink to this headline"></a>
        </h2>
        <p>Beginning with libvirt 0.8.0, specific events on a host system will
       trigger custom scripts.</p>
        <p>These custom <b>hook</b> scripts are executed when any of the following
       actions occur:</p>
        <ul><li>The libvirt daemon starts, stops, or reloads its
          configuration
          (<span class="since">since 0.8.0</span>)<br /><br /></li><li>A QEMU guest is started or stopped
         (<span class="since">since 0.8.0</span>)<br /><br /></li><li>An LXC guest is started or stopped
         (<span class="since">since 0.8.0</span>)<br /><br /></li><li>A network is started or stopped or an interface is
          plugged/unplugged to/from the network
          (<span class="since">since 1.2.2</span>)<br /><br /></li></ul>
        <h2>
          <a name="location" shape="rect" id="location">Script location</a>
          <a class="headerlink" href="#location" title="Permalink to this headline"></a>
        </h2>
        <p>The libvirt hook scripts are located in the directory
       <code>$SYSCONFDIR/libvirt/hooks/</code>.</p>
        <ul><li>In Linux distributions such as Fedora and RHEL, this is
          <code>/etc/libvirt/hooks/</code>.  Other Linux distributions may do
          this differently.</li><li>If your installation of libvirt has instead been compiled from
          source, it is likely to be
          <code>/usr/local/etc/libvirt/hooks/</code>.</li></ul>
        <p>To use hook scripts, you will need to create this <code>hooks</code>
       directory manually, place the desired hook scripts inside, then make
       them executable.</p>
        <br />
        <h2>
          <a name="names" shape="rect" id="names">Script names</a>
          <a class="headerlink" href="#names" title="Permalink to this headline"></a>
        </h2>
        <p>At present, there are three hook scripts that can be called:</p>
        <ul><li><code>/etc/libvirt/hooks/daemon</code><br /><br />
          Executed when the libvirt daemon is started, stopped, or reloads
          its configuration<br /><br /></li><li><code>/etc/libvirt/hooks/qemu</code><br /><br />
          Executed when a QEMU guest is started, stopped, or migrated<br /><br /></li><li><code>/etc/libvirt/hooks/lxc</code><br /><br />
          Executed when an LXC guest is started or stopped</li><li><code>/etc/libvirt/hooks/network</code><br /><br />
          Executed when a network is started or stopped or an
          interface is plugged/unplugged to/from the network</li></ul>
        <br />
        <h2>
          <a name="structure" shape="rect" id="structure">Script structure</a>
          <a class="headerlink" href="#structure" title="Permalink to this headline"></a>
        </h2>
        <p>The hook scripts are executed using standard Linux process creation
       functions.  Therefore, they must begin with the declaration of the
       command interpreter to use.</p>
        <p>For example:</p>
        <pre xml:space="preserve">#!/bin/bash</pre>
        <p>or:</p>
        <pre xml:space="preserve">#!/usr/bin/python</pre>
        <p>Other command interpreters are equally valid, as is any executable
       binary, so you are welcome to use your favourite languages.</p>
        <br />
        <h2>
          <a name="arguments" shape="rect" id="arguments">Script arguments</a>
          <a class="headerlink" href="#arguments" title="Permalink to this headline"></a>
        </h2>
        <p>The hook scripts are called with specific command line arguments,
       depending upon the script, and the operation being performed.</p>
        <p>The guest hook scripts, qemu and lxc, are also given the <b>full</b>
       XML description for the domain on their stdin. This includes items
       such the UUID of the domain and its storage information, and is
       intended to provide all the libvirt information the script needs.</p>
        <p>For all cases, stdin of the network hook script is provided with the
       full XML description of the network status in the following form:</p>
        <pre xml:space="preserve">&lt;hookData&gt;
  &lt;network&gt;
     &lt;name&gt;$network_name&lt;/name&gt;
     &lt;uuid&gt;afca425a-2c3a-420c-b2fb-dd7b4950d722&lt;/uuid&gt;
     ...
  &lt;/network&gt;
&lt;/hookData&gt;</pre>
        <p>In the case of an interface
       being plugged/unplugged to/from the network, the network XML will be
       followed with the full XML description of the domain containing the
       interface that is being plugged/unplugged:</p>
        <pre xml:space="preserve">&lt;hookData&gt;
  &lt;network&gt;
     &lt;name&gt;$network_name&lt;/name&gt;
     &lt;uuid&gt;afca425a-2c3a-420c-b2fb-dd7b4950d722&lt;/uuid&gt;
     ...
  &lt;/network&gt;
  &lt;domain type='$domain_type' id='$domain_id'&gt;
     &lt;name&gt;$domain_name&lt;/name&gt;
     &lt;uuid&gt;afca425a-2c3a-420c-b2fb-dd7b4950d722&lt;/uuid&gt;
     ...
  &lt;/domain&gt;
&lt;/hookData&gt;</pre>
        <p>Please note that this approach is different from other cases such as
       <code>daemon</code>, <code>qemu</code> or <code>lxc</code> hook scripts,
       because two XMLs may be passed here, while in the other cases only a single
       XML is passed.</p>
        <p>The command line arguments take this approach:</p>
        <ol><li>The first argument is the name of the <b>object</b> involved in the
          operation, or '-' if there is none.<br /><br />
          For example, the name of a guest being started.<br /><br /></li><li>The second argument is the name of the <b>operation</b> being
          performed.<br /><br />
          For example, "start" if a guest is being started.<br /><br /></li><li>The third argument is a <b>sub-operation</b> indication, or '-' if there
          is none.<br /><br /></li><li>The last argument is an <b>extra argument</b> string, or '-' if there is
          none.</li></ol>
        <h4>
          <a name="arguments_specifics" shape="rect" id="arguments_specifics">Specifics</a>
          <a class="headerlink" href="#arguments_specifics" title="Permalink to this headline"></a>
        </h4>
        <p>This translates to the following specifics for each hook script:</p>
        <h5>
          <a name="daemon" shape="rect" id="daemon">/etc/libvirt/hooks/daemon</a>
          <a class="headerlink" href="#daemon" title="Permalink to this headline"></a>
        </h5>
        <ul><li>When the libvirt daemon is started, this script is called as:<br />
          <pre xml:space="preserve">/etc/libvirt/hooks/daemon - start - start</pre></li><li>When the libvirt daemon is shut down, this script is called as:<br />
          <pre xml:space="preserve">/etc/libvirt/hooks/daemon - shutdown - shutdown</pre></li><li>When the libvirt daemon receives the SIGHUP signal, it reloads its
          configuration and triggers the hook script as:<br />
          <pre xml:space="preserve">/etc/libvirt/hooks/daemon - reload begin SIGHUP</pre></li></ul>
        <p>Please note that when the libvirt daemon is restarted, the <i>daemon</i>
       hook script is called once with the "shutdown" operation, and then once
       with the "start" operation.  There is no specific operation to indicate
       a "restart" is occurring.</p>
        <h5>
          <a name="qemu" shape="rect" id="qemu">/etc/libvirt/hooks/qemu</a>
          <a class="headerlink" href="#qemu" title="Permalink to this headline"></a>
        </h5>
        <ul><li>Before a QEMU guest is started, the qemu hook script is
        called in three locations; if any location fails, the guest
        is not started.  The first location, <span class="since">since
        0.9.0</span>, is before libvirt performs any resource
        labeling, and the hook can allocate resources not managed by
        libvirt such as DRBD or missing bridges.  This is called as:<br />
        <pre xml:space="preserve">/etc/libvirt/hooks/qemu guest_name prepare begin -</pre>
        The second location, available <span class="since">Since
        0.8.0</span>, occurs after libvirt has finished labeling
        all resources, but has not yet started the guest, called as:<br />
        <pre xml:space="preserve">/etc/libvirt/hooks/qemu guest_name start begin -</pre>
        The third location, <span class="since">0.9.13</span>,
        occurs after the QEMU process has successfully started up:<br />
        <pre xml:space="preserve">/etc/libvirt/hooks/qemu guest_name started begin -</pre>
      </li><li>When a QEMU guest is stopped, the qemu hook script is called
        in two locations, to match the startup.
        First, <span class="since">since 0.8.0</span>, the hook is
        called before libvirt restores any labels:<br />
        <pre xml:space="preserve">/etc/libvirt/hooks/qemu guest_name stopped end -</pre>
        Then, after libvirt has released all resources, the hook is
        called again, <span class="since">since 0.9.0</span>, to allow
        any additional resource cleanup:<br />
        <pre xml:space="preserve">/etc/libvirt/hooks/qemu guest_name release end -</pre></li><li><span class="since">Since 0.9.11</span>, the qemu hook script
        is also called at the beginning of incoming migration. It is called
        as: <pre xml:space="preserve">/etc/libvirt/hooks/qemu guest_name migrate begin -</pre>
        with domain XML sent to standard input of the script. In this case,
        the script acts as a filter and is supposed to modify the domain
        XML and print it out on its standard output. Empty output is
        identical to copying the input XML without changing it. In case the
        script returns failure or the output XML is not valid, incoming
        migration will be canceled. This hook may be used, e.g., to change
        location of disk images for incoming domains.</li><li><span class="since">Since 1.2.9</span>, the qemu hook script is
        also called when restoring a saved image either via the API or
        automatically when restoring a managed save machine. It is called
        as: <pre xml:space="preserve">/etc/libvirt/hooks/qemu guest_name restore begin -</pre>
        with domain XML sent to standard input of the script. In this case,
        the script acts as a filter and is supposed to modify the domain
        XML and print it out on its standard output. Empty output is
        identical to copying the input XML without changing it. In case the
        script returns failure or the output XML is not valid, restore of the
        image will be aborted. This hook may be used, e.g., to change
        location of disk images for restored domains.</li><li><span class="since">Since 0.9.13</span>, the qemu hook script
        is also called when the libvirtd daemon restarts and reconnects
        to previously running QEMU processes. If the script fails, the
        existing QEMU process will be killed off. It is called as:
        <pre xml:space="preserve">/etc/libvirt/hooks/qemu guest_name reconnect begin -</pre>
      </li><li><span class="since">Since 0.9.13</span>, the qemu hook script
        is also called when the QEMU driver is told to attach to an
        externally launched QEMU process. It is called as:
        <pre xml:space="preserve">/etc/libvirt/hooks/qemu guest_name attach begin -</pre>
      </li></ul>
        <h5>
          <a name="lxc" shape="rect" id="lxc">/etc/libvirt/hooks/lxc</a>
          <a class="headerlink" href="#lxc" title="Permalink to this headline"></a>
        </h5>
        <ul><li>Before a LXC guest is started, the lxc hook script is
        called in three locations; if any location fails, the guest
        is not started.  The first location, <span class="since">since
        0.9.13</span>, is before libvirt performs any resource
        labeling, and the hook can allocate resources not managed by
        libvirt such as DRBD or missing bridges.  This is called as:<br />
        <pre xml:space="preserve">/etc/libvirt/hooks/lxc guest_name prepare begin -</pre>
        The second location, available <span class="since">Since
        0.8.0</span>, occurs after libvirt has finished labeling
        all resources, but has not yet started the guest, called as:<br />
        <pre xml:space="preserve">/etc/libvirt/hooks/lxc guest_name start begin -</pre>
        The third location, <span class="since">0.9.13</span>,
        occurs after the LXC process has successfully started up:<br />
        <pre xml:space="preserve">/etc/libvirt/hooks/lxc guest_name started begin -</pre>
      </li><li>When a LXC guest is stopped, the lxc hook script is called
        in two locations, to match the startup.
        First, <span class="since">since 0.8.0</span>, the hook is
        called before libvirt restores any labels:<br />
        <pre xml:space="preserve">/etc/libvirt/hooks/lxc guest_name stopped end -</pre>
        Then, after libvirt has released all resources, the hook is
        called again, <span class="since">since 0.9.0</span>, to allow
        any additional resource cleanup:<br />
        <pre xml:space="preserve">/etc/libvirt/hooks/lxc guest_name release end -</pre></li><li><span class="since">Since 0.9.13</span>, the lxc hook script
        is also called when the libvirtd daemon restarts and reconnects
        to previously running LXC processes. If the script fails, the
        existing LXC process will be killed off. It is called as:
        <pre xml:space="preserve">/etc/libvirt/hooks/lxc guest_name reconnect begin -</pre>
      </li></ul>
        <h5>
          <a name="network" shape="rect" id="network">/etc/libvirt/hooks/network</a>
          <a class="headerlink" href="#network" title="Permalink to this headline"></a>
        </h5>
        <ul><li><span class="since">Since 1.2.2</span>, before a network is started,
        this script is called as:<br />
          <pre xml:space="preserve">/etc/libvirt/hooks/network network_name start begin -</pre></li><li>After the network is started, up ∧ running, the script is
        called as:<br />
          <pre xml:space="preserve">/etc/libvirt/hooks/network network_name started begin -</pre></li><li>When a network is shut down, this script is called as:<br />
          <pre xml:space="preserve">/etc/libvirt/hooks/network network_name stopped end -</pre></li><li>Later, when network is started and there's an interface from a
        domain to be plugged into the network, the hook script is called as:<br />
          <pre xml:space="preserve">/etc/libvirt/hooks/network network_name plugged begin -</pre>
        Please note, that in this case, the script is passed both network and
        domain XMLs on its stdin.</li><li>When the domain from previous case is shutting down, the interface
        is unplugged. This leads to another script invocation:<br />
          <pre xml:space="preserve">/etc/libvirt/hooks/network network_name unplugged begin -</pre>
        And again, as in previous case, both network and domain XMLs are passed
        onto script's stdin.</li></ul>
        <br />
        <h2>
          <a name="execution" shape="rect" id="execution">Script execution</a>
          <a class="headerlink" href="#execution" title="Permalink to this headline"></a>
        </h2>
        <ul><li>The "start" operation for the guest and network hook scripts,
          executes <b>prior</b> to the object (guest or network) being created.
          This allows the object start operation to be aborted if the script
          returns indicating failure.<br /><br /></li><li>The "shutdown" operation for the guest and network hook scripts,
          executes <b>after</b> the object (guest or network) has stopped. If
          the hook script indicates failure in its return, the shut down of the
          object cannot be aborted because it has already been performed.
          <br /><br /></li><li>Hook scripts execute in a synchronous fashion.  Libvirt waits
          for them to return before continuing the given operation.<br /><br />
          This is most noticeable with the guest or network start operation,
          as a lengthy operation in the hook script can mean an extended wait
          for the guest or network to be available to end users.<br /><br /></li><li>For a hook script to be utilised, it must have its execute bit set
          (e.g. chmod o+rx <i>qemu</i>), and must be present when the libvirt
          daemon is started.<br /><br /></li><li>If a hook script is added to a host after the libvirt daemon is
          already running, it won't be used until the libvirt daemon
          next starts.</li></ul>
        <br />
        <h2>
          <a name="qemu_migration" shape="rect" id="qemu_migration">QEMU guest migration</a>
          <a class="headerlink" href="#qemu_migration" title="Permalink to this headline"></a>
        </h2>
        <p>Migration of a QEMU guest involves running hook scripts on both the
       source and destination hosts:</p>
        <ol><li>At the beginning of the migration, the <i>qemu</i> hook script on
          the <b>destination</b> host is executed with the "migrate"
          operation.</li><li>Before QEMU process is spawned, the two operations ("prepare" and
          "start") called for domain start are executed on
          <b>destination</b> host.</li><li>If both of these hook script executions exit successfully (exit
          status 0), the migration continues.  Any other exit code indicates
          failure, and the migration is aborted.</li><li>The QEMU guest is then migrated to the destination host.</li><li>Unless an error occurs during the migration process, the <i>qemu</i>
          hook script on the <b>source</b> host is then executed with the
          "stopped" and "release" operations to indicate it is no longer
          running on this host. Regardless of the return codes, the
          migration is not aborted as it has already been performed.</li></ol>
        <br />
        <h2>
          <a name="recursive" shape="rect" id="recursive">Calling libvirt functions from within a hook script</a>
          <a class="headerlink" href="#recursive" title="Permalink to this headline"></a>
        </h2>
        <p>
          <b>DO NOT DO THIS!</b>
        </p>
        <p>A hook script must not call back into libvirt, as the libvirt daemon
       is already waiting for the script to exit.</p>
        <p>A deadlock is likely to occur.</p>
        <br />
        <h2>
          <a name="return_codes" shape="rect" id="return_codes">Return codes and logging</a>
          <a class="headerlink" href="#return_codes" title="Permalink to this headline"></a>
        </h2>
        <p>If a hook script returns with an exit code of 0, the libvirt daemon
       regards this as successful and performs no logging of it.</p>
        <p>However, if a hook script returns with a non zero exit code, the libvirt
       daemon regards this as a failure, logs its return code, and
       additionally logs anything on stderr the hook script returns.</p>
        <p>For example, a hook script might use this code to indicate failure,
       and send a text string to stderr:</p>
        <pre xml:space="preserve">echo "Could not find required XYZZY" &gt;&amp;2
exit 1</pre>
        <p>The resulting entry in the libvirt log will appear as:</p>
        <pre xml:space="preserve">20:02:40.297: error : virHookCall:285 : Hook script execution failed: internal error Child process (LC_ALL=C PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
                       HOME=/root USER=root LOGNAME=root /etc/libvirt/hooks/qemu qemu prepare begin -) unexpected exit status 1: Could not find required XYZZY</pre>
      </div>
    </div>
    <div id="footer">
      <p id="sponsor">
	    Sponsored by:<br /><a href="http://et.redhat.com/"><img src="et.png" alt="Project sponsored by Red Hat Emerging Technology" /></a></p>
    </div>
  </body>
</html>