added simple log rotator
This commit is contained in:
+3
-3
@@ -102,7 +102,7 @@ DIST_COMMON = $(srcdir)/Makefile.am $(top_srcdir)/configure \
|
|||||||
am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \
|
am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \
|
||||||
configure.lineno config.status.lineno
|
configure.lineno config.status.lineno
|
||||||
mkinstalldirs = $(install_sh) -d
|
mkinstalldirs = $(install_sh) -d
|
||||||
CONFIG_CLEAN_FILES = app/config/path.go initrc/minilbd.service \
|
CONFIG_CLEAN_FILES = app/config/variant.go initrc/minilbd.service \
|
||||||
debian/control debian/changelog
|
debian/control debian/changelog
|
||||||
CONFIG_CLEAN_VPATH_FILES =
|
CONFIG_CLEAN_VPATH_FILES =
|
||||||
am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(sbindir)"
|
am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(sbindir)"
|
||||||
@@ -173,7 +173,7 @@ am__define_uniq_tagged_files = \
|
|||||||
done | $(am__uniquify_input)`
|
done | $(am__uniquify_input)`
|
||||||
AM_RECURSIVE_TARGETS = cscope
|
AM_RECURSIVE_TARGETS = cscope
|
||||||
am__DIST_COMMON = $(srcdir)/Makefile.in \
|
am__DIST_COMMON = $(srcdir)/Makefile.in \
|
||||||
$(top_srcdir)/app/config/path.go.in \
|
$(top_srcdir)/app/config/variant.go.in \
|
||||||
$(top_srcdir)/debian/changelog.in \
|
$(top_srcdir)/debian/changelog.in \
|
||||||
$(top_srcdir)/debian/control.in \
|
$(top_srcdir)/debian/control.in \
|
||||||
$(top_srcdir)/initrc/minilbd.service.in README.md config.guess \
|
$(top_srcdir)/initrc/minilbd.service.in README.md config.guess \
|
||||||
@@ -405,7 +405,7 @@ $(top_srcdir)/configure: $(am__configure_deps)
|
|||||||
$(ACLOCAL_M4): $(am__aclocal_m4_deps)
|
$(ACLOCAL_M4): $(am__aclocal_m4_deps)
|
||||||
$(am__cd) $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS)
|
$(am__cd) $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS)
|
||||||
$(am__aclocal_m4_deps):
|
$(am__aclocal_m4_deps):
|
||||||
app/config/path.go: $(top_builddir)/config.status $(top_srcdir)/app/config/path.go.in
|
app/config/variant.go: $(top_builddir)/config.status $(top_srcdir)/app/config/variant.go.in
|
||||||
cd $(top_builddir) && $(SHELL) ./config.status $@
|
cd $(top_builddir) && $(SHELL) ./config.status $@
|
||||||
initrc/minilbd.service: $(top_builddir)/config.status $(top_srcdir)/initrc/minilbd.service.in
|
initrc/minilbd.service: $(top_builddir)/config.status $(top_srcdir)/initrc/minilbd.service.in
|
||||||
cd $(top_builddir) && $(SHELL) ./config.status $@
|
cd $(top_builddir) && $(SHELL) ./config.status $@
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ type Config struct {
|
|||||||
LogPath string `json:"logfile" yaml:"logfile"`
|
LogPath string `json:"logfile" yaml:"logfile"`
|
||||||
RunPath string `json:"runfile" yaml:"runfile"`
|
RunPath string `json:"runfile" yaml:"runfile"`
|
||||||
AsDaemon bool `json:"asDaemon" yaml:"asDaemon"`
|
AsDaemon bool `json:"asDaemon" yaml:"asDaemon"`
|
||||||
|
LogLimit int64 `json:"logLimit" yaml:logLimit`
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewConfig() (*Config, error) {
|
func NewConfig() (*Config, error) {
|
||||||
@@ -43,6 +45,7 @@ func NewConfig() (*Config, error) {
|
|||||||
Port: client.DefaultServicePort,
|
Port: client.DefaultServicePort,
|
||||||
},
|
},
|
||||||
AsDaemon: false,
|
AsDaemon: false,
|
||||||
|
LogLimit: 1024 * 1024 * 10, // 10 Mb
|
||||||
}
|
}
|
||||||
hostname, err := os.Hostname()
|
hostname, err := os.Hostname()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package config
|
||||||
|
|
||||||
|
const (
|
||||||
|
confdirPath = "/home/ziggi/Projects/sys2agent/etc/minilb"
|
||||||
|
rundirPath = "/home/ziggi/Projects/sys2agent/tmp/run"
|
||||||
|
logdirPath = "/home/ziggi/Projects/sys2agent/tmp/log"
|
||||||
|
datadirPath = "/home/ziggi/Projects/sys2agent/tmp/data"
|
||||||
|
packageVersion = "0.0.1"
|
||||||
|
)
|
||||||
|
|
||||||
+25
-4
@@ -3,11 +3,11 @@ package server
|
|||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"syscall"
|
|
||||||
|
|
||||||
"os/user"
|
"os/user"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
|
||||||
"helmet/app/config"
|
"helmet/app/config"
|
||||||
"helmet/app/handler"
|
"helmet/app/handler"
|
||||||
@@ -88,13 +88,13 @@ func (srv *Server) Build() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
// Create ghandler
|
// Create handler
|
||||||
handlerConfig := &handler.HandlerConfig{
|
handlerConfig := &handler.HandlerConfig{
|
||||||
Operator: srv.oper,
|
Operator: srv.oper,
|
||||||
}
|
}
|
||||||
srv.hand = handler.NewHandler(handlerConfig)
|
srv.hand = handler.NewHandler(handlerConfig)
|
||||||
|
|
||||||
// Create gservice
|
// Create service
|
||||||
serviceConfig := &service.ServiceConfig{
|
serviceConfig := &service.ServiceConfig{
|
||||||
PortNum: srv.conf.Service.Port,
|
PortNum: srv.conf.Service.Port,
|
||||||
Hostname: srv.conf.Hostname,
|
Hostname: srv.conf.Hostname,
|
||||||
@@ -220,6 +220,27 @@ func (srv *Server) Daemonize() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
// Log file rotator
|
||||||
|
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")
|
||||||
|
prevLogFile := logFile
|
||||||
|
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()))
|
||||||
|
prevLogFile.Close()
|
||||||
|
}
|
||||||
|
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)
|
||||||
|
|||||||
@@ -3864,7 +3864,7 @@ printf "%s\n" "$as_me: srv_datadir set as ${SRV_DATADIR}" >&6;}
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
ac_config_files="$ac_config_files Makefile app/config/path.go initrc/minilbd.service debian/control debian/changelog"
|
ac_config_files="$ac_config_files Makefile app/config/variant.go initrc/minilbd.service debian/control debian/changelog"
|
||||||
|
|
||||||
cat >confcache <<\_ACEOF
|
cat >confcache <<\_ACEOF
|
||||||
# This file is a shell script that caches the results of configure
|
# This file is a shell script that caches the results of configure
|
||||||
@@ -4616,7 +4616,7 @@ for ac_config_target in $ac_config_targets
|
|||||||
do
|
do
|
||||||
case $ac_config_target in
|
case $ac_config_target in
|
||||||
"Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
|
"Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
|
||||||
"app/config/path.go") CONFIG_FILES="$CONFIG_FILES app/config/path.go" ;;
|
"app/config/variant.go") CONFIG_FILES="$CONFIG_FILES app/config/variant.go" ;;
|
||||||
"initrc/minilbd.service") CONFIG_FILES="$CONFIG_FILES initrc/minilbd.service" ;;
|
"initrc/minilbd.service") CONFIG_FILES="$CONFIG_FILES initrc/minilbd.service" ;;
|
||||||
"debian/control") CONFIG_FILES="$CONFIG_FILES debian/control" ;;
|
"debian/control") CONFIG_FILES="$CONFIG_FILES debian/control" ;;
|
||||||
"debian/changelog") CONFIG_FILES="$CONFIG_FILES debian/changelog" ;;
|
"debian/changelog") CONFIG_FILES="$CONFIG_FILES debian/changelog" ;;
|
||||||
|
|||||||
+1
-1
@@ -243,7 +243,7 @@ dnl ----------------------------------------------------------------------------
|
|||||||
|
|
||||||
AC_CONFIG_FILES([
|
AC_CONFIG_FILES([
|
||||||
Makefile
|
Makefile
|
||||||
app/config/path.go
|
app/config/variant.go
|
||||||
initrc/minilbd.service
|
initrc/minilbd.service
|
||||||
debian/control
|
debian/control
|
||||||
debian/changelog
|
debian/changelog
|
||||||
|
|||||||
Reference in New Issue
Block a user