From 5c93f88495dee6c5c5042e144d5b9aa976c96a78 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Mon, 24 Jun 2024 13:36:31 +0300 Subject: [PATCH] Code refactoring --- common/updown-badge-server.knf | 4 ++-- common/updown-badge-server.service | 13 ++++++++----- common/updown-badge-server.spec | 14 ++++++++++---- daemon/daemon.go | 15 +++++++-------- 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/common/updown-badge-server.knf b/common/updown-badge-server.knf index 369fe82..2cc86da 100644 --- a/common/updown-badge-server.knf +++ b/common/updown-badge-server.knf @@ -42,8 +42,8 @@ # Path to log file file: {log:dir}/updown-badge-server.log - # Log permissions - perms: 600 + # Log file mode + mode: 0600 # Default log level (debug/info/warn/error/crit) level: info diff --git a/common/updown-badge-server.service b/common/updown-badge-server.service index e7abe8a..3e1d51f 100644 --- a/common/updown-badge-server.service +++ b/common/updown-badge-server.service @@ -5,11 +5,14 @@ Requires=network.target remote-fs.target After=network.target remote-fs.target [Service] -User=updownbs -ExecStart=/usr/bin/updown-badge-server -ExecReload=kill -HUP $MAINPID -StandardError=syslog -SyslogIdentifier=updown-badge-server +Type=simple +User=updown +EnvironmentFile=/etc/sysconfig/updown-badge-server +ExecStart=/usr/bin/updown-badge-server -c /etc/updown-badge-server.knf +ExecReload=/bin/kill -s HUP $MAINPID +ExecStop=/bin/kill -s TERM $MAINPID +StandardError=file:/var/log/updown-badge-server/startup.log +PrivateTmp=true [Install] WantedBy=multi-user.target diff --git a/common/updown-badge-server.spec b/common/updown-badge-server.spec index ad4f9b0..c18d30f 100644 --- a/common/updown-badge-server.spec +++ b/common/updown-badge-server.spec @@ -14,7 +14,7 @@ Summary: Service for generating badges for updown.io checks Name: updown-badge-server -Version: 1.3.1 +Version: 1.3.2 Release: 0%{?dist} Group: Applications/System License: Apache License, Version 2.0 @@ -43,13 +43,15 @@ Service for generating badges for updown.io checks. %{crc_check} %setup -q - -%build if [[ ! -d "%{name}/vendor" ]] ; then - echo "This package requires vendored dependencies" + echo -e "----\nThis package requires vendored dependencies\n----" + exit 1 +elif [[ -f "%{name}/%{name}" ]] ; then + echo -e "----\nSources must not contain precompiled binaries\n----" exit 1 fi +%build pushd %{name} go build %{name}.go cp LICENSE .. @@ -98,6 +100,10 @@ exit 0 ################################################################################ %changelog +* Mon Jun 24 2024 Anton Novojilov - 1.3.2-0 +- Code refactoring +- Dependencies update + * Sat Mar 30 2024 Anton Novojilov - 1.3.1-0 - Improved support information gathering - Code refactoring diff --git a/daemon/daemon.go b/daemon/daemon.go index 4478424..90b3c4c 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -21,6 +21,7 @@ import ( "github.com/essentialkaos/ek/v12/signal" "github.com/essentialkaos/ek/v12/support" "github.com/essentialkaos/ek/v12/support/deps" + "github.com/essentialkaos/ek/v12/terminal" "github.com/essentialkaos/ek/v12/terminal/tty" "github.com/essentialkaos/ek/v12/usage" @@ -41,7 +42,7 @@ import ( // Basic service info const ( APP = "UpDownBadgeServer" - VER = "1.3.1" + VER = "1.3.2" DESC = "Service for generating badges for updown.io checks" ) @@ -78,7 +79,7 @@ const ( SERVER_REDIRECT = "server:redirect" LOG_DIR = "log:dir" LOG_FILE = "log:file" - LOG_PERMS = "log:perms" + LOG_MODE = "log:mode" LOG_LEVEL = "log:level" ) @@ -109,11 +110,9 @@ func Run(gomod []byte) { _, errs := options.Parse(optMap) - if len(errs) != 0 { - for _, err := range errs { - log.Crit(err.Error()) - } - + if !errs.IsEmpty() { + terminal.Error("Options parsing errors:") + terminal.Error(errs.String()) os.Exit(1) } @@ -236,7 +235,7 @@ func registerSignalHandlers() { // setupLogger configures logger subsystems func setupLogger() { - err := log.Set(knf.GetS(LOG_FILE), knf.GetM(LOG_PERMS, 0644)) + err := log.Set(knf.GetS(LOG_FILE), knf.GetM(LOG_MODE, 0644)) if err != nil { log.Crit(err.Error())