sudo journalctl -u <service-name> | view logs for a specific service |
---|---|
sudo journalctl -u <service-name> -f | tail logs in real time |
sudo journalctl --since "1 hour ago" | |
sudo journalctl --since "2023-10-01" --until "2023-10-02” | view logs from the last hour, a specific date range, or just recent logs |
systemctl list-units --type=service --all | list every single service on your system, even disabled or static ones |
systemctl list-dependencies <service-name> | List dependencies of a service |
sudo systemctl mask <service-name> | Prevent a service from starting — manually or automatically |
sudo systemctl restart --dry-run <service-name> | see what will happen when you restart a service, but without actually doing it |
systemctl list-unit-files --type=service | list all installed unit files |
systemctl cat <service-name> | see the details of a unit file |
sudo systemctl edit <service-name> | edit a unit file |
[Unit] Description=My Custom Service After=network.target [Service] ExecStart=/path/to/your/script.sh Restart=always User=root Group=root [Install] WantedBy=multi-user.target
| Sample unit file.
Here's what each section does:
[Unit]: Defines the service's description and its relationship with other services (in this case, it starts after the network is up). [Service]: Specifies the command to run (ExecStart) and the behavior for restarting the service (Restart=always). [Install]: Ensures the service starts automatically at boot when the system reaches the multi-user target. | | sudo systemctl daemon-reload sudo systemctl enable my_custom_service.service sudo systemctl start my_custom_service.service | Reload systemd with a new unit file | | systemd-analyze plot > boot-graph.svg | visual representation of your boot process | | systemctl --failed | list and examine failed units |
https://www.youtube.com/watch?v=rAe9Iw08Fn0