rc-local service enabling on centos7

rc-local service enabling on centos7

In redhat systemd is used as default upstart daemon replacing int, systemd provides back wards compatibility with with the init scripts, under rehdhat/centos6 id customs were supposed to run at at boot time they would be placed in rc.local file , rc.local will be executed after the all the init process are started.

on cenots7 we can enable rc-local service.

#systemctl status rc-local 

#once the service is started create a file /etc/rc.local and set executable
permisson on it.

 root  ~  touch /etc/rc.d/rc.local 
 root  ~  chmod u+x /etc/rc.d/rc.local

rc-local file need to habe shebang defined in the first line or else , service fails.

#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: inactive (dead)
Condition: start condition failed at Thu 2018-04-05 03:49:24 IST; 2min 35s ago
           └─ ConditionFileIsExecutable=/etc/rc.d/rc.local was not met

lets modify the rc.local file

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

After restarting rc-local we can see service is running fine now.

# 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)
      CPU: 16ms

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.