Created
December 22, 2024 10:10
-
-
Save love4taylor/45187fe1f31003aa83e36451f86bafab to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # PROVIDE: sing_box | |
| # REQUIRE: networking | |
| # KEYWORD: shutdown | |
| # Add these lines to /etc/rc.conf.local or /etc/rc.conf to enable `sing-box': | |
| # | |
| # sing_box_enable (bool): Set to "NO" by default. | |
| # Set it to "YES" to enable sing-box | |
| # sing_box_workdir (path): Set to "/usr/local/etc/sing-box" by default | |
| # Set it to the sing-box working directory | |
| # sing_box_config (path): Set to "/usr/local/etc/sing-box/config.json" by default | |
| # Set it to the sing-box server config | |
| . /etc/rc.subr | |
| name="sing_box" | |
| rcvar="${name}_enable" | |
| : ${sing_box_enable="NO"} | |
| : ${sing_box_workdir="/usr/local/etc/sing-box"} | |
| : ${sing_box_config="/usr/local/etc/sing-box/config.json"} | |
| : ${sing_box_user="root"} | |
| : ${sing_box_group="wheel"} | |
| pidfile="/var/run/sing-box.pid" | |
| procname="/usr/local/bin/sing-box" | |
| command="/usr/sbin/daemon" | |
| command_args="-c -p ${pidfile} -f ${procname} run -c ${sing_box_config} -D ${sing_box_workdir}" | |
| start_precmd="sing_box_startprecmd" | |
| sing_box_startprecmd() { | |
| touch "${pidfile}" | |
| mkdir -p ${sing_box_workdir} | |
| chown ${sing_box_user}:${sing_box_group} "${pidfile}" ${sing_box_workdir} | |
| } | |
| load_rc_config "$name" | |
| run_rc_command "$1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment