Skip to content

Commit d034a40

Browse files
uaisuDreamacro
authored andcommitted
Doc: add FreeBSD rc script (#2925)
1 parent db2b5db commit d034a40

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

docs/introduction/service.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,3 +130,85 @@ Stop Clash with:
130130
```shell
131131
docker-compose stop
132132
```
133+
134+
## FreeBSD rc
135+
136+
install clash with `ports(7)` or `pkg(8)`
137+
138+
copy the required files to `/usr/local/etc/clash`
139+
140+
```shell
141+
cp config.yaml /usr/local/etc/clash/
142+
cp Country.mmdb /usr/local/etc/clash/
143+
```
144+
145+
Create the rc configuration file at `/usr/local/etc/rc.d/clash`:
146+
147+
```shell
148+
#!/bin/sh
149+
150+
# PROVIDE: clash
151+
# REQUIRE: NETWORKING DAEMON
152+
# BEFORE: LOGIN
153+
# KEYWORD: shutdown
154+
155+
. /etc/rc.subr
156+
157+
name=clash
158+
rcvar=clash_enable
159+
160+
: ${clash_enable="NO"}
161+
: ${clash_config_dir="/usr/local/etc/clash"}
162+
163+
required_dirs="${clash_config_dir}"
164+
required_files="${clash_config_dir}/config.yaml ${clash_config_dir}/Country.mmdb"
165+
166+
command="/usr/sbin/daemon"
167+
procname="/usr/local/bin/${name}"
168+
pidfile="/var/run/${name}.pid"
169+
start_precmd="${name}_prestart"
170+
171+
clash_prestart()
172+
{
173+
rc_flags="-T ${name} -p ${pidfile} ${procname} -d ${clash_config_dir} ${rc_flags}"
174+
}
175+
176+
load_rc_config $name
177+
run_rc_command "$1"
178+
```
179+
180+
make the script executable:
181+
182+
```shell
183+
chmod +x /usr/local/etc/rc.d/clash
184+
```
185+
186+
Launch clashd on system startup with:
187+
188+
```shell
189+
service clash enable
190+
```
191+
192+
Launch clashd immediately with:
193+
194+
```shell
195+
service clash onestart
196+
```
197+
198+
Check the status of Clash with:
199+
200+
```shell
201+
service clash status
202+
```
203+
204+
You can check log in file `/var/log/daemon.log`
205+
206+
::: tip
207+
If you want to change the default config directory add the following lines to /etc/rc.conf :
208+
```shell
209+
clash_enable (bool): Set it to YES to run clash on startup.
210+
Default: NO
211+
clash_config_dir (string): clash config directory.
212+
Default: /usr/loca/etc/clash
213+
```
214+
:::

0 commit comments

Comments
 (0)