Master Linux Boot Startup: Systemd, chkconfig, and Crontab Techniques
This guide explains how to configure Linux services and applications to start automatically at boot using systemd (systemctl), legacy chkconfig, custom startup scripts, and crontab special keywords, offering practical commands, examples, and production‑grade recommendations for reliable operations.
1. System Service
If a component is installed as a system service, its unit file (e.g., xxx.service) resides in /usr/lib/systemd/system. You can enable boot start using either systemctl or chkconfig.
systemctl method
systemctl enable xxx # enable boot start
systemctl disable xxx # cancel boot start
systemctl status xxx.service # check status
systemctl list-unit-files --state=enabled # list enabled units
systemctl list-unit-files --state=disabled # list disabled unitsEnabling creates a symlink under /etc/systemd/system/ (or /etc/systemd/user/) pointing to the unit file.
chkconfig method (more complex)
chkconfig --add xxx && chkconfig --level 3 xxx on # add and enable at runlevel 3
chkconfig --list xxx # view status (only SysV services)To disable, either systemctl disable xxx or remove the corresponding symlink.
2. General Startup Scripts
When a component is not a system service, you can start it at boot by adding executable scripts.
Method 1: Append the command to /etc/rc.local (or its symlink /etc/rc.d/rc.local).
Method 2: Place a .sh script in /etc/profile.d.
Method 3: Write a script and append its execution line to /etc/rc.local.
Remember to make scripts executable with chmod +x.
3. Crontab Method
Crontab supports special keywords prefixed with @ to schedule tasks without the traditional five‑field time format.
@reboot : run once after reboot
@yearly : run once a year (0 0 1 1 *)
@monthly : run once a month (0 0 1 * *)
@weekly : run once a week (0 0 * * 0)
@daily : run once a day (0 0 * * *)
@hourly : run once an hour (0 * * * *)Example to start a script at boot:
# crontab -e
@reboot /usr/local/daemonProcess/somescript.sh4. Production Recommendations
In production, adopt a single boot‑start mechanism for all components to simplify operations and reduce error risk.
5. Appendix: Sample Startup Script
# chmod +x /etc/rc.d/rc.local
# /usr/local/AutoStartOnBoot.sh
chmod +x /usr/local/AutoStartOnBoot.sh
source /etc/profile
# redis
/usr/local/redis/redis-5.0.13/bin/redis-server /usr/local/redis/redis-5.0.13/conf/redis.conf
# zookeeper
rm -f /data/zookeeper/data/zookeeper_server.pid
/usr/local/apache-zookeeper-3.6.3-bin/bin/zkServer.sh start
# kafka
JMX_PORT=9999 /usr/local/kafka_2.13-2.7.1/bin/kafka-server-start.sh -daemon /usr/local/kafka_2.13-2.7.1/config/server.properties
# kafka-manager
rm -f /usr/local/kafka-manager-2.0.0.2/RUNNING_PID
nohup /usr/local/kafka-manager-2.0.0.2/bin/kafka-manager -Dconfig.file=/usr/local/kafka-manager-2.0.0.2/conf/application.conf -Dhttp.port=9002 >/dev/null 2>&1 &
# mysql
service mysqld startSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Linux Cloud Computing Practice
Welcome to Linux Cloud Computing Practice. We offer high-quality articles on Linux, cloud computing, DevOps, networking and related topics. Dive in and start your Linux cloud computing journey!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
