SystemD
Follow Logs
Section titled “Follow Logs”!!!note “Follow Logs”
```shelljournalctl -u code-server@root.service -f```Last 50 lines
Section titled “Last 50 lines”!!!note “Last 50 lines”
```shelljournalctl -u code-server@root.service -n 50```Time range
Section titled “Time range”!!!note “Follow Logs”
```shelljournalctl -u code-server@root.service --since "10 minutes ago"```Create New Service
Section titled “Create New Service”New Service
Section titled “New Service”!!!note “New Service”
```shell#!/bin/bash
SERVICE_NAME="myservice"SERVICE_FILE="/etc/systemd/system/$SERVICE_NAME.service"SCRIPT_PATH="/usr/local/bin/myscript.sh"
# Create the systemd service file using a here-documentcat <<EOF | sudo tee $SERVICE_FILE >/dev/null[Unit]Description=My Custom ServiceAfter=network.target
[Service]Type=simpleExecStart=$SCRIPT_PATHRestart=alwaysUser=rootStandardOutput=journalStandardError=journal
[Install]WantedBy=multi-user.targetEOF
# Reload systemd, enable, and start the servicesudo systemctl daemon-reloadsudo systemctl enable $SERVICE_NAMEsudo systemctl start $SERVICE_NAME
echo "$SERVICE_NAME service has been created and started successfully."echo "Check logs with: journalctl -u $SERVICE_NAME -f"```Follow Logs
Section titled “Follow Logs”!!!note “Follow Logs”
```journalctl -u myservice -f```