Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: Update docs on boothooks #5546

Merged
merged 2 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/examples/boothook.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#cloud-boothook
#!/bin/sh
echo 192.168.1.130 us.archive.ubuntu.com > /etc/hosts
51 changes: 42 additions & 9 deletions doc/rtd/explanation/format.rst
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,50 @@ a MIME archive.
``cloud-boothook``
==================

This content is `boothook` data. It is stored in a file under
:file:`/var/lib/cloud` and executed immediately. This is the earliest `hook`
available. Note, that there is no mechanism provided for running only once. The
`boothook` must take care of this itself.
One line ``#cloud-boothook`` header and then executable payload.

It is provided with the instance id in the environment variable
``INSTANCE_ID``. This could be made use of to provide a 'once-per-instance'
type of functionality.
This is run very early on the boot process, during the
:ref:`Network boot stage<boot-Network>`, even before ``cc_bootcmd``.

Begins with: ``#cloud-boothook`` or ``Content-Type: text/cloud-boothook`` when
using a MIME archive.
This can be used when something has to be configured very early on boot,
potentially on every boot, with less convenience as ``cc_bootcmd`` but more
flexibility.

.. note::
Boothooks are executed on every boot.
The environment variable ``INSTANCE_ID`` will be set to the current instance
ID. ``INSTANCE_ID`` can be used to implement a `once-per-instance` type of
functionality.

Begins with: ``#cloud-boothook``.

Example with simple script
--------------------------

.. code-block:: bash

#cloud-boothook
#!/bin/sh
echo 192.168.1.130 us.archive.ubuntu.com > /etc/hosts

Example of once-per-instance script
-----------------------------------

.. code-block:: bash

#cloud-boothook
#!/bin/sh

PERSIST_ID=/var/lib/cloud/first-instance-id
_id=""
if [ -r $PERSIST_ID ]; then
_id=$(cat /var/lib/cloud/first-instance-id)
fi

if [ -z $_id ] || [ $INSTANCE_ID != $_id ]; then
echo 192.168.1.130 us.archive.ubuntu.com >> /etc/hosts
fi
sudo echo $INSTANCE_ID > $PERSIST_ID

Part-handler
============
Expand Down
7 changes: 7 additions & 0 deletions doc/rtd/reference/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ Run commands on first boot
:language: yaml
:linenos:

Run commands on very early at every boot
========================================

.. literalinclude:: ../../examples/boothook.txt
:language: bash
:linenos:

Install arbitrary packages
==========================

Expand Down
Loading