fix: expose Trojan logs and build metadata
This commit is contained in:
+3
-1
@@ -1,5 +1,6 @@
|
|||||||
# syntax=docker/dockerfile:1
|
# syntax=docker/dockerfile:1
|
||||||
ARG RUNTIME_BASE=jrohy/trojan@sha256:f559fac7e9960614032e520c59405cec0e8937eca009a8169cb1d188f2b5ccb9
|
ARG RUNTIME_BASE=jrohy/trojan@sha256:f559fac7e9960614032e520c59405cec0e8937eca009a8169cb1d188f2b5ccb9
|
||||||
|
ARG MANAGER_VERSION=2.0.0
|
||||||
FROM node:20.11.1-bookworm AS frontend
|
FROM node:20.11.1-bookworm AS frontend
|
||||||
WORKDIR /src
|
WORKDIR /src
|
||||||
COPY trojan-web-master/package.json trojan-web-master/package-lock.json ./
|
COPY trojan-web-master/package.json trojan-web-master/package-lock.json ./
|
||||||
@@ -13,7 +14,8 @@ COPY trojan-master/go.mod trojan-master/go.sum ./
|
|||||||
RUN go mod download
|
RUN go mod download
|
||||||
COPY trojan-master/ ./
|
COPY trojan-master/ ./
|
||||||
COPY --from=frontend /src/dist ./web/templates
|
COPY --from=frontend /src/dist ./web/templates
|
||||||
RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags='-s -w' -o /out/trojan .
|
ARG MANAGER_VERSION
|
||||||
|
RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -ldflags="-s -w -X trojan/trojan.MVersion=${MANAGER_VERSION} -X trojan/trojan.BuildDate=compat-image -X trojan/trojan.GoVersion=go1.21.6 -X trojan/trojan.GitVersion=local-build" -o /out/trojan .
|
||||||
|
|
||||||
# Production builds pass an immutable, verified runtime snapshot that contains
|
# Production builds pass an immutable, verified runtime snapshot that contains
|
||||||
# the legacy Trojan core. This avoids a runtime download and preserves protocol
|
# the legacy Trojan core. This avoids a runtime download and preserves protocol
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ After=network.target network-online.target nss-lookup.target mysql.service maria
|
|||||||
[Service]
|
[Service]
|
||||||
Type=simple
|
Type=simple
|
||||||
StandardError=journal
|
StandardError=journal
|
||||||
ExecStart=/usr/bin/trojan/trojan /usr/local/etc/trojan/config.json
|
ExecStart=/bin/sh -c '/usr/bin/trojan/trojan /usr/local/etc/trojan/config.json >> /var/log/trojan.log 2>&1'
|
||||||
ExecReload=/bin/kill -HUP $MAINPID
|
ExecReload=/bin/kill -HUP $MAINPID
|
||||||
Restart=on-failure
|
Restart=on-failure
|
||||||
RestartSec=3s
|
RestartSec=3s
|
||||||
|
|||||||
@@ -96,7 +96,14 @@ func Log(serviceName string, line int) {
|
|||||||
|
|
||||||
// LogChan 指定服务实时日志, 返回chan
|
// LogChan 指定服务实时日志, 返回chan
|
||||||
func LogChan(serviceName, param string, closeChan chan byte) (chan string, error) {
|
func LogChan(serviceName, param string, closeChan chan byte) (chan string, error) {
|
||||||
cmd := exec.Command("bash", "-c", fmt.Sprintf("journalctl -f -u %s -o cat %s", serviceName, param))
|
logFile := fmt.Sprintf("/var/log/%s.log", serviceName)
|
||||||
|
command := fmt.Sprintf("journalctl -f -u %s -o cat %s", serviceName, param)
|
||||||
|
// docker-systemctl has no persistent journal. Compatibility images write
|
||||||
|
// service output to /var/log/<service>.log instead.
|
||||||
|
if IsExists(logFile) {
|
||||||
|
command = fmt.Sprintf("tail %s -F %s", param, logFile)
|
||||||
|
}
|
||||||
|
cmd := exec.Command("bash", "-c", command)
|
||||||
|
|
||||||
stdout, _ := cmd.StdoutPipe()
|
stdout, _ := cmd.StdoutPipe()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user