diff --git a/Makefile.in b/Makefile.in index fa64b86..b9d0b75 100644 --- a/Makefile.in +++ b/Makefile.in @@ -102,7 +102,7 @@ DIST_COMMON = $(srcdir)/Makefile.am $(top_srcdir)/configure \ am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \ configure.lineno config.status.lineno 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 CONFIG_CLEAN_VPATH_FILES = am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(sbindir)" @@ -173,7 +173,7 @@ am__define_uniq_tagged_files = \ done | $(am__uniquify_input)` AM_RECURSIVE_TARGETS = cscope 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/control.in \ $(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) $(am__cd) $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS) $(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 $@ initrc/minilbd.service: $(top_builddir)/config.status $(top_srcdir)/initrc/minilbd.service.in cd $(top_builddir) && $(SHELL) ./config.status $@ diff --git a/app/config/config.go b/app/config/config.go index a101499..77cd051 100644 --- a/app/config/config.go +++ b/app/config/config.go @@ -35,6 +35,8 @@ type Config struct { LogPath string `json:"logfile" yaml:"logfile"` RunPath string `json:"runfile" yaml:"runfile"` AsDaemon bool `json:"asDaemon" yaml:"asDaemon"` + LogLimit int64 `json:"logLimit" yaml:logLimit` + } func NewConfig() (*Config, error) { @@ -43,6 +45,7 @@ func NewConfig() (*Config, error) { Port: client.DefaultServicePort, }, AsDaemon: false, + LogLimit: 1024 * 1024 * 10, // 10 Mb } hostname, err := os.Hostname() if err != nil { diff --git a/app/config/variant.go b/app/config/variant.go new file mode 100644 index 0000000..2325339 --- /dev/null +++ b/app/config/variant.go @@ -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" +) + diff --git a/app/config/path.go.in b/app/config/variant.go.in similarity index 100% rename from app/config/path.go.in rename to app/config/variant.go.in diff --git a/app/server/server.go b/app/server/server.go index 69f1a4d..0e9a797 100644 --- a/app/server/server.go +++ b/app/server/server.go @@ -3,11 +3,11 @@ package server import ( "os" "os/signal" - "syscall" - "os/user" "path/filepath" "strconv" + "syscall" + "time" "helmet/app/config" "helmet/app/handler" @@ -88,13 +88,13 @@ func (srv *Server) Build() error { if err != nil { return err } - // Create ghandler + // Create handler handlerConfig := &handler.HandlerConfig{ Operator: srv.oper, } srv.hand = handler.NewHandler(handlerConfig) - // Create gservice + // Create service serviceConfig := &service.ServiceConfig{ PortNum: srv.conf.Service.Port, Hostname: srv.conf.Hostname, @@ -220,6 +220,27 @@ func (srv *Server) Daemonize() error { if err != nil { 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 rundir := filepath.Dir(srv.conf.RunPath) err = os.MkdirAll(rundir, 0750) diff --git a/configure b/configure index 9468f8a..7304b21 100755 --- a/configure +++ b/configure @@ -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 # 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 case $ac_config_target in "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" ;; "debian/control") CONFIG_FILES="$CONFIG_FILES debian/control" ;; "debian/changelog") CONFIG_FILES="$CONFIG_FILES debian/changelog" ;; diff --git a/configure.ac b/configure.ac index ee294c9..fa35e77 100644 --- a/configure.ac +++ b/configure.ac @@ -243,7 +243,7 @@ dnl ---------------------------------------------------------------------------- AC_CONFIG_FILES([ Makefile -app/config/path.go +app/config/variant.go initrc/minilbd.service debian/control debian/changelog