Operations 10 min read

Master Linux Startup: Systemd, chkconfig, and crontab Methods Explained

This guide details how to configure Linux services for automatic boot startup using systemd (systemctl), the legacy chkconfig method, generic script approaches, and crontab @reboot syntax, plus best‑practice recommendations for production environments.

Open Source Linux
Open Source Linux
Open Source Linux
Master Linux Startup: Systemd, chkconfig, and crontab Methods Explained

1. System Services

If a component is installed as a system service, its default service file (e.g., xxx.service) resides in /usr/lib/systemd/system.

You can enable or disable boot‑time start in two ways.

systemctl method

systemctl enable/disable xxx   # enable or disable boot start
systemctl status chronyd.service   # check if enabled
# Example output shows the service is loaded and active
systemctl list-unit-files   # list all unit files and their enable state
systemctl list-unit-files --state=enabled   # list enabled services
systemctl is-enabled xxx   # check a specific service
systemctl list-unit-files --state=disabled   # list disabled services
systemctl --state=help   # help for state options

Note: the systemctl approach creates a symlink under /etc/systemd/system/ (or /etc/systemd/user/) pointing to the original service file.

chkconfig method (more complex)

chkconfig --add xxx && chkconfig --level 3 xxx on/off
# Service scripts must reside in /etc/init.d/ and be linked in /etc/rc.d/rc*.d
chkconfig --list network   # list SysV services (does not include native systemd services)
# To list systemd services, use 'systemctl list-unit-files'
# To see services enabled for a specific target, use 'systemctl list-dependencies [target]'

To disable boot start with systemctl you can either run systemctl disable xxx or remove the corresponding symlink from /etc/systemd/system/ or /etc/systemd/user/.

2. General Approach

Regardless of whether a component is already a system service, you can use a boot‑time script. Ensure the script is executable ( chmod +x).

Add the start command to the default startup script /etc/rc.local (or its symlink /etc/rc.d/rc.local).

Create a .sh script and place it in /etc/profile.d.

Or append the execution command to /etc/rc.local / /etc/rc.d/rc.local from a custom script.

3. Crontab Approach

Crontab supports special keywords prefixed with @ to replace the five‑field time specification.

@reboot   : Run once after reboot (executes earlier than /etc/rc.d/rc.local by ~1‑2 seconds).
@yearly   : Run once a year ("0 0 1 1 *").
@annually : Same as @yearly.
@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 daemon at boot:

# crontab -e
@reboot /usr/local/daemonProcess/somescript.sh
# Daemon keep‑alive every minute
* * * * * /usr/local/daemonProcess/somescript.sh

Use @reboot together with regular schedules only when the workload tolerates possible duplicate executions within the first minute after boot.

4. Production Environment Startup Recommendations

In production, adopt a single startup method for all components to simplify operations and reduce error risk. Some services may not provide native systemd units, making the generic script approach preferable.

Appendix: Startup Script Examples

# Add commands to /etc/rc.local (or its symlink /etc/rc.d/rc.local)
# Write a script.sh and place it in /etc/profile.d
chmod +x /etc/rc.d/rc.local
# Example boot script
/usr/local/AutoStartOnBoot.sh
chmod +x /usr/local/AutoStartOnBoot.sh
# Load environment variables before starting services
source /etc/profile
# Start Redis
/usr/local/redis/redis-5.0.13/bin/redis-server /usr/local/redis/redis-5.0.13/conf/redis.conf
# Start Zookeeper (remove stale pid first)
rm -f /data/zookeeper/data/zookeeper_server.pid
/usr/local/apache-zookeeper-3.6.3-bin/bin/zkServer.sh start
# Start Kafka with JMX port
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
# Start Kafka Manager (remove stale pid first)
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 &
# Start MySQL
service mysqld start
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

OperationsLinuxSystem Administrationstartupcrontab
Open Source Linux
Written by

Open Source Linux

Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.

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.