|
1 | 1 | # Debug an IOC instance locally
|
2 | 2 |
|
3 |
| -Todo |
| 3 | +:::{warning} |
| 4 | +This is an early draft |
| 5 | +::: |
4 | 6 |
|
5 |
| -# Debug an IOC instance in Kubernetes |
| 7 | +This guide will show you how to debug an IOC instance locally. It will use the example IOC made in the [Create an IOC instance](./create-ioc-instance.md) guide. That IOC is called `bl01t-ea-test-02` in the guide but you may have chosen a different name. |
6 | 8 |
|
7 |
| -Todo |
| 9 | +## Setting up |
| 10 | + |
| 11 | +Get the IOC Instance definition repository and deliberately break the IOC instance so that you can debug it. |
| 12 | + |
| 13 | +```bash |
| 14 | +git clone [email protected]:YOUR_GITHUB_USERNAME/bl01t.git |
| 15 | +cd bl01t |
| 16 | +source environment.sh |
| 17 | +code . |
| 18 | +# now edit services/bl01t-ea-test-02/config/ioc.yaml |
| 19 | +``` |
| 20 | + |
| 21 | +## Breaking the IOC instance |
| 22 | + |
| 23 | +Add the phrase 'deliberate_error' to the top of the `ioc.yaml` file. Then try to launch the IOC instance, but use the `-v` flag to see the underlying commands: |
| 24 | + |
| 25 | +```bash |
| 26 | +ec -v deploy-local services/bl01t-ea-test-02 |
| 27 | +``` |
| 28 | + |
| 29 | +You should see something like this (for docker users - podman users will see something similar): |
| 30 | + |
| 31 | +<pre>$ ec -v deploy-local services/bl01t-ea-test-02 |
| 32 | +<font color="#5F8787">docker --version</font> |
| 33 | +<font color="#5F8787">docker buildx version</font> |
| 34 | +Deploy TEMPORARY version 2024.2.17-b8.30 from /home/giles/tutorial/bl01t/services/bl01t-ea-test-02 to the local docker instance |
| 35 | +Are you sure ? [y/N]: y |
| 36 | +<font color="#5F8787">docker stop -t0 bl01t-ea-test-02</font> |
| 37 | +<font color="#5F8787">docker rm -f bl01t-ea-test-02</font> |
| 38 | +<font color="#5F8787">docker volume rm -f bl01t-ea-test-02_config</font> |
| 39 | +<font color="#5F8787">docker volume create bl01t-ea-test-02_config</font> |
| 40 | +<font color="#5F8787">docker rm -f busybox</font> |
| 41 | +<font color="#5F8787">docker container create --name busybox -v bl01t-ea-test-02_config:/copyto busybox</font> |
| 42 | +<font color="#5F8787">docker cp /home/giles/tutorial/bl01t/services/bl01t-ea-test-02/config/ioc.yaml busybox:copyto</font> |
| 43 | +<font color="#5F8787">docker rm -f busybox</font> |
| 44 | +<font color="#5F8787">docker run -dit --net host --restart unless-stopped -l is_IOC=true -l version=2024.2.17-b8.30 -v bl01t-ea-test-02_config:/epics/ioc/config/ -e IOC_NAME=bl01t-ea-test-02 --name bl01t-ea-test-02 ghcr.io/epics-containers/ioc-adsimdetector-linux-runtime:2024.2.2</font> |
| 45 | +76c2834dac805780b3329af91c332abb90fb2692a510c11b888b82e48f60b44f |
| 46 | +<font color="#5F8787">docker ps -f name=bl01t-ea-test-02 --format '{{.Names}}'</font> |
| 47 | +</pre> |
| 48 | + |
| 49 | +Now if you try these commands you should see that the IOC instance keeps restarting and that the logs show an error: |
| 50 | + |
| 51 | +```bash |
| 52 | +ec ps |
| 53 | +ec logs bl01t-ea-test-02 |
| 54 | +``` |
| 55 | + |
| 56 | +## Debugging the IOC instance |
| 57 | + |
| 58 | +Now you can tell `ec` to stop the IOC instance and then run it in a way that you can debug it, by copying the command that `ec` used to run the IOC instance and adding the `--entrypoint bash` and removing `-d` flag and `--restart unless-stopped`. Also change the name to have a `-debug` suffix, like so: |
| 59 | + |
| 60 | +```bash |
| 61 | +ec stop bl01t-ea-test-02 |
| 62 | +docker run --entrypoint bash -it --net host -l is_IOC=true -l version=2024.2.17-b8.30 -v bl01t-ea-test-02_config:/epics/ioc/config/ -e IOC_NAME=bl01t-ea-test-02 --name bl01t-ea-test-02-debug ghcr.io/epics-containers/ioc-adsimdetector-linux-runtime:2024.2.2 |
| 63 | +``` |
| 64 | + |
| 65 | +You should now be in a shell inside the container. You can look at the files and run the IOC instance manually to see what the error is. You can re-run the IOC instance multiple times and you can even install your favourite editor or debugging tools. |
| 66 | + |
| 67 | +e.g. |
| 68 | + |
| 69 | +```bash |
| 70 | +apt update |
| 71 | +apt install vim |
| 72 | +ls /epics/ioc/config/ |
| 73 | +cat /epics/ioc/config/ioc.yaml |
| 74 | +cd /epics/ioc |
| 75 | +./start.sh |
| 76 | +# ctrl-d to exit |
| 77 | +vim /epics/ioc/config/ioc.yaml |
| 78 | +# fix the error |
| 79 | +./start.sh |
| 80 | +``` |
| 81 | + |
| 82 | +When you are done you can exit the container with `ctrl-d` and then remove it (or you can keep it around for later and restart it with `docker start -i bl01t-ea-test-02-debug`): |
| 83 | + |
| 84 | +```bash |
| 85 | +docker rm -f bl01t-ea-test-02-debug |
| 86 | +``` |
| 87 | + |
| 88 | +You can now apply the fix you made to the local filesystem and retry the deployment. |
0 commit comments