|
62073f6…
|
stephan
|
1 |
<title>Serving via rc on OpenBSD</title> |
|
62073f6…
|
stephan
|
2 |
|
|
62073f6…
|
stephan
|
3 |
OpenBSD provides [https://man.openbsd.org/rc.subr.8|rc.subr(8)], |
|
62073f6…
|
stephan
|
4 |
a framework for writing [https://man.openbsd.org/rc.8|rc(8)] scripts. |
|
62073f6…
|
stephan
|
5 |
|
|
62073f6…
|
stephan
|
6 |
<h2>Creating the daemon</h2> |
|
8a1ba49…
|
wyoung
|
7 |
|
|
62073f6…
|
stephan
|
8 |
Create the file /etc/rc.d/fossil with contents like the following. |
|
62073f6…
|
stephan
|
9 |
|
|
8a1ba49…
|
wyoung
|
10 |
<pre> |
|
62073f6…
|
stephan
|
11 |
#!/bin/ksh |
|
62073f6…
|
stephan
|
12 |
daemon="/usr/local/bin/fossil" # fossil executable |
|
62073f6…
|
stephan
|
13 |
daemon_user="_fossil" # user to run fossil as |
|
62073f6…
|
stephan
|
14 |
daemon_flags="server /home/_fossil/example --repolist --port 8888" # fossil command |
|
62073f6…
|
stephan
|
15 |
|
|
62073f6…
|
stephan
|
16 |
. /etc/rc.d/rc.subr |
|
62073f6…
|
stephan
|
17 |
# pexp="$daemon server .*" # See below. |
|
f0e1d0c…
|
mark
|
18 |
rc_reload=NO # Unsupported by Fossil; 'rcctl reload fossil' kills the process. |
|
62073f6…
|
stephan
|
19 |
rc_bg=YES # Run in the background, since fossil serve does not daemonize itself |
|
62073f6…
|
stephan
|
20 |
rc_cmd $1 |
|
8a1ba49…
|
wyoung
|
21 |
</pre> |
|
62073f6…
|
stephan
|
22 |
|
|
62073f6…
|
stephan
|
23 |
<h3>pexp</h3> |
|
8a1ba49…
|
wyoung
|
24 |
|
|
62073f6…
|
stephan
|
25 |
You may need to uncomment the "pexp=". rc.subr typically |
|
62073f6…
|
stephan
|
26 |
finds the daemon process based by matching the process name and argument list. |
|
62073f6…
|
stephan
|
27 |
Without the "pexp=" line, rc.subr would look for this exact command: |
|
62073f6…
|
stephan
|
28 |
|
|
8a1ba49…
|
wyoung
|
29 |
<pre> |
|
62073f6…
|
stephan
|
30 |
/usr/local/bin/fossil server /home/_fossil/example --repolist --port 8888 |
|
8a1ba49…
|
wyoung
|
31 |
</pre> |
|
62073f6…
|
stephan
|
32 |
|
|
62073f6…
|
stephan
|
33 |
Depending on the arguments and their order, fossil may rewrite the arguments |
|
62073f6…
|
stephan
|
34 |
for display in the process listing ([https://man.openbsd.org/ps.1|ps(1)]), |
|
62073f6…
|
stephan
|
35 |
so rc.subr may fail to find the process through the default match. The example |
|
62073f6…
|
stephan
|
36 |
above does not get rewritten, but the same commands in a different order can |
|
62073f6…
|
stephan
|
37 |
be rewritten. |
|
62073f6…
|
stephan
|
38 |
For example, when I switch the order of the arguments in "daemon_flags", |
|
62073f6…
|
stephan
|
39 |
|
|
8a1ba49…
|
wyoung
|
40 |
<pre> |
|
62073f6…
|
stephan
|
41 |
/usr/local/bin/fossil server --repolist --port 8888 /home/_fossil/example |
|
8a1ba49…
|
wyoung
|
42 |
</pre> |
|
62073f6…
|
stephan
|
43 |
|
|
62073f6…
|
stephan
|
44 |
the process command is changed to this. |
|
62073f6…
|
stephan
|
45 |
|
|
8a1ba49…
|
wyoung
|
46 |
<pre> |
|
62073f6…
|
stephan
|
47 |
/usr/local/bin/fossil server /home/_fossil/example /home/_fossil/example 8888 /home/_fossil/example |
|
8a1ba49…
|
wyoung
|
48 |
</pre> |
|
62073f6…
|
stephan
|
49 |
|
|
62073f6…
|
stephan
|
50 |
The commented "pexp=" line instructs rc.subr to choose the process whose |
|
62073f6…
|
stephan
|
51 |
command and arguments text starts with this: |
|
62073f6…
|
stephan
|
52 |
|
|
8a1ba49…
|
wyoung
|
53 |
<pre> |
|
62073f6…
|
stephan
|
54 |
/usr/local/bin/fossil server |
|
8a1ba49…
|
wyoung
|
55 |
</pre> |
|
62073f6…
|
stephan
|
56 |
|
|
62073f6…
|
stephan
|
57 |
<h2>Enabling the daemon</h2> |
|
8a1ba49…
|
wyoung
|
58 |
|
|
62073f6…
|
stephan
|
59 |
Once you have created /etc/rc.d/fossil, run these commands. |
|
62073f6…
|
stephan
|
60 |
|
|
8a1ba49…
|
wyoung
|
61 |
<pre> |
|
62073f6…
|
stephan
|
62 |
rcctl enable fossil # add fossil to pkg_scripts in /etc/rc.conf.local |
|
62073f6…
|
stephan
|
63 |
rcctl start fossil # start the daemon now |
|
8a1ba49…
|
wyoung
|
64 |
</pre> |
|
62073f6…
|
stephan
|
65 |
|
|
62073f6…
|
stephan
|
66 |
The daemon should now be running and set to start at boot. |
|
62073f6…
|
stephan
|
67 |
|
|
62073f6…
|
stephan
|
68 |
<h2>Multiple daemons</h2> |
|
8a1ba49…
|
wyoung
|
69 |
|
|
62073f6…
|
stephan
|
70 |
You may want to serve multiple fossil instances with different options. |
|
62073f6…
|
stephan
|
71 |
For example, |
|
62073f6…
|
stephan
|
72 |
|
|
62073f6…
|
stephan
|
73 |
* If different users own different repositories, you may want different users |
|
62073f6…
|
stephan
|
74 |
to serve different repositories. |
|
62073f6…
|
stephan
|
75 |
* You may want to serve different repositories on different ports so you can |
|
62073f6…
|
stephan
|
76 |
control them differently with, for example, HTTP reverse proxies or |
|
62073f6…
|
stephan
|
77 |
[https://man.openbsd.org/pf.4|pf(4)]. |
|
62073f6…
|
stephan
|
78 |
|
|
62073f6…
|
stephan
|
79 |
To run multiple fossil daemons, create multiple files in /etc/rc.d, and |
|
62073f6…
|
stephan
|
80 |
enable each of them. Here are two approaches for creating |
|
62073f6…
|
stephan
|
81 |
the files in /etc/rc.d: Symbolic links and copies. |
|
62073f6…
|
stephan
|
82 |
|
|
62073f6…
|
stephan
|
83 |
<h3>Symbolic links</h3> |
|
8a1ba49…
|
wyoung
|
84 |
|
|
62073f6…
|
stephan
|
85 |
Suppose you want to run one fossil daemon as user "user1" on port 8881 |
|
62073f6…
|
stephan
|
86 |
and another as user "user2" on port 8882. Create the files with |
|
62073f6…
|
stephan
|
87 |
[https://man.openbsd.org/ln.1|ln(1)], and configure them to run different |
|
62073f6…
|
stephan
|
88 |
fossil commands. |
|
62073f6…
|
stephan
|
89 |
|
|
8a1ba49…
|
wyoung
|
90 |
<pre> |
|
62073f6…
|
stephan
|
91 |
cd /etc/rc.d |
|
62073f6…
|
stephan
|
92 |
ln -s fossil fossil1 |
|
62073f6…
|
stephan
|
93 |
ln -s fossil fossil2 |
|
62073f6…
|
stephan
|
94 |
rcctl enable fossil1 fossil2 |
|
62073f6…
|
stephan
|
95 |
rcctl set fossil1 user user1 |
|
62073f6…
|
stephan
|
96 |
rcctl set fossil2 user user2 |
|
62073f6…
|
stephan
|
97 |
rcctl set fossil1 flags 'server /home/user1/repo1.fossil --port 8881' |
|
62073f6…
|
stephan
|
98 |
rcctl set fossil2 flags 'server /home/user2/repo2.fossil --port 8882' |
|
62073f6…
|
stephan
|
99 |
rcctl start fossil1 fossil2 |
|
8a1ba49…
|
wyoung
|
100 |
</pre> |
|
62073f6…
|
stephan
|
101 |
|
|
62073f6…
|
stephan
|
102 |
<h3>Copies</h3> |
|
8a1ba49…
|
wyoung
|
103 |
|
|
62073f6…
|
stephan
|
104 |
You may want to run fossil daemons that are too different to configure |
|
62073f6…
|
stephan
|
105 |
just with [https://man.openbsd.org/rcctl.8|rcctl(8)]. |
|
62073f6…
|
stephan
|
106 |
In particular, you can't change the "pexp" with rcctl. |
|
62073f6…
|
stephan
|
107 |
|
|
62073f6…
|
stephan
|
108 |
If you want to run fossil commands that are more different, |
|
62073f6…
|
stephan
|
109 |
you may prefer to create separate files in /etc/rc.d. |
|
62073f6…
|
stephan
|
110 |
Replace "ln -s" above with "cp" to accomplish this. |
|
62073f6…
|
stephan
|
111 |
|
|
8a1ba49…
|
wyoung
|
112 |
<pre> |
|
62073f6…
|
stephan
|
113 |
cp /etc/rc.d/fossil /etc/rc.d/fossil-user1 |
|
62073f6…
|
stephan
|
114 |
cp /etc/rc.d/fossil /etc/rc.d/fossil-user2 |
|
8a1ba49…
|
wyoung
|
115 |
</pre> |
|
62073f6…
|
stephan
|
116 |
|
|
62073f6…
|
stephan
|
117 |
You can still use commands like "rcctl set fossil-user1 flags", but you |
|
62073f6…
|
stephan
|
118 |
can also edit the "/etc/rc.d/fossil-user1" file. |