Sign inSign up free

770. Stop Cleanly on SIGTERM

hard 40 XP ~14 minHands-on lab

/home/student/bin/worker.sh processes the files in /home/student/queue-lantern/in/, one at a time: it copies a file to work/, "processes" it (about 2 seconds), moves the result to done/ and deletes the input. When a deploy stops it with SIGTERM, it dies wherever it is, leaving half-written files in work/ and items processed twice after a restart.

Task

Change worker.sh so that when it receives SIGTERM:

  • it finishes the item it's working on (that item ends up in done/, its input is removed, work/ is empty),
  • it starts no new item,
  • it appends stopped after N items to /home/student/queue-lantern/worker.log (N = items finished in this run) and exits 0.

Without a signal, it keeps processing until in/ is empty, then exits 0.

About this machine

Ubuntu 24.04 with no internet access. You are student with passwordless sudo. The grader checks the final state of the machine, not the commands you typed. Values like names and ports are generated for you.

Part of Shell Scripting for Automation

Teaching or writing about this? Embed this lab on your page

TerminalNot started

Your machine is ready to start

A fresh, isolated Ubuntu machine boots in a few seconds with the task already set up.

No account needed: 3 of 3 free tries left. Guest machines last 30 minutes.