Skip to content

Commit

Permalink
feat: 支持从环境变量读取配置
Browse files Browse the repository at this point in the history
  • Loading branch information
Dream authored and Dream committed Apr 25, 2024
1 parent 862f66a commit 423d890
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 3 deletions.
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ RUN if [ ! -e /etc/nsswitch.conf ]; then echo 'hosts: files dns' > /etc/nsswitch
#
# Do not try to add the "--no-cache" option when there are multiple "apk"
# commands, this will cause the build process to become very slow.
COPY ./entrypoint /usr/local/bin/entrypoint
RUN set -ex \
&& apk upgrade \
&& apk add bash tzdata ca-certificates \
&& rm -rf /var/cache/apk/*
&& rm -rf /var/cache/apk/* \
&& chmod +x /usr/local/bin/entrypoint

COPY --from=builder /go/bin/hysteria /usr/local/bin/hysteria

ENTRYPOINT ["hysteria" , "server", "-c", "/etc/hysteria/server.yaml"]
CMD ["entrypoint"]
49 changes: 49 additions & 0 deletions entrypoint
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/sh

CONFIG_FILE="/etc/hysteria/server.yaml"

# 判断配置文件是否存存在,如果不存在走不存在的逻辑
if [ ! -f "$CONFIG_FILE" ]; then
echo "Creating configuration file $CONFIG_FILE"
mkdir -p /etc/hysteria
cat <<EOF >"$CONFIG_FILE"
apiHost: ${apiHost}
apiKey: ${apiKey}
nodeID: ${nodeID}
acme:
domains:
- ${domain}
email: [email protected]
auth:
type: v2board
trafficStats:
listen: 127.0.0.1:7653
acl:
inline:
- reject(10.0.0.0/8)
- reject(172.16.0.0/12)
- reject(192.168.0.0/16)
- reject(127.0.0.0/8)
- reject(fc00::/7)
EOF
fi

hysteria server -c $CONFIG_FILE 2>&1 | tee &

# 获取HYSTERIA server命令的进程组ID(Process Group ID)
HYSTERIA_PID=$!

# 定义一个函数来处理Ctrl+C信号
cleanup() {
echo "接收到Ctrl+C信号,正在停止HYSTERIA..."
# 向HYSTERIA进程组发送终止信号
kill -SIGINT $HYSTERIA_PID
exit 0
}

# 捕获Ctrl+C信号并调用cleanup函数
trap cleanup INT
trap cleanup SIGTERM

# 等待HYSTERIA进程结束
wait

0 comments on commit 423d890

Please sign in to comment.