auto-run script at boot time in c7

General support questions
Post Reply
neuronetv
Posts: 76
Joined: 2012/01/08 21:53:07

auto-run script at boot time in c7

Post by neuronetv » 2014/08/26 19:33:04

I've been trawling google and this forum but can't see a way to get centos 7 to auto-run a script at boot time. Google has plenty about this on centos 5 and 6 but very little on centos 7.
The script is /root/red5-screens.sh, it works fine if run manually. What I've tried so far:
# chkconfig /root/red5-screens.sh on
error reading information on service /root/red5-screens.sh: No such file or directory
# chkconfig --add /root/red5-screens.sh
error reading information on service red5-screens.sh: No such file or directory
putting an entry in rc.local doesn'r work either. Thanks for any pointers.

jensd
Posts: 36
Joined: 2014/07/08 12:23:09

Re: auto-run script at boot time in c7

Post by jensd » 2014/08/27 11:48:10

/etc/rc.local or /etc/rc.d/rc.local are no longer executed by default due to systemd-changes.
to still use those, you need to make /etc/rc.d/rc.local executable:

Code: Select all

chmod +x /etc/rc.d/rc.local
If the script is executable, it should be executed at boot when you add a line containing

Code: Select all

/root/red5-screens.sh 
to /etc/rc.local (which is a symlink to /etc/rc.d/rc.local)
to be sure that your script is executable, just do a chmod +x /root/red5-screens.sh

To debug your problem, it would be a good idea to redirect the output of the script (if there is any) to a logfile to be sure if the script has been executed or not.

neuronetv
Posts: 76
Joined: 2012/01/08 21:53:07

Re: auto-run script at boot time in c7

Post by neuronetv » 2014/08/27 13:07:45

jensd thanks for this help, your suggestions worked.

bpb21
Posts: 2
Joined: 2014/10/07 18:59:55

Re: auto-run script at boot time in c7

Post by bpb21 » 2015/09/24 18:41:47

This post helped me out as well with a similar situation, so thanks!

But, one further question: what is the non-rc.d way of running a script at startup for c7? As in, what is the "way of the future" with systemd for running scripts at startup?

User avatar
TrevorH
Forum Moderator
Posts: 27164
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: auto-run script at boot time in c7

Post by TrevorH » 2015/09/24 23:12:23

You create a systemd unit file in /etc/systemd/system/ by looking at the ones in /usr/lib/systemd/system that do a similar job to the one you want to create.
CentOS 6 will die in November 2020 - migrate sooner rather than later!
CentOS 5 has been EOL for nearly 3 years and should no longer be used for anything!
Full time Geek, part time moderator. Use the FAQ Luke

MohammedAlahmed
Posts: 1
Joined: 2015/10/28 12:46:33

Re: auto-run script at boot time in c7

Post by MohammedAlahmed » 2015/10/28 12:49:08

jensd thanks for this it was really useful

Post Reply

Return to “CentOS 7 - General Support”