upgdate log rotation
This commit is contained in:
+6
-4
@@ -1,7 +1,7 @@
|
|||||||
FROM alpine:3.20 AS builder
|
FROM alpine:3.23 AS builder
|
||||||
|
|
||||||
RUN apk --no-cache add make binutils gcc libc-dev automake autoconf curl
|
RUN apk --no-cache add make binutils gcc libc-dev automake autoconf curl
|
||||||
RUN curl -o /usr/local/lib/go.tar.gz https://dl.google.com/go/go1.25.5.linux-amd64.tar.gz
|
RUN curl -o /usr/local/lib/go.tar.gz https://dl.google.com/go/go1.25.6.linux-amd64.tar.gz
|
||||||
RUN cd /usr/local/lib && tar xzf go.tar.gz
|
RUN cd /usr/local/lib && tar xzf go.tar.gz
|
||||||
RUN cd /usr/local/bin && ln -sf ../lib/go/bin/* .
|
RUN cd /usr/local/bin && ln -sf ../lib/go/bin/* .
|
||||||
|
|
||||||
@@ -14,11 +14,13 @@ RUN make all install
|
|||||||
RUN make clean
|
RUN make clean
|
||||||
RUN rm -rf /app/src
|
RUN rm -rf /app/src
|
||||||
|
|
||||||
FROM alpine:3.20 AS runner
|
FROM alpine:3.23 AS runner
|
||||||
|
|
||||||
COPY --from=builder /app /app
|
COPY --from=builder /app /app
|
||||||
RUN chmod 1777 /var
|
RUN chmod 1777 /var
|
||||||
|
RUN mkdir -p /app/etc/mstore
|
||||||
|
RUN touch /app/etc/mstore/mstored.yaml
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
|
|
||||||
#USER daemon:daemon
|
#USER daemon:daemon
|
||||||
ENTRYPOINT ["/app/sbin/mstored"]
|
ENTRYPOINT ["/app/sbin/mstored", "--asDaemon=false", "--port=1025"]
|
||||||
|
|||||||
@@ -282,9 +282,6 @@ EXTRA_DIST = vendor/* \
|
|||||||
docs/mstore.png \
|
docs/mstore.png \
|
||||||
docs/podman-manifest.json.txt
|
docs/podman-manifest.json.txt
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
format:
|
format:
|
||||||
@dirs=$$($(FIND) $(CWD)/app $(CWD)/cmd $(CWD)/pkg $(CWD)/test \
|
@dirs=$$($(FIND) $(CWD)/app $(CWD)/cmd $(CWD)/pkg $(CWD)/test \
|
||||||
-name '*.go' | $(XARGS) -n1 dirname | $(SORT) | $(UNIQ)); \
|
-name '*.go' | $(XARGS) -n1 dirname | $(SORT) | $(UNIQ)); \
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
package config
|
package config
|
||||||
|
|
||||||
const (
|
const (
|
||||||
confdir = "/usr/local/etc/mstore"
|
confdir = "/etc/mstore"
|
||||||
rundir = "/var/run/mstore"
|
rundir = "/var/run/mstore"
|
||||||
logdir = "/var/log/mstore"
|
logdir = "/var/log/mstore"
|
||||||
datadir = "/var/lib/mstore"
|
datadir = "/var/lib/mstore"
|
||||||
version = "0.2.0"
|
version = "0.2.3"
|
||||||
srvname = "mstored"
|
srvname = "mstored"
|
||||||
)
|
)
|
||||||
|
|||||||
+52
-20
@@ -12,12 +12,14 @@ package server
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"os/user"
|
"os/user"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"sync"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -48,6 +50,10 @@ type Server struct {
|
|||||||
logg *logger.Logger
|
logg *logger.Logger
|
||||||
stor *storage.Storage
|
stor *storage.Storage
|
||||||
stat descr.Server
|
stat descr.Server
|
||||||
|
ctx context.Context
|
||||||
|
cancel context.CancelFunc
|
||||||
|
wg sync.WaitGroup
|
||||||
|
logf *os.File
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewServer() (*Server, error) {
|
func NewServer() (*Server, error) {
|
||||||
@@ -97,7 +103,7 @@ func (srv *Server) Configure() error {
|
|||||||
err = srv.conf.ReadConfigfile()
|
err = srv.conf.ReadConfigfile()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
srv.logg.Warningf("Error loading config file: %v", err)
|
srv.logg.Warningf("Error loading config file: %v", err)
|
||||||
//return err
|
err = nil
|
||||||
}
|
}
|
||||||
err = srv.conf.ReadX509Cert()
|
err = srv.conf.ReadX509Cert()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -327,6 +333,7 @@ func (srv *Server) Run() error {
|
|||||||
}
|
}
|
||||||
srv.logg.Infof("Server run as user %s", currUser.Username)
|
srv.logg.Infof("Server run as user %s", currUser.Username)
|
||||||
|
|
||||||
|
srv.ctx, srv.cancel = context.WithCancel(context.Background())
|
||||||
svcDone := make(chan error, 1)
|
svcDone := make(chan error, 1)
|
||||||
|
|
||||||
// Service run
|
// Service run
|
||||||
@@ -341,17 +348,20 @@ func (srv *Server) Run() error {
|
|||||||
go startService(srv.svc, svcDone)
|
go startService(srv.svc, svcDone)
|
||||||
|
|
||||||
sigs := make(chan os.Signal, 1)
|
sigs := make(chan os.Signal, 1)
|
||||||
|
|
||||||
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
|
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
|
||||||
var signal os.Signal
|
var signal os.Signal
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case signal = <-sigs:
|
case signal = <-sigs:
|
||||||
srv.logg.Infof("Services stopped by signal: %v", signal)
|
srv.logg.Infof("Services stopped by signal: %v", signal)
|
||||||
|
srv.cancel()
|
||||||
srv.svc.Stop()
|
srv.svc.Stop()
|
||||||
|
srv.wg.Wait()
|
||||||
case err = <-svcDone:
|
case err = <-svcDone:
|
||||||
srv.logg.Infof("Service stopped by service error: %v", err)
|
srv.logg.Infof("Service stopped by service error: %v", err)
|
||||||
|
srv.cancel()
|
||||||
srv.svc.Stop()
|
srv.svc.Stop()
|
||||||
|
srv.wg.Wait()
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -431,24 +441,7 @@ func (srv *Server) Daemonize() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Log file rotator
|
srv.logf = logFile
|
||||||
logFunc := func() {
|
|
||||||
for {
|
|
||||||
stat, err := os.Stat(srv.conf.Logpath)
|
|
||||||
if err == nil && stat.Size() > srv.conf.LogLimit {
|
|
||||||
os.Rename(srv.conf.Logpath+".2", srv.conf.Logpath+".3")
|
|
||||||
os.Rename(srv.conf.Logpath+".1", srv.conf.Logpath+".2")
|
|
||||||
os.Rename(srv.conf.Logpath, srv.conf.Logpath+".1")
|
|
||||||
logFile.Close()
|
|
||||||
logFile, err = os.OpenFile(srv.conf.Logpath, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0640)
|
|
||||||
syscall.Dup2(int(logFile.Fd()), int(os.Stdout.Fd()))
|
|
||||||
syscall.Dup2(int(logFile.Fd()), int(os.Stderr.Fd()))
|
|
||||||
time.Sleep(10 * time.Second)
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
go logFunc()
|
|
||||||
// Write process ID
|
// Write process ID
|
||||||
rundir := filepath.Dir(srv.conf.Runpath)
|
rundir := filepath.Dir(srv.conf.Runpath)
|
||||||
err = os.MkdirAll(rundir, 0750)
|
err = os.MkdirAll(rundir, 0750)
|
||||||
@@ -468,3 +461,42 @@ func (srv *Server) Daemonize() error {
|
|||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (srv *Server) Rotator() {
|
||||||
|
srv.wg.Add(1)
|
||||||
|
var counter uint64
|
||||||
|
logFunc := func() {
|
||||||
|
for {
|
||||||
|
counter += 1
|
||||||
|
select {
|
||||||
|
case <-srv.ctx.Done():
|
||||||
|
srv.wg.Done()
|
||||||
|
srv.logg.Infof("Log file rotator done")
|
||||||
|
return
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
if (counter % 60) == 1 {
|
||||||
|
stat, err := srv.logf.Stat()
|
||||||
|
if err == nil && stat.Size() > srv.conf.LogLimit {
|
||||||
|
srv.logg.Infof("Rotate log file")
|
||||||
|
countFiles := 3
|
||||||
|
for i := 1; i < countFiles; i++ {
|
||||||
|
nextName := fmt.Sprintf("%s.%d", srv.conf.Logpath, i+1)
|
||||||
|
prevName := fmt.Sprintf("%s.%d", srv.conf.Logpath, i)
|
||||||
|
os.Rename(prevName, nextName)
|
||||||
|
}
|
||||||
|
os.Rename(srv.conf.Logpath, srv.conf.Logpath+".1")
|
||||||
|
logFile, err := os.OpenFile(srv.conf.Logpath, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0640)
|
||||||
|
if err == nil {
|
||||||
|
syscall.Dup2(int(logFile.Fd()), int(os.Stdout.Fd()))
|
||||||
|
syscall.Dup2(int(logFile.Fd()), int(os.Stderr.Fd()))
|
||||||
|
srv.logf.Close()
|
||||||
|
srv.logf = logFile
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
time.Sleep(1 * time.Second)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
go logFunc()
|
||||||
|
}
|
||||||
|
|||||||
@@ -26,12 +26,12 @@ spec:
|
|||||||
volumeMounts:
|
volumeMounts:
|
||||||
- name: config-volume
|
- name: config-volume
|
||||||
mountPath: /app/etc/mstore
|
mountPath: /app/etc/mstore
|
||||||
- name: db-volume
|
# - name: db-volume
|
||||||
mountPath: /var/lib
|
# mountPath: /var/lib
|
||||||
volumes:
|
volumes:
|
||||||
- name: config-volume
|
- name: config-volume
|
||||||
configMap:
|
configMap:
|
||||||
name: mstored-config
|
name: mstored-config
|
||||||
- name: db-volume
|
# - name: db-volume
|
||||||
persistentVolumeClaim:
|
# persistentVolumeClaim:
|
||||||
claimName: mstore-data
|
# claimName: mstore-data
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
kind: PersistentVolumeClaim
|
|
||||||
apiVersion: v1
|
|
||||||
metadata:
|
|
||||||
name: mstore-data
|
|
||||||
spec:
|
|
||||||
storageClassName: {{ include "mstore.storageClass" . }}
|
|
||||||
accessModes:
|
|
||||||
- ReadWriteOnce
|
|
||||||
volumeMode: Filesystem
|
|
||||||
resources:
|
|
||||||
requests:
|
|
||||||
storage: {{ include "mstore.storageSize" . }}
|
|
||||||
@@ -67,6 +67,7 @@ func (sta *Starter) run(cmd *cobra.Command, args []string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
srv.Rotator()
|
||||||
err = srv.Run()
|
err = srv.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
#! /bin/sh
|
#! /bin/sh
|
||||||
# Guess values for system-dependent variables and create Makefiles.
|
# Guess values for system-dependent variables and create Makefiles.
|
||||||
# Generated by GNU Autoconf 2.72 for mstore 0.2.0.
|
# Generated by GNU Autoconf 2.72 for mstore 0.2.3.
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# Copyright (C) 1992-1996, 1998-2017, 2020-2023 Free Software Foundation,
|
# Copyright (C) 1992-1996, 1998-2017, 2020-2023 Free Software Foundation,
|
||||||
@@ -600,8 +600,8 @@ MAKEFLAGS=
|
|||||||
# Identity of this package.
|
# Identity of this package.
|
||||||
PACKAGE_NAME='mstore'
|
PACKAGE_NAME='mstore'
|
||||||
PACKAGE_TARNAME='mstore'
|
PACKAGE_TARNAME='mstore'
|
||||||
PACKAGE_VERSION='0.2.0'
|
PACKAGE_VERSION='0.2.3'
|
||||||
PACKAGE_STRING='mstore 0.2.0'
|
PACKAGE_STRING='mstore 0.2.3'
|
||||||
PACKAGE_BUGREPORT=''
|
PACKAGE_BUGREPORT=''
|
||||||
PACKAGE_URL=''
|
PACKAGE_URL=''
|
||||||
|
|
||||||
@@ -1278,7 +1278,7 @@ if test "$ac_init_help" = "long"; then
|
|||||||
# Omit some internal or obsolete options to make the list less imposing.
|
# Omit some internal or obsolete options to make the list less imposing.
|
||||||
# This message is too long to be a string in the A/UX 3.1 sh.
|
# This message is too long to be a string in the A/UX 3.1 sh.
|
||||||
cat <<_ACEOF
|
cat <<_ACEOF
|
||||||
'configure' configures mstore 0.2.0 to adapt to many kinds of systems.
|
'configure' configures mstore 0.2.3 to adapt to many kinds of systems.
|
||||||
|
|
||||||
Usage: $0 [OPTION]... [VAR=VALUE]...
|
Usage: $0 [OPTION]... [VAR=VALUE]...
|
||||||
|
|
||||||
@@ -1349,7 +1349,7 @@ fi
|
|||||||
|
|
||||||
if test -n "$ac_init_help"; then
|
if test -n "$ac_init_help"; then
|
||||||
case $ac_init_help in
|
case $ac_init_help in
|
||||||
short | recursive ) echo "Configuration of mstore 0.2.0:";;
|
short | recursive ) echo "Configuration of mstore 0.2.3:";;
|
||||||
esac
|
esac
|
||||||
cat <<\_ACEOF
|
cat <<\_ACEOF
|
||||||
|
|
||||||
@@ -1436,7 +1436,7 @@ fi
|
|||||||
test -n "$ac_init_help" && exit $ac_status
|
test -n "$ac_init_help" && exit $ac_status
|
||||||
if $ac_init_version; then
|
if $ac_init_version; then
|
||||||
cat <<\_ACEOF
|
cat <<\_ACEOF
|
||||||
mstore configure 0.2.0
|
mstore configure 0.2.3
|
||||||
generated by GNU Autoconf 2.72
|
generated by GNU Autoconf 2.72
|
||||||
|
|
||||||
Copyright (C) 2023 Free Software Foundation, Inc.
|
Copyright (C) 2023 Free Software Foundation, Inc.
|
||||||
@@ -1473,7 +1473,7 @@ cat >config.log <<_ACEOF
|
|||||||
This file contains any messages produced by compilers while
|
This file contains any messages produced by compilers while
|
||||||
running configure, to aid debugging if configure makes a mistake.
|
running configure, to aid debugging if configure makes a mistake.
|
||||||
|
|
||||||
It was created by mstore $as_me 0.2.0, which was
|
It was created by mstore $as_me 0.2.3, which was
|
||||||
generated by GNU Autoconf 2.72. Invocation command line was
|
generated by GNU Autoconf 2.72. Invocation command line was
|
||||||
|
|
||||||
$ $0$ac_configure_args_raw
|
$ $0$ac_configure_args_raw
|
||||||
@@ -2612,7 +2612,7 @@ fi
|
|||||||
|
|
||||||
# Define the identity of the package.
|
# Define the identity of the package.
|
||||||
PACKAGE='mstore'
|
PACKAGE='mstore'
|
||||||
VERSION='0.2.0'
|
VERSION='0.2.3'
|
||||||
|
|
||||||
|
|
||||||
printf "%s\n" "#define PACKAGE \"$PACKAGE\"" >>confdefs.h
|
printf "%s\n" "#define PACKAGE \"$PACKAGE\"" >>confdefs.h
|
||||||
@@ -4448,7 +4448,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
|
|||||||
# report actual input values of CONFIG_FILES etc. instead of their
|
# report actual input values of CONFIG_FILES etc. instead of their
|
||||||
# values after options handling.
|
# values after options handling.
|
||||||
ac_log="
|
ac_log="
|
||||||
This file was extended by mstore $as_me 0.2.0, which was
|
This file was extended by mstore $as_me 0.2.3, which was
|
||||||
generated by GNU Autoconf 2.72. Invocation command line was
|
generated by GNU Autoconf 2.72. Invocation command line was
|
||||||
|
|
||||||
CONFIG_FILES = $CONFIG_FILES
|
CONFIG_FILES = $CONFIG_FILES
|
||||||
@@ -4503,7 +4503,7 @@ ac_cs_config_escaped=`printf "%s\n" "$ac_cs_config" | sed "s/^ //; s/'/'\\\\\\\\
|
|||||||
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
|
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
|
||||||
ac_cs_config='$ac_cs_config_escaped'
|
ac_cs_config='$ac_cs_config_escaped'
|
||||||
ac_cs_version="\\
|
ac_cs_version="\\
|
||||||
mstore config.status 0.2.0
|
mstore config.status 0.2.3
|
||||||
configured by $0, generated by GNU Autoconf 2.72,
|
configured by $0, generated by GNU Autoconf 2.72,
|
||||||
with options \\"\$ac_cs_config\\"
|
with options \\"\$ac_cs_config\\"
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
AC_INIT([mstore],[0.2.0])
|
AC_INIT([mstore],[0.2.4])
|
||||||
AM_INIT_AUTOMAKE([foreign subdir-objects tar-pax])
|
AM_INIT_AUTOMAKE([foreign subdir-objects tar-pax])
|
||||||
AC_PREFIX_DEFAULT(/usr/local)
|
AC_PREFIX_DEFAULT(/usr/local)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user