search
top

How To Create an Auto-start file aka: rc.local for Fedora 21

As with many things there always is a script, service restart or something that needs to be run to resolve and issue or to add a feature. You could create and init.d script or systemd script to address this, but you can also create a bash script called rc.local and use it for your purposes.

One of the nice things is this can be used to run multiple commands in one file that are applied system wide. For instance you have a laptop and for some reason on reboot it doesn’t keep the brightness and you have to typed the command after logging in or a service needs to restarted like sshd for an issue. There are many possibilities so you ask how do we do this? Very simple to do.

Open a terminal and navigate to /etc/rc.d

$ cd /etc/rc.d

Now let’s create the file.

$ sudo vi rc.local

Let’s start the population and the first line needs to be #!/bin/bash and after that add your command. Be aware you will want to put the full path to the command unless you are going to declare a PATH so it knows what you want to achieve.

$ sudo vi rc.local
#!/bin/bash
# Correct brightness issue
echo 200 > /sys/class/backlight/intel_backlight/brightness
# Restart the sshd service due to unknown issue
systemctl restart sshd.service

Save the file and we must make it executable so it can run.

$ sudo chmod +x /etc/rc.d/rc.local

That’s it! Systemd has a unit that enables this by default on the next boot. Note the file must be executable and in the rc.d subdirectory which is achieved by the command we just ran.

This tip will work on Fedora 19+ versions.

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

top