# Startup commands



## Mwh65 (May 2, 2018)

FreeBSD 11.1 p9
PHP 5.6.36
MySQL 5.7.22

I have some commands listed below which I would like ran when the server starts up. Normally I manually run them from SSH after the server has booted up but sometimes I forget to do so which causes all sorts of problems onsite ...


```
cd /websites/pgls/forums/chatrooms/socket
./server stop
cd ..
php -f FlashPolicyService.php
cd socket
./server start
```

Is there an easy way or is it likely I will need to create a script in the rc.d directory ?


----------



## SirDice (May 2, 2018)

Mwh65 said:


> is it likely I will need to create a script in the rc.d directory


That's the best and cleanest solution. And it's really not that difficult to do.


----------



## ShelLuser (May 3, 2018)

You could also set up a cronjob and then use @reboot in the time field. See also crontab(5). This will ensure that the job gets run when Cron gets started. This seems to be safe enough because from what I can tell Cron will only start after all the other 'major' targets such as NETWORKING and FILESYSTEMS have been provided.


----------



## ralphbsz (May 3, 2018)

Is this a service, which can be started and stopped, and which you might want to disable at times and enable at other times (for example for maintenance)?  But perhaps which right now you only want to start at boot time (you haven't felt the need for the other functions stop/disable/enable yet)?  Then the logical place is a new script in rc.d.  Since it is a local service, you should probably put it in /usr/local/etc/rc.d.

Or is it something that is guaranteed to only have to be done when booting, independent of other services having been enabled or disabled?  The @reboot in crontab would work (although I personally find that a little perverse, not really what cron was intended for, although it can do it just fine).  Another choice would be /etc/rc.local, or more accurately: Take these commands, put them into a shell script with an obvious name like /usr/local/sbin/start_Mwh65_flashpolicyservice, comment the script well and make it standalone, and then call it from rc.local.  Personally, I find that also a little perverse: rc.local is deprecated for things like services, and the only thing that I have left in there is site-specific hardware setups (my printer port needs to be tweaked, the keyboard layout needs to be adjusted to the unusual keyboard I have, and so on).

My recommendation would be a rc.d script, since it really seems that you are starting a service here.  And you probably want to think about how this service is to be stopped.


----------

