Skip to content

Systemd

Systemd Logs

Follow Logs

Follow Logs

journalctl -u [email protected] -f

Last 50 lines

Last 50 lines

journalctl -u [email protected] -n 50

Time range

Follow Logs

journalctl -u [email protected] --since "10 minutes ago"

Create New Service

New Service

New Service

#!/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-document
cat <<EOF | sudo tee $SERVICE_FILE >/dev/null
[Unit]
Description=My Custom Service
After=network.target

[Service]
Type=simple
ExecStart=$SCRIPT_PATH
Restart=always
User=root
StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target
EOF

# Reload systemd, enable, and start the service
sudo systemctl daemon-reload
sudo systemctl enable $SERVICE_NAME
sudo 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

Follow Logs

journalctl -u myservice -f