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