Baptiste Daroussin, a member of the FreeBSD Core Team and author of the pkg package manager, is developing a new service manager for FreeBSD called rcd. The rcd service manager is invoked by the init process instead of /etc/rc, reads service configuration files (/etc/rcd.d/*.ucl), builds a dependency tree, and starts services concurrently whenever possible, after which it monitors the service operation and restarts them if necessary.
Background process management and service operations can be performed through direct command transmission to a UNIX socket or using the command-line utility rctl. Unit files with service parameters are formatted in UCL, which resembles the configuration file formats of nginx and bind, with elements for simplifying automated processing borrowed from JSON. There is an option to create template unit files and write built-in handlers in Lua. An example unit file for starting nginx: name = "nginx"; description = "Nginx HTTP Server"; type = "simple"; command = "/usr/local/sbin/nginx"; command_args = "-g 'daemon off;'"; provides = ["nginx", "http"]; requires = ["NETWORKING", "sshd"]; restart { policy = "always"; max_retries = 10; delay = 2000; backoff = "linear"; } process { user = "www"; group = "www"; cpuset = "0-3"; } rctl { memoryuse = { action = "deny"; amount = "2g"; }; pcpu = { action = "throttle"; amount = "80"; }; }
Instead of working with PID files, tracking the activity of running processes is done using descriptors returned by the system call pdfork(). There is support for activating services only upon access to the network socket and the ability to protect critical services from forced termination in case of memory shortage in the system. It is possible to update the version of the background process rcd on the fly without losing state.
To limit the resources available to a service, rctl is used, while complete isolation of services is supported through their execution in jail environments. Access to the controlling UNIX socket can be configured in relation to individual services. Sleep mode transition is supported.
The system manager is fully backward compatible with the existing rc.d service startup system and can operate without changing the current rc.d scripts and configuration files. It is sufficient to install rcd on a running system, and after a restart, everything will continue to function as before, except for reduced boot time due to parallelizing service startups. This compatibility will facilitate the migration of systems to rcd and enable a gradual transition of existing rc.d scripts to unit file format.
To maintain compatibility with rc.d, a special type of unit called 'legacy' is supported. Rcd scans the contents of /etc/rc.d/ and /usr/local/etc/rc.d/, parses the PROVIDE/REQUIRE/BEFORE/KEYWORD headers in the scripts, reads the rc.conf settings, and determines the state of script startups, after which it processes each script as a virtual legacy unit. When using the rcctl command to manage such virtual units, the operations are translated into the old format; for instance, executing 'rcctl reload sshd' will result in ' /etc/rc.d/sshd reload'.
Source: opennet.ru
