10/60
Sign inSign up free

747. A start/stop/status Script

medium 20 XP ~12 minHands-on lab

/home/student/indexer/run.sh is a long-running worker. Write the control script /home/student/bin/svc.sh for it:

svc.sh start|stop|status|restart

Task

  • start: if the worker isn't running, start /home/student/indexer/run.sh in the background, write its PID to /home/student/indexer/worker.pid, print started and exit 0. If it is already running, print already running and exit 0 without starting a second one.
  • stop: stop the worker if it runs, remove the PID file, print stopped, exit 0 (also when it wasn't running).
  • status: print running and exit 0, or print stopped and exit 3. A PID file left behind by a worker that died counts as stopped.
  • restart: stop, then start; exit 0.
  • Anything else (or nothing): print usage: svc.sh start|stop|status|restart to stderr and exit 2.

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.

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.