|
| 1 | +--- |
| 2 | +title: "how I update my sonarqube instance with very little space left" |
| 3 | +tags: ["sonarqube", "docker", "update"] |
| 4 | +keywords: ["sonarqube", "docker", "update", "space", "disk", "disk space", "disk usage", "disk usage sonarqube"] |
| 5 | +created: 2025-01-30 |
| 6 | +--- |
| 7 | + |
| 8 | +the sonarqube instance that I maintain for my company is a t4g.medium EC2 |
| 9 | +instance with very little space assigned to it (8GB). I have already mounted |
| 10 | +a separate EBS volume that allows me to store all the important data, but the |
| 11 | +instance itself has very little space left, not enough to even run a simple |
| 12 | +update. |
| 13 | + |
| 14 | +technically, the process should be straightforward: |
| 15 | + |
| 16 | +1. stop the sonarqube instance |
| 17 | +2. pull the latest version of the sonarqube image |
| 18 | +3. run the sonarqube instance |
| 19 | + |
| 20 | +BUT I usually run into some messages like this: |
| 21 | + |
| 22 | +``` |
| 23 | +write /var/lib/docker/tmp/GetImageBlob339603890: no space left on device |
| 24 | +# ... or ... |
| 25 | +failed to register layer: write /opt/sonarqube/lib/extensions/sonar-iac-plugin-1.40.0.13983.jar: no space left on device |
| 26 | +``` |
| 27 | + |
| 28 | +this has happened every single time that I get a prompt asking me to update the |
| 29 | +version of the sonarqube instance, which happens every 3 months or so. my |
| 30 | +mental process is usually something like this: |
| 31 | + |
| 32 | +1. okay, let's quickly prune docker caches/images/layers/etc. |
| 33 | +2. that wasn't enough, let's see what's taking up space (I use `ncdu` for this) |
| 34 | +3. let's delete some old logs, maybe that'll free up some space |
| 35 | +4. ??? |
| 36 | +5. profit? |
| 37 | + |
| 38 | +this time, I decided to actually document the process, so I can do it again in |
| 39 | +the future. |
| 40 | + |
| 41 | +### you have to stop the instances!!! |
| 42 | +yes! and there should be nothing wrong with that, I'm already saving all the |
| 43 | +data in volumes, right? well yes, but I'm always afraid of losing information, |
| 44 | +so I recheck that the `docker-compose.yml` file is correctly configured to use |
| 45 | +the volumes. |
| 46 | + |
| 47 | +after checking, I stop the instances and prune all caches and images: |
| 48 | + |
| 49 | +```sh |
| 50 | +docker compose down |
| 51 | +yes | docker system prune -a; yes | docker builder prune -a |
| 52 | +``` |
| 53 | + |
| 54 | +{% tilImg 'clear-docker.png', 'result of the docker system prune command' %} |
| 55 | + |
| 56 | +this is much of the space that I'm looking for, but I'm not done yet. |
| 57 | + |
| 58 | +### delete journal logs |
| 59 | + |
| 60 | +the next step is to *vacuum* the journal logs, as they take up more than 500MB |
| 61 | +of space (in my case). |
| 62 | + |
| 63 | +{% tilImg 'journal-size.png', 'journal dir size in ncdu' %} |
| 64 | + |
| 65 | +to delete the journal logs, I use the following command: |
| 66 | + |
| 67 | +```sh |
| 68 | +journalctl --vacuum-size=10M |
| 69 | +``` |
| 70 | + |
| 71 | +### delete unused kernel versions |
| 72 | + |
| 73 | +the last step is to delete the unused kernel versions. in AL2023, the system |
| 74 | +usually keeps the last 3 kernel versions, so we can delete the unused ones |
| 75 | +using the following command: |
| 76 | + |
| 77 | +```sh |
| 78 | +sudo dnf remove --oldinstallonly |
| 79 | +``` |
| 80 | + |
| 81 | +this will remove the unused kernel versions as well as other packages that are |
| 82 | +no longer "active" (usually only kernel packages). |
| 83 | + |
| 84 | +## summary |
| 85 | + |
| 86 | +this is the summary of the process: |
| 87 | + |
| 88 | +1. stop the sonarqube instance |
| 89 | +2. prune docker caches/images/layers/etc. |
| 90 | +3. delete journal logs |
| 91 | +4. delete unused kernel versions |
| 92 | +5. start the sonarqube instance |
| 93 | + |
| 94 | +single command: |
| 95 | + |
| 96 | +```sh |
| 97 | +docker compose down; yes | docker system prune -a; yes | docker builder prune -a; journalctl --vacuum-size=10M; sudo dnf remove --oldinstallonly; docker compose up -d |
| 98 | +``` |
0 commit comments