From 8f34f6fa952bbb249e12c2cab4a15a15250bf858 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=95=D0=B2=D0=B3=D0=B5=D0=BD=D0=B8=D0=B9=20=D0=AE=D0=B4?= =?UTF-8?q?=D0=B0=D0=BA=D0=BE=D0=B2?= Date: Wed, 9 Sep 2020 14:06:35 +0300 Subject: [PATCH] feat: log cmd group --- SOURCES/Makefile | 3 ++ SOURCES/main/cmdgrp/log/cat | 47 +++++++++++++++++++ SOURCES/main/cmdgrp/log/tail | 47 +++++++++++++++++++ SOURCES/main/lib/log.lib | 75 +++++++++++++++++++++++++++++++ SOURCES/main/rsyslog/kf2-srv.conf | 5 ++- SPECS/kf2-srv.spec | 5 ++- 6 files changed, 180 insertions(+), 2 deletions(-) create mode 100644 SOURCES/main/cmdgrp/log/cat create mode 100644 SOURCES/main/cmdgrp/log/tail create mode 100644 SOURCES/main/lib/log.lib diff --git a/SOURCES/Makefile b/SOURCES/Makefile index 897b1d8..1549fa0 100644 --- a/SOURCES/Makefile +++ b/SOURCES/Makefile @@ -196,6 +196,8 @@ test: fake-systemd-build $(BASHCHECK) $(RELEASEDIR)/main/cmdgrp/workshop/add $(BASHCHECK) $(RELEASEDIR)/main/cmdgrp/workshop/delete $(BASHCHECK) $(RELEASEDIR)/main/cmdgrp/workshop/sync + $(BASHCHECK) $(RELEASEDIR)/main/cmdgrp/log/cat + $(BASHCHECK) $(RELEASEDIR)/main/cmdgrp/log/tail $(BASHCHECK) $(RELEASEDIR)/main/lib/ban.lib $(BASHCHECK) $(RELEASEDIR)/main/lib/game.lib @@ -205,6 +207,7 @@ test: fake-systemd-build $(BASHCHECK) $(RELEASEDIR)/main/lib/playerids.lib $(BASHCHECK) $(RELEASEDIR)/main/lib/webadmin.lib $(BASHCHECK) $(RELEASEDIR)/main/lib/workshop.lib + $(BASHCHECK) $(RELEASEDIR)/main/lib/log.lib $(BASHCHECK) $(RELEASEDIR)/main/bash_completion/$(NAME) diff --git a/SOURCES/main/cmdgrp/log/cat b/SOURCES/main/cmdgrp/log/cat new file mode 100644 index 0000000..f6cbc6e --- /dev/null +++ b/SOURCES/main/cmdgrp/log/cat @@ -0,0 +1,47 @@ +#!/bin/bash + +# kf2-srv is a command line tool for managing a set of Killing Floor 2 servers. +# Copyright (C) 2019, 2020 GenZmeY +# mailto: genzmey@gmail.com +# +# This file is part of kf2-srv. +# +# kf2-srv is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +cmd_need_superuser () { false ;} +cmd_need_steamuser () { false ;} +cmd_need_installed_server () { true ;} + +function cmd_usage () +{ + echo "[...]" +} + +function cmd_info () +{ + echo "Print in stdout full log of specified server instance(s)" +} + +function cmd_help () +{ + echo "TODO: description" +} + +function cmd_main () +{ + include "$LibDir/log.lib" + + log_cat "$@" +} + diff --git a/SOURCES/main/cmdgrp/log/tail b/SOURCES/main/cmdgrp/log/tail new file mode 100644 index 0000000..c6c9194 --- /dev/null +++ b/SOURCES/main/cmdgrp/log/tail @@ -0,0 +1,47 @@ +#!/bin/bash + +# kf2-srv is a command line tool for managing a set of Killing Floor 2 servers. +# Copyright (C) 2019, 2020 GenZmeY +# mailto: genzmey@gmail.com +# +# This file is part of kf2-srv. +# +# kf2-srv is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +cmd_need_superuser () { false ;} +cmd_need_steamuser () { false ;} +cmd_need_installed_server () { true ;} + +function cmd_usage () +{ + echo "[...]" +} + +function cmd_info () +{ + echo "Print in stdout tail log of specified server instance(s) in real time" +} + +function cmd_help () +{ + echo "TODO: description" +} + +function cmd_main () +{ + include "$LibDir/log.lib" + + log_tail "$@" +} + diff --git a/SOURCES/main/lib/log.lib b/SOURCES/main/lib/log.lib new file mode 100644 index 0000000..57d9e59 --- /dev/null +++ b/SOURCES/main/lib/log.lib @@ -0,0 +1,75 @@ +#!/bin/bash + +# kf2-srv is a command line tool for managing a set of Killing Floor 2 servers. +# Copyright (C) 2019, 2020 GenZmeY +# mailto: genzmey@gmail.com +# +# This file is part of kf2-srv. +# +# kf2-srv is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +function log_cat () # $*: InstanceName[s] +{ + include "$LibDir/instance.lib" + + local InstanceList="$*" + if [[ -z "$InstanceList" ]] ; then + InstanceList=$(show_instances) + fi + + local Logs + for Instance in $InstanceList + do + if instance_exists "$Instance"; then + local Service=$(service_name "$Instance") + Logs+="-u $Service " + else + echo "Instance $Instance not exitst" + fi + done + + if [[ -z "$Logs" ]]; then + echo "No logs available." + else + journalctl --no-pager $Logs + fi +} + +function log_tail () # $*: InstanceName[s] +{ + include "$LibDir/instance.lib" + + local InstanceList="$*" + if [[ -z "$InstanceList" ]] ; then + InstanceList=$(show_instances) + fi + + local Logs + for Instance in $InstanceList + do + if instance_exists "$Instance"; then + local Service=$(service_name "$Instance") + Logs+="-u $Service " + else + echo "Instance $Instance not exitst" + fi + done + + if [[ -z "$Logs" ]]; then + echo "No logs available." + else + echo "Hint: use Ctrl+C to stop output" + journalctl --no-pager -f $Logs + fi +} diff --git a/SOURCES/main/rsyslog/kf2-srv.conf b/SOURCES/main/rsyslog/kf2-srv.conf index 36d3b59..07d458f 100644 --- a/SOURCES/main/rsyslog/kf2-srv.conf +++ b/SOURCES/main/rsyslog/kf2-srv.conf @@ -2,9 +2,12 @@ global(parser.permitSlashInProgramName="on") template(name="DynFile" type="string" string="/var/log/%programname%.log") +# Change "UMask" in /usr/lib/systemd/system/rsyslog.service +# to make "FileCreateMode" and "Umask" work correctly for this config. + if ($programname startswith "kf2-srv") then { - action(Type="omfile" DynaFile="DynFile" FileCreateMode="0640" Umask="0027" FileOwner="root" FileGroup="steam") + action(Type="omfile" DynaFile="DynFile" FileCreateMode="0644" Umask="0022" FileOwner="root" FileGroup="steam") stop } diff --git a/SPECS/kf2-srv.spec b/SPECS/kf2-srv.spec index b4747b5..70eae34 100644 --- a/SPECS/kf2-srv.spec +++ b/SPECS/kf2-srv.spec @@ -1,7 +1,7 @@ %global steamuser steam Name: kf2-srv -Version: 0.15.4 +Version: 0.15.8 Release: 1%{dist} Summary: Killing Floor 2 server Group: Amusements/Games @@ -101,6 +101,9 @@ if [[ $1 == 1 ]]; then # Install fi %changelog +* Tue Sep 8 2020 GenZmeY - 0.16.0-1 +- log cmg group. + * Sat Aug 15 2020 GenZmeY - 0.15.4-1 - fixed broken update; - replaced steamID3/steamID64 conversation algorithm.