https://www.vultr.com

The Everywhere Cloud

Deploy an instance.
Accelerate your application.


Running FreeBSD Commands at Startup


The following procedure enables FreeBSD programs to start automatically after booting, without requiring users to log in first. This method is useful when automating custom daemons to act as servers with user-specific privileges.

This is almost identical to the Linux procedure, except for one redirection parameter excluded here.

==========

1. Edit the user crontab file.

user@host: $ crontab -e

2. Add the @reboot line with the desired command.

# BEGIN CODE

@reboot /myfolder/mydaemon.sh > /dev/null &

# "> /dev/null" discards standard output by redirecting to the null device.

# Terminating with "&" executes the command in the background.

# END CODE

3. Save and exit crontab, then reboot the machine.

==========

The default shell configured in an account's environment variables is used by crontab to process the listed commands. In Linux crontab, the default Bourne Again shell (bash) accepts parameters like "2>&1" which redirects standard error to standard output.

Although some default shells in FreeBSD accept the "2>&1" redirection parameter, such as the Bourne shell (sh) used by regular user accounts, others like the extended C shell (tcsh) used by the "root" superuser do not. So for the purpose of uniform implementation, regardless of the default shell present, such redirection is skipped altogether.

==========

Comments

Popular posts from this blog

Enabling HTTPS in Home Assistant

Configuring the FreeBSD Firewall with IPFW

Running Home Assistant on FreeBSD Servers