6

In linux I can easily add a service or disable it from startup using the update-rc.d command.

I am trying to create a toggle-able service and I don't wan't to go into sed to manually edit the /etc/rc.conf file and add/edit a line service_enable=YES/NO

GAD3R
  • 63,407
  • 31
  • 131
  • 192

2 Answers2

6

There is a nice tool for the job named sysrc so you can avoid manually editing /etc/rc.conf

Example:

sysrc nginx_enable=YES
sysrc sendmail=NONE

Furthermore you have the service command to control your service:

service nginx start
service nginx reload
Claus Andersen
  • 3,239
  • 1
  • 12
  • 24
1

There is not a precise equivalent, for two reasons. update-rc.d incorporates a "policy" mechanism that has no equivalent in the Mewburn rc system; and update-rc.d has various mechanisms, defunct since 2013 admittedly, dealing in run levels which FreeBSD, like the BSD world in general, has no notion of.

On the subject of things defunct for years: on a Linux system nowadays you will be likely using systemctl rather than update-rc.d.

What you use to enable or to disable services depends from what service management system you are employing.

  • Mewburn rc: For the Mewburn rc system that comes with vanilla FreeBSD, there is indeed sysrc as mentioned by M. Andersen in another answer.
    sysrc -v jail_enable
    sysrc sshd_enable=YES
    
  • OpenRC: For the OpenRC system that comes with TrueOS, one of the FreeBSD derivatives, one enables and disables services using the rc-update command instead:
    rc-update add nginx
    rc-update del ipfw
  • nosh service management: For nosh service management in addition to the external configuration import mechanism that takes the _enable settings from various rc.conf files and translates them, you have some choices for natively enabling and disabling services:
    • There is the native system-control command:
      system-control preset gopher4d
      system-control enable sshd
      system-control disable ntpd
    • There is a compatibility systemctl command:
      systemctl preset gopher4d
      systemctl enable sshd
      systemctl disable ntpd
    • There is a compatibility update-rc.d command:
      update-rc.d sshd defaults
      update-rc.d ntpd remove

      The defaults subcommand is equivalent to system-control preset, meaning that it takes preset file information into account, and so this command is closer to the van Smoorenburg rc utility of that name.

    • There is a compatibility rcctl command:
      rcctl enable sshd
      rcctl disable ntpd

      rcctl is OpenBSD's utility for editing /etc/rc.conf.local.

All of these enable and disable native services for their respective systems.

JdeBP
  • 66,967
  • 12
  • 159
  • 343