From b1b375ef480af436fb2d509b9e3ac841f713ef7c Mon Sep 17 00:00:00 2001 From: Dave Wilding Date: Wed, 26 Feb 2025 14:03:54 +0800 Subject: [PATCH] docs: small updates to machine charm tutorial (#1583) This PR is for capturing small updates to [Write your first machine charm](https://ops.readthedocs.io/en/latest/tutorial/write-your-first-machine-charm.html) while I'm working on creating my own sample machine charm. Summary of changes: - Adjusted the "What you'll need section" to tidy up the language & formatting, and to clarify that familiarity with Juju is not an absolute requirement. - When using `curl` to test the service after the initial deployment, we don't need to `juju exec` into the unit first. Instead, we can do `curl http://10.122.219.101:8080`, where 10.122.219.101 is the IP of the unit. I've updated the command and the preceding text to match. - Added missing context to the note that comes after using `curl` to test the service. This note was supposed to say that the reader should follow the four steps in case something went wrong after deploying the charm. I added this context. I also removed a commented-out part about inspecting hooks. In the newly-added context, I mention about `juju debug-log`, which is probably more useful than inspecting hooks. **[Preview doc](https://ops--1583.org.readthedocs.build/en/1583/tutorial/write-your-first-machine-charm.html)** --- .../write-your-first-machine-charm.md | 43 +++++++------------ 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/docs/tutorial/write-your-first-machine-charm.md b/docs/tutorial/write-your-first-machine-charm.md index 05ba67c76..684c3c246 100644 --- a/docs/tutorial/write-your-first-machine-charm.md +++ b/docs/tutorial/write-your-first-machine-charm.md @@ -12,10 +12,12 @@ When it's available in Juju. --> **What you'll need:** -- A workstation, e.g., a laptop, with amd64 architecture and which has sufficient resources to launch a virtual machine with 4 CPUs, 8 GB RAM, and 50 GB disk space -- Familiarity with Linux -- Familiarity with Juju. -- Familiarity with object-oriented programming in Python + +- A workstation. For example, a laptop with an amd64 architecture. You'll need sufficient resources to launch a virtual machine with 4 CPUs, 8 GB RAM, and 50 GB disk space. +- Familiarity with Linux. +- Familiarity with the Python programming language, including Object-Oriented Programming and event handlers. + +It will also help if you're familiar with Juju, but don't worry if you're new to Juju. This tutorial will guide you through each step. **What you'll do:** @@ -232,39 +234,26 @@ Machine State Address Inst id Base AZ Message ``` -Finally, test that the service works by executing `curl` on your application unit: +Finally, use `curl` to test that the service works. Get the address of the running machine from the Juju status +(10.122.219.101 in this example), then run `curl`: ```text -ubuntu@charm-dev:~/microsample-vm$ juju exec --unit microsample/0 -- "curl -s http://localhost:8080" +ubuntu@charm-dev:~/microsample-vm$ curl http://10.122.219.101:8080 Online ``` ```{note} -1. Fix the code in `src/charm.py`. -2. Rebuild the charm: `charmcraft pack` -3. Refresh the application from the repacked charm: `juju refresh microsample --path=./microsample-vm_ubuntu-22.04-amd64.charm --force-units` -4. Let the model know the issue is resolved (fixed): `juju resolved microsample/0`. +If the Juju status doesn't look right, for example if you see an "error" status instead of "active", +there might be an issue with the charm code. You can use a debug session (`juju debug-log`) to get +more detailed information about the issue. After you've identified the issue: -``` +1. Fix the code in `src/charm.py`. +2. Rebuild the charm: `charmcraft pack`. +3. Refresh the application from the repacked charm: `juju refresh microsample --path=./microsample-vm_ubuntu-22.04-amd64.charm --force-units`. +4. Let the model know that you've fixed the issue: `juju resolved microsample/0`. - - - ```{note}