Operations 3 min read

Automate Linux Service Startup: rc.local, Crontab @reboot, and Systemd

This guide shows three reliable ways to run custom scripts automatically after a Linux machine boots—by editing /etc/rc.local, using a crontab @reboot entry, or creating a dedicated systemd service—along with example commands and advanced timing options.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Automate Linux Service Startup: rc.local, Crontab @reboot, and Systemd

Introduction

When a server loses power and restarts, manually launching many services can be tedious; configuring automatic startup scripts ensures critical processes resume without intervention.

Method 1: Using /etc/rc.local

cat /etc/rc.local
bash /root/script/restart.sh

Placing the script call in /etc/rc.local works but is considered less elegant.

Method 2: Using Crontab @reboot

crontab -e
@reboot /root/script/restart.sh

The @reboot directive runs the specified command each time the host boots.

Run the script after a delay (e.g., 5 minutes):

# Run script 5 minutes after boot
@reboot sleep 300 && /home/wwwjobs/clean-static-cache.sh

Method 3: Using a Systemd Service

# /lib/systemd/system/restart.service
[Unit]
Description=restart
After=default.target

[Service]
ExecStart=/root/script/restart.sh

[Install]
WantedBy=default.target
systemctl daemon-reload
systemctl enable restart.service

After enabling, the service executes the script automatically on each boot.

Reference Documents

https://www.google.com

https://tinyurl.com/6ryafefw

https://www.cyberciti.biz/faq/linux-execute-cron-job-after-system-reboot/

AutomationLinuxcrontabsystemdrc.localstartup scripts
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.