Tue, April 3, 2018 ยท 1 min read

rc-local service enabling on centos7

rc-local service enabling on centos7

In Redhat systemd is used as default init system replacing sysvinit. Under RHEL/CentOS 6 if custom scripts were supposed to run at boot time they would be placed in rc.local file. On CentOS 7 we can enable rc-local service.

Check status

# systemctl status rc-local

Create rc.local file

# touch /etc/rc.d/rc.local
# chmod u+x /etc/rc.d/rc.local

The rc.local file needs to have shebang defined in the first line or else the service fails.

Edit rc.local

# cat /etc/rc.d/rc.local
#!/bin/bash
echo hello

Start the service

# sudo systemctl start rc-local

# sudo systemctl status rc-local
โ— rc-local.service - /etc/rc.d/rc.local Compatibility
   Loaded: loaded (/usr/lib/systemd/system/rc-local.service; static; vendor preset: disabled)
   Active: active (exited) since Thu 2018-04-05 04:05:07 IST; 2s ago
  Process: 18246 ExecStart=/etc/rc.d/rc.local start (code=exited, status=0/SUCCESS)

Apr 05 04:05:07 server.sand.box systemd[1]: Starting /etc/rc.d/rc.local Compatibility...
Apr 05 04:05:07 server.sand.box rc.local[18246]: hello
Apr 05 04:05:07 server.sand.box systemd[1]: Started /etc/rc.d/rc.local Compatibility.