惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
The Last Watchdog
The Last Watchdog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
T
Troy Hunt's Blog
L
LINUX DO - 最新话题
C
Check Point Blog
T
Threat Research - Cisco Blogs
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
罗磊的独立博客
V
Vulnerabilities – Threatpost
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
J
Java Code Geeks
Apple Machine Learning Research
Apple Machine Learning Research
大猫的无限游戏
大猫的无限游戏
S
Security @ Cisco Blogs
IT之家
IT之家
T
The Exploit Database - CXSecurity.com
The GitHub Blog
The GitHub Blog
D
Docker
Engineering at Meta
Engineering at Meta
AWS News Blog
AWS News Blog
S
Security Affairs
U
Unit 42
P
Palo Alto Networks Blog
V
Visual Studio Blog
Y
Y Combinator Blog
D
DataBreaches.Net
Forbes - Security
Forbes - Security
阮一峰的网络日志
阮一峰的网络日志
美团技术团队
Security Latest
Security Latest
aimingoo的专栏
aimingoo的专栏
Simon Willison's Weblog
Simon Willison's Weblog
A
Arctic Wolf
博客园_首页
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
H
Hacker News: Front Page
博客园 - 司徒正美
博客园 - Franky
宝玉的分享
宝玉的分享
TaoSecurity Blog
TaoSecurity Blog
Latest news
Latest news
Scott Helme
Scott Helme
MongoDB | Blog
MongoDB | Blog
量子位
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
C
Cisco Blogs
P
Privacy International News Feed
Application and Cybersecurity Blog
Application and Cybersecurity Blog

Jiajun的技术笔记

你好,2026! TiDB 源码阅读(六):TiDB Coprocessor 源码解析 性能优化的核心思想 TiDB 源码阅读(五):索引 TiDB 源码阅读(四):AST、逻辑计划、物理计划 CockroachDB Serverless Architecture podman 无故退出 Cursor Control-L (CTRL-L) Keyboard Shortcuts in Terminal Replace docker with podman Using xmonad with xfce4 自己动手写一个k8s controller AI 会取代你的(编程)岗位吗? 自建DERP服务器提升Tailscale连接速度(使用Nginx转发) 自动升级Docker容器 再读《程序员修炼之道-从小工到专家》 让浏览器下载文件 再读《软件随想录》/《黑客与画家》/《软技能》 HTTP 压力测试中的 Coordinated Omission 2的补码 编程语言中的 context 是什么? flutter macOS 构建出错 Flatpak 使用小记 Golang CAS 操作是怎么实现的 PostgreSQL 当MQ来使用 Clash 结合 工作VPN 的网络设计 使用 PostgreSQL 搭建 JuiceFS PostgreSQL 配置优化和日志分析 有GitHub Copilot?那就可以搭建你的ChatGPT4服务 窗口函数的使用(以PG为例) 读《为什么学生不喜欢上学》 OpenAI Prompt Engineering 摘录和总结 读《打造真正的新产品》 VueJS 总结 Linux 自动挂载 alist 提供的webdav FreeBSD 使用 vm-bhyve 安装Debian虚拟机 FreeBSD 和 Linux 网卡聚合实现提速 GPT 帮我搞定了时区转换问题 长任务系统如何处理? macOS/Linux 编译 InputLeap 使用开源软KVM - synergy-core 解决 macOS 终端hostname一直变化问题 KVM 共享 Intel 集成显卡 PromQL 备忘 读《格鲁夫给经理人的第一课》 读《打开心智》 为什么要把复杂的联表操作拆成多个单表查询? 红包系统的设计 MySQL Index Condition Pushdown Optimization Go mod 简明教程 OpenWRT 使用 Android/iOS USB 网络 搭建旁路由 Golang gRPC 错误处理 编写可维护的单元测试代码 OAuth 2 详解(六):Authorization Code Flow with PKCE OAuth 2 详解(五):Device Authorization Flow OAuth 2 详解(三):Resource Owner Password Credentials Grant OAuth 2 详解(四):Client Credentials Flow OAuth 2 详解(二):Implict Grant Flow OAuth 2 详解(一):简介及 Authorization Code 模式 ElasticSearch 学习笔记 三种git流程以及发版模型 错误处理实践 权限模型(RBAC/ABAC) OIDC(OpenID Connect) 简介 任务队列简介 PostgreSQL 操作笔记 使用Drone CI构建CI/CD系统 Golang migrate 做数据库变更管理 使用PostgreSQL做搜索引擎 Nginx 源码阅读(三): 连接池、内存池 Nginx 源码阅读(二): 请求处理 Nginx 源码阅读(一): 启动流程 Go 泛型简明教程 KVM 显卡穿透给 Windows 使用 HTTP Router 处理 Telegram Bot 按钮回调 使用反射(reflect)对结构体赋值 GIN 是如何绑定参数的 你好 2022(2021 年终总结) 用Go导入大型CSV到PostgreSQL 使用 OpenWRT 搭建软路由 使用软KVM切换器 barrier 共享键鼠 SQL 防注入及原理 使用 gomock 测试 Go 代码 gevent不是黑魔法(二): gevent 实现 gevent不是黑魔法(一): greenlet 实现 用 entgo 替代 gorm 应用内使用crontab不是那么方便 单测时要不要 mock 数据库? Sentry 自建指南 用selenium完成自动化任务 用闲置的安卓手机做垃圾电话短信过滤 推荐三个时间管理工具 一次事故反思 当JS遇到uint64:JS整数溢出问题 SQLite3 存储以及ACID原理 Redis源码阅读:pub/sub实现 Redis源码阅读:zset实现 Redis源码阅读:bitmap 位图的运算 Redis源码阅读:set是怎么做交并集运算的? Redis源码阅读:list实现(ziplist, quicklist)
A RC script for freebsd frpc
Jiajun Huang · 2025-03-16 · via Jiajun的技术笔记

Today I’m trying to setup a jumpserver for my local network using frpc. My jumpserver is a Linux machine before but now I decide to use FreeBSD instead.

Edit the rc script file /usr/local/etc/rc.d/frpc first:

#!/bin/sh
#
# PROVIDE: frpc
# REQUIRE: NETWORKING SERVERS
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
#
# frpc_enable (bool):        Set to YES to enable frpc
#                            Default: NO
# frpc_config (str):         Main configuration file
#                            Default: /usr/local/etc/frpc/frpc.ini
# frpc_user (str):           User to run frpc as
#                            Default: nobody
# frpc_group (str):          Group to run frpc as
#                            Default: nobody
# frpc_instances (str):      List of named instances of frpc
#                            Default: empty
# 
# For each named instance in frpc_instances, the following variables
# can be defined to override the defaults:
#
# frpc_${instance}_enable (bool):    Set to YES to enable this instance
#                                    Default: NO
# frpc_${instance}_config (str):     Configuration file for this instance
#                                    Default: /usr/local/etc/frpc/frpc_${instance}.ini
# frpc_${instance}_user (str):       User to run this instance as
#                                    Default: nobody
# frpc_${instance}_group (str):      Group to run this instance as
#                                    Default: nobody
# frpc_${instance}_flags (str):      Additional flags for this instance
#                                    Default: empty
#
# Example:
#   frpc_enable="YES"
#   frpc_instances="office home"
#   frpc_office_enable="YES"
#   frpc_office_config="/usr/local/etc/frpc/frpc_office.ini"
#   frpc_home_enable="YES"
#   frpc_home_config="/usr/local/etc/frpc/frpc_home.ini"
#

. /etc/rc.subr

name="frpc"
rcvar=frpc_enable

load_rc_config $name

: ${frpc_enable:="NO"}
: ${frpc_config:="/usr/local/etc/frpc/frpc.ini"}
: ${frpc_user:="nobody"}
: ${frpc_group:="nobody"}
: ${frpc_flags:=""}
: ${frpc_instances:=""}

command="/usr/local/bin/frpc"
piddir="/var/run/frpc"
pidfile="${piddir}/${name}.pid"

# Create pid directory if it doesn't exist
if [ ! -d ${piddir} ]; then
    mkdir -p ${piddir}
    if [ -n "${frpc_user}" ]; then
        chown ${frpc_user}:${frpc_group} ${piddir}
    fi
    chmod 755 ${piddir}
fi

start_cmd="frpc_start"
stop_cmd="frpc_stop"
status_cmd="frpc_status"
restart_cmd="frpc_restart"
configtest_cmd="frpc_configtest"
extra_commands="status restart configtest"

frpc_start()
{
    if [ -n "$1" ]; then
        _instance_start "$1"
    else
        # Start the main instance if enabled
        if checkyesno frpc_enable; then
            echo "Starting frpc."
            _instance_start ""
        fi
        
        # Start all enabled instances
        for instance in ${frpc_instances}; do
            eval frpc_instance_enable=\$frpc_${instance}_enable
            if checkyesno frpc_instance_enable; then
                echo "Starting frpc instance: ${instance}"
                _instance_start "${instance}"
            fi
        done
    fi
}

frpc_stop()
{
    if [ -n "$1" ]; then
        _instance_stop "$1"
    else
        # Stop all enabled instances
        for instance in ${frpc_instances}; do
            eval frpc_instance_enable=\$frpc_${instance}_enable
            if checkyesno frpc_instance_enable; then
                echo "Stopping frpc instance: ${instance}"
                _instance_stop "${instance}"
            fi
        done
        
        # Stop the main instance if enabled
        if checkyesno frpc_enable; then
            echo "Stopping frpc."
            _instance_stop ""
        fi
    fi
}

frpc_status()
{
    if [ -n "$1" ]; then
        _instance_status "$1"
    else
        # Check status of main instance if enabled
        if checkyesno frpc_enable; then
            _instance_status ""
        fi
        
        # Check status of all enabled instances
        for instance in ${frpc_instances}; do
            eval frpc_instance_enable=\$frpc_${instance}_enable
            if checkyesno frpc_instance_enable; then
                _instance_status "${instance}"
            fi
        done
    fi
}

frpc_restart()
{
    if [ -n "$1" ]; then
        _instance_restart "$1"
    else
        frpc_stop
        frpc_start
    fi
}

frpc_configtest()
{
    if [ -n "$1" ]; then
        _instance_configtest "$1"
    else
        # Test main instance config if enabled
        if checkyesno frpc_enable; then
            _instance_configtest ""
        fi
        
        # Test all enabled instances
        for instance in ${frpc_instances}; do
            eval frpc_instance_enable=\$frpc_${instance}_enable
            if checkyesno frpc_instance_enable; then
                _instance_configtest "${instance}"
            fi
        done
    fi
}

_instance_start()
{
    local instance="$1"
    local inst_name
    
    if [ -n "${instance}" ]; then
        inst_name="${name}_${instance}"
        eval frpc_instance_config=\$frpc_${instance}_config
        eval frpc_instance_user=\$frpc_${instance}_user
        eval frpc_instance_group=\$frpc_${instance}_group
        eval frpc_instance_flags=\$frpc_${instance}_flags
        
        : ${frpc_instance_config:="/usr/local/etc/frpc/frpc_${instance}.ini"}
        : ${frpc_instance_user:="${frpc_user}"}
        : ${frpc_instance_group:="${frpc_group}"}
        : ${frpc_instance_flags:="${frpc_flags}"}
        
        instance_pidfile="${piddir}/${inst_name}.pid"
        instance_config="${frpc_instance_config}"
        instance_user="${frpc_instance_user}"
        instance_group="${frpc_instance_group}"
        instance_flags="${frpc_instance_flags}"
    else
        inst_name="${name}"
        instance_pidfile="${pidfile}"
        instance_config="${frpc_config}"
        instance_user="${frpc_user}"
        instance_group="${frpc_group}"
        instance_flags="${frpc_flags}"
    fi
    
    if [ ! -f "${instance_config}" ]; then
        echo "Error: ${instance_config} does not exist."
        return 1
    fi
    
    echo "Starting ${inst_name}."
    /usr/sbin/daemon -f -p ${instance_pidfile} -u ${instance_user} \
        ${command} -c ${instance_config} ${instance_flags}
}

_instance_stop()
{
    local instance="$1"
    local inst_name
    
    if [ -n "${instance}" ]; then
        inst_name="${name}_${instance}"
        instance_pidfile="${piddir}/${inst_name}.pid"
    else
        inst_name="${name}"
        instance_pidfile="${pidfile}"
    fi
    
    if [ -f "${instance_pidfile}" ]; then
        echo "Stopping ${inst_name}."
        kill `cat ${instance_pidfile}` 2>/dev/null
        rm -f ${instance_pidfile}
    else
        echo "${inst_name} is not running."
    fi
}

_instance_status()
{
    local instance="$1"
    local inst_name
    
    if [ -n "${instance}" ]; then
        inst_name="${name}_${instance}"
        instance_pidfile="${piddir}/${inst_name}.pid"
    else
        inst_name="${name}"
        instance_pidfile="${pidfile}"
    fi
    
    if [ -f "${instance_pidfile}" ]; then
        pid=`cat ${instance_pidfile}`
        if ps -p ${pid} > /dev/null 2>&1; then
            echo "${inst_name} is running as pid ${pid}."
            return 0
        else
            echo "${inst_name} is not running but pidfile exists."
            return 1
        fi
    else
        echo "${inst_name} is not running."
        return 1
    fi
}

_instance_restart()
{
    local instance="$1"
    
    _instance_stop "${instance}"
    sleep 1
    _instance_start "${instance}"
}

_instance_configtest()
{
    local instance="$1"
    local inst_name
    
    if [ -n "${instance}" ]; then
        inst_name="${name}_${instance}"
        eval frpc_instance_config=\$frpc_${instance}_config
        : ${frpc_instance_config:="/usr/local/etc/frpc/frpc_${instance}.ini"}
        instance_config="${frpc_instance_config}"
    else
        inst_name="${name}"
        instance_config="${frpc_config}"
    fi
    
    if [ ! -f "${instance_config}" ]; then
        echo "Error: ${instance_config} does not exist."
        return 1
    fi
    
    echo "Testing configuration for ${inst_name}:"
    ${command} verify -c ${instance_config}
}

# Handle instance-specific commands
if [ $# -gt 0 ]; then
    # Extract instance name if command contains colon
    case "$1" in
        *:*)
            instance="${1#*:}"
            command="${1%%:*}"
            shift
            case "${command}" in
                start|stop|restart|status|configtest)
                    frpc_${command} "${instance}" $@
                    exit $?
                    ;;
                *)
                    echo "Unknown command: ${command}"
                    exit 1
                    ;;
            esac
            ;;
    esac
fi

run_rc_command "$1"

Give permission by executing chmod +x /usr/local/etc/rc.d/frpc.

Now, paste your frpc configuration in /usr/local/etc/frpc/frpc.ini, /usr/local/etc/frpc/frpc_office.ini and /usr/local/etc/frpc/frpc_home.ini(if you only have one instance, omit office and home configuration).

Enable frpc in /etc/rc.conf:

# Enable the main frpc instance
frpc_enable="YES"
frpc_config="/usr/local/etc/frpc/frpc.ini"

# Define additional instances
frpc_instances="office home"

# Configure the "office" instance
frpc_office_enable="YES"
frpc_office_config="/usr/local/etc/frpc/frpc_office.ini"

# Configure the "home" instance
frpc_home_enable="YES"
frpc_home_config="/usr/local/etc/frpc/frpc_home.ini"

And now we can using frpc by commands:

# Start all enabled instances:
service frpc start
# Start a specific instance:
service frpc start:office
# Stop a specific instance:
service frpc stop:home
# Check status of all instances:
service frpc status
# Check status of a specific instance:
service frpc status:office
# Test configuration of a specific instance:
service frpc configtest:home

相关文章