Its not very complicated to create a init script in FreeBSD and we could have our own reasons to do it. Example that we will have below, will create a file, to prove that the init script is working.

To start, go to /usr/local/etc/rc.d/ and create a new file, owned by root.

$su -
# cd /usr/local/etc/rc.d/ 
# vim

Put this in to your code:

# This script will create a test.txt file in your /root dir
echo 'Test' > /root/test.txt
chown root:wheel /root/test.txt

Now we give our script executable rights:

# chmod +x

Last thing that you must to do, is to tell the system about our script, and that we want to execute it during boot process. That's why we must to add one line to /etc/rc.conf


After a reebot we can find a test.txt file in /root directory.