Put in remaining pages and wiki contents.
[ikiwiki.git] / docs / handbook / handbook-configtuning-rcng.mdwn
1 ## 6.7 Using rc under DragonFly \r
2 \r
3 ***Contributed by Tom Rhodes. ***\r
4 \r
5 DragonFly uses the NetBSD® `rc.d` system for system initialization. Users should notice the files listed in the `/etc/rc.d` directory. Many of these files are for basic services which can be controlled with the `start`, `stop`, and `restart` options. For instance, [sshd(8)](http://leaf.dragonflybsd.org/cgi/web-man?command#sshd&section8&manpath=OpenBSD+3.3) can be restarted with the following command:\r
6 \r
7     \r
8     # /etc/rc.d/sshd restart\r
9 \r
10 \r
11 This procedure is similar for other services. Of course, services are usually started automatically as specified in [rc.conf(5)](http://leaf.dragonflybsd.org/cgi/web-man?command#rc.conf&section5). For example, enabling the Network Address Translation daemon at startup is as simple as adding the following line to `/etc/rc.conf`:\r
12 \r
13     \r
14     natd_enable="YES"\r
15 \r
16 \r
17 If a `natd_enable="NO"` line is already present, then simply change the `NO` to `YES`. The rc scripts will automatically load any other dependent services during the next reboot, as described below.\r
18 \r
19 Since the `rc.d` system is primarily intended to start/stop services at system startup/shutdown time, the standard `start`, `stop` and `restart` options will only perform their action if the appropriate `/etc/rc.conf` variables are set. For instance the above `sshd restart` command will only work if `sshd_enable` is set to `YES` in `/etc/rc.conf`. To `start`, `stop` or `restart` a service regardless of the settings in `/etc/rc.conf`, the commands should be prefixed with ***force***. For instance to restart `sshd` regardless of the current `/etc/rc.conf` setting, execute the following command:\r
20 \r
21     \r
22     # /etc/rc.d/sshd forcerestart\r
23 \r
24 \r
25 It is easy to check if a service is enabled in `/etc/rc.conf` by running the appropriate `rc.d` script with the option `rcvar`. Thus, an administrator can check that `sshd` is in fact enabled in `/etc/rc.conf` by running:\r
26 \r
27     \r
28     # /etc/rc.d/sshd rcvar\r
29     # sshd\r
30     $sshd_enable=YES\r
31 \r
32 \r
33  **Note:** The second line (`# sshd`) is the output from the `rc.d` script, not a `root` prompt.\r
34 \r
35 To determine if a service is running, a `status` option is available. For instance to verify that `sshd` is actually started:\r
36 \r
37     \r
38     # /etc/rc.d/sshd status\r
39     sshd is running as pid 433.\r
40 \r
41 \r
42 It is also possible to `reload` a service. This will attempt to send a signal to an individual service, forcing the service to reload its configuration files. In most cases this means sending the service a `SIGHUP` signal.\r
43 \r
44 The  **rcNG**  structure is used both for network services and system initialization. Some services are run only at boot; and the RCNG system is what triggers them.\r
45 \r
46 Many system services depend on other services to function properly. For example, NIS and other RPC-based services may fail to start until after the `rpcbind` (portmapper) service has started. To resolve this issue, information about dependencies and other meta-data is included in the comments at the top of each startup script. The [rcorder(8)](http://leaf.dragonflybsd.org/cgi/web-man?command#rcorder&section8) program is then used to parse these comments during system initialization to determine the order in which system services should be invoked to satisfy the dependencies. The following words may be included at the top of each startup file:\r
47 \r
48
49 * `PROVIDE`: Specifies the services this file provides.\r
50
51 * `REQUIRE`: Lists services which are required for this service. This file will run ***after*** the specified services.\r
52
53 * `BEFORE`: Lists services which depend on this service. This file will run ***before*** the specified services.\r
54
55 * KEYWORD: When [rcorder(8)](http://leaf.dragonflybsd.org/cgi/web-man?command#rcorder&section8) uses the `-k` option, then only the rc.d files matching this keyword are used. [(1)](#FTN.AEN4751) For example, when using `-k shutdown`, only the `rc.d` scripts defining the `shutdown` keyword are used.\r
56   With the `-s` option, [rcorder(8)](http://leaf.dragonflybsd.org/cgi/web-man?command#rcorder&section8) will skip any `rc.d` script defining the corresponding keyword to skip. For example, scripts defining the `nostart` keyword are skipped at boot time.\r
57 \r
58 By using this method, an administrator can easily control system services without the hassle of ***runlevels*** like some other UNIX® operating systems.\r
59 \r
60 Additional information about the DragonFly `rc.d` system can be found in the [rc(8)](http://leaf.dragonflybsd.org/cgi/web-man?command#rc&section8), [rc.conf(5)](http://leaf.dragonflybsd.org/cgi/web-man?command=rc.conf&section=5), and [rc.subr(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=rc.subr&section=8) manual pages.\r
61 ### Using DragonFly's rcrun(8) \r
62 Besides the methods described above DragonFly supports [rcrun(8)](http://leaf.dragonflybsd.org/cgi/web-man?command#rcrun&section8) to control rc(8) scripts.  [rcrun(8)](http://leaf.dragonflybsd.org/cgi/web-man?command=rcrun&section=8) provides a number of command for controlling rc(8)\r
63 scripts.  The ***start***, ***forcestart***, ***faststart***, ***stop***, ***restart***, and ***rcvar*** commands are just passed to the scripts.  See rc(8) for more information on these commands.\r
64 \r
65 The remaining commands are:\r
66 \r
67 [[!table  data="""
68 |  **disable**  | Sets the corresponding `_enable` variable in rc.conf(5) to ***NO*** and runs the stop command. 
69   **enable**   | Sets the corresponding `_enable` variable in rc.conf(5) to ***YES*** and runs the start command. 
70   **list**  | Shows the status of the specified scripts.  If no argument is specified, the status of all scripts is shown. |\r
71 """]]\r
72 To check if [dntpd(8)](http://leaf.dragonflybsd.org/cgi/web-man?command#dntpd&section8) is running you can use the following command:\r
73     \r
74     # rclist dntpd\r
75     rcng_dntpd=stopped\r
76 \r
77 To start [dntpd(8)](http://leaf.dragonflybsd.org/cgi/web-man?command#dntpd&section8):\r
78 \r
79     \r
80     # rcstart dntpd\r
81     Running /etc/rc.d/dntpd start\r
82     Starting dntpd.\r
83 \r
84 Restart and stop works the same way:\r
85     \r
86     # rcrestart dntpd\r
87     Stopping dntpd.\r
88     Starting dntpd.\r
89     \r
90     # rcstop dntpd\r
91     Stopping dntpd.\r
92 \r
93 \r
94 If a service is not enabled in `/etc/rc.conf`, but you want it start anyway, execute the following:\r
95     \r
96     # rcforce dntpd\r
97     Running /etc/rc.d/dntpd forcestart\r
98     Starting dntpd.\r
99 \r
100 #### Notes \r
101 \r
102 [[!table  data="""
103 |<tablestyle="width:100%"> [(1)](configtuning-rcng.html#AEN4751) | Previously this was used to define *BSD dependent features. |\r
104 """]]