# FILES STARTS WITH RC PREFIX IN /etc folder



## ravinew1 (Jul 4, 2019)

Hi all,
I do not know this question is relevant or not but i am asking.

I am exploring some application deployed on Freebsd.
This application written using PHP, which has  some .inc files also along with normal php files.
In this app, there are some scripts in /etc/ folder with prefix rc such as rc.file_config which
actually contains  php code which has included statements importing .inc files.

My doubt is , How these files starts with prefix rc will be used. when  these
files will be executed.

why applications put their own config files with prefix rc in /etc folder.

If there are so many config files starts with rc prefix. In which order they will be executed.

thank you for help


----------



## usdmatt (Jul 4, 2019)

Without seeing what these files are trying to do, or how they are actually used it’s difficult to give a definitive answer. However two important points -

1) An application should not be dumping files in /etc. This is for base system configuration files and startup scripts.

2) the rc system will run various scripts in /etc during system startup/shutdown. However, it doesn’t just run any file that happens to start with rc.

Scripts in /etc/rc.d and /usr/local/etc/rc.d are run on boot/shutdown. The order of these can be seen with the service() command.


----------



## SirDice (Jul 4, 2019)

ravinew1 said:


> If there are so many config files starts with rc prefix. In which order they will be executed.


Read rc(8) and rcorder(8).


----------



## ravinew1 (Jul 5, 2019)

I have seen rcorder available which is in binary form. Is there any chance of  another rc file which defines oder of config files?

There is a rc.bootup file in /etc folder. It contains the following code.
<code>
#!/usr/local/bin/php-cgi -f
<?php
some code
<?>
</code>

1) When this code is executed,  How "#!/usr/local/bin/php-cgi -f" line helps?


----------



## usdmatt (Jul 5, 2019)

> When this code is executed, How "#!/usr/local/bin/php-cgi -f" line helps?



When you try an execute a text file, the shell will look for that first line, and if it starts #!, it will execute the listed program, and pass in the filename as the argument. So when you execute `/etc/rc.bootup`, it will actually run `/usr/local/bin/php-cgi -f /etc/rc.bootup`. This is why most scripting languages support # for comments, as it allows them to conveniently ignore this first line when the actual php/perl/sh/etc program runs.

However, not only is executing an rc script via PHP incredibly ugly and non-standard, but I can find no documentation of rc.bootup, so it's still not clear how this is being run.

Overall it looks like the way this application has been implemented is incredibly messy. Here is what I would do if I wanted to create a PHP application (called 'myapp') that runs on boot via the rc system.


I would create my main PHP application in /usr/local/sbin/myapp. This is the standard location for 3rd party programs (i.e. those that are not part of base FreeBSD
If there were any additional scripts (classes/includes/etc) that go with this, I would put those under /usr/local/lib/myapp/ (or maybe /usr/local/share/myapp/). This is the standard location for 3rd party library files.
I would create a shell based rc script called /usr/local/etc/rc.d/myapp to start/stop this application on boot/shutdown. (I normally just use one of those existing scripts as a template for my own). This then allows starting/stopping the service with `service start|stop myapp` if the script has been written correctly.
If you look at any scripts in there (or /etc/rc.d where base FreeBSD startup scripts are located), you will see a section at the top containing PROVIDE/REQUIRE/BEFORE information. This is the information used by rc to decide what order services need to be started in. As an example, a service that "REQUIRES" mysql, will start after the service which "PROVIDES" mysql.


----------

