Ubuntu Server 1.1: Services with systemd
Stopping a service from starting, masking it, writing your own unit, and changing it with a drop-in.
Before you start
The lab doesn't install anything: installing nginx is part of task 1. It
checks that nothing listens on port 8080 yet and that there's no
hello.service.
Tasks
- Install nginx, stop it from starting at boot, then make sure it can't be started at all. Undo both, so nginx is enabled and running again.
- Write a service
hello.servicethat runs/usr/bin/python3 -m http.server 8080from/tmpas the usernobody, enabled at boot.curl -s localhost:8080 | head -1prints HTML. - With a drop-in, make
hellorestart 3 seconds after it fails. Aftersudo kill -9of its main PID, it's active again within a few seconds.
Hints
systemctl disable,mask,unmask,enable --now;is-enabled,is-active.- A unit in
/etc/systemd/system/withUser=,WorkingDirectory=,ExecStart=and[Install]WantedBy=multi-user.target;systemctl daemon-reload,enable --now.ps -o user= -C python3. sudo systemctl edit hello,Restart=on-failure,RestartSec=3;systemctl cat hello,systemctl show hello -p MainPID.