Compare commits

..

18 Commits

Author SHA1 Message Date
1c25ebb829 fix: endless downloading 2020-07-19 07:58:23 +03:00
c7b3a6f396 fix misprint 2020-07-13 05:19:53 +03:00
4dedd8616b renamed: SOURCES/main.conf.template -> SOURCES/instance.conf.template 2020-07-13 05:06:55 +03:00
b3f39306a4 rename main.conf to instance.conf 2020-07-13 05:04:36 +03:00
fbfa8a268f Update TODO 2020-07-13 02:39:17 +03:00
85d4c46576 feat: force attrs for new files 2020-07-13 02:35:29 +03:00
d4b64d566d upd 2020-07-12 23:32:25 +03:00
250a440ee0 feat: force attr for log/ini files
- based for systemd service with inotify;
- group and permissions can be set in kf2-srv.conf;
- bot password in separate conf with no permissions for others.
2020-07-12 04:38:39 +03:00
7a6807fbf9 update systemd services
After/Wants/Requires blocks
2020-07-12 03:16:42 +03:00
ac84df6ced add idea on how fix permissions 2020-07-12 02:22:55 +03:00
b21333e317 rollback ACL/SGID
- ACL works as umask and can't help if program creates file with 600 permissions :(
- SGID is redunant with new rsyslog config.
2020-07-12 01:51:45 +03:00
02211b985c fix: update dir permissions
- game directories has SGID now;
- log directories has 660;
- conf has read bit for others.
2020-07-12 00:54:02 +03:00
9870ebfa66 fix: logfile permission is 640 now 2020-07-12 00:52:42 +03:00
ec6a3852f0 fix: now logrotate DO rotation 2020-07-12 00:49:30 +03:00
546a1d1740 feat: server logs with 'steam' group 2020-07-10 23:50:25 +03:00
4a53fda1c5 fix: disable timestamp for chat logs; 2020-07-10 23:29:50 +03:00
5209d059b7 Update TODO 2020-07-10 22:10:30 +03:00
6cb4b43de6 Update TODO 2020-07-10 04:18:20 +03:00
14 changed files with 224 additions and 101 deletions

4
SOURCES/bot.conf Normal file
View File

@ -0,0 +1,4 @@
# Bot default password
# To change the password for the bot, you must do this here and in WebAdmin.
# Otherwise, the bot will stop working and some actions cannot be done on running servers
ServerBotPassword=VerySecretBotPassword

View File

@ -26,10 +26,11 @@ declare -A MutNames
source /etc/steamcmd/steamcmd.conf source /etc/steamcmd/steamcmd.conf
source /etc/kf2-srv/kf2-srv.conf source /etc/kf2-srv/kf2-srv.conf
source /etc/kf2-srv/bot.conf
ScriptFullname=$(readlink -e "$0") readonly ScriptFullname=$(readlink -e "$0")
ScriptName=$(echo "$ScriptFullname" | awk -F '/' '{print $NF;}') readonly ScriptName=$(echo "$ScriptFullname" | awk -F '/' '{print $NF;}')
readonly ScriptVersion="0.11.1" readonly ScriptVersion=$(rpm -qi "$ScriptName" | grep 'Version' | sed -r 's|.+: +||g') # mb problems in other langs ('Version')
# Constants. Don't change. # Constants. Don't change.
readonly AppServerNum="232130" readonly AppServerNum="232130"
@ -203,7 +204,7 @@ function new_instance () # $*: InstanceName[s]
local MaxWebAdminPort='8080' local MaxWebAdminPort='8080'
for Instance in $(show_instances) for Instance in $(show_instances)
do do
local Config="$InstanceConfigDir/$Instance/main.conf" local Config="$InstanceConfigDir/$Instance/instance.conf"
local GamePort=$(multini --get "$Config" '' 'PortGame') local GamePort=$(multini --get "$Config" '' 'PortGame')
local WebAdminPort=$(multini --get "$Config" '' 'PortWeb') local WebAdminPort=$(multini --get "$Config" '' 'PortWeb')
local QueryPort=$(multini --get "$Config" '' 'PortQuery') local QueryPort=$(multini --get "$Config" '' 'PortQuery')
@ -221,13 +222,13 @@ function new_instance () # $*: InstanceName[s]
local InstanceDir="$InstanceConfigDir/$Instance" local InstanceDir="$InstanceConfigDir/$Instance"
local DirMode="-d -g $SteamUser -o $SteamUser -m 775" local DirMode="-d -g $SteamUser -o $ForceIniGroup -m 775"
local FileMode=" -g $SteamUser -o $SteamUser -m 664" local FileMode=" -g $SteamUser -o $ForceIniGroup -m $ForceIniPermissions"
install $DirMode "$InstanceDir" install $DirMode "$InstanceDir"
install $DirMode "$InstanceDir/LinuxServer" install $DirMode "$InstanceDir/LinuxServer"
install $FileMode "$MainConfigTemplate" "$InstanceDir/main.conf" install $FileMode "$InstanceConfigTemplate" "$InstanceDir/instance.conf"
install $FileMode "$DefaultConfigDir/KFAI.ini" "$InstanceDir" install $FileMode "$DefaultConfigDir/KFAI.ini" "$InstanceDir"
install $FileMode "$DefaultConfigDir/KFWeb.ini" "$InstanceDir" install $FileMode "$DefaultConfigDir/KFWeb.ini" "$InstanceDir"
install $FileMode "$DefaultConfigDir/KFWebAdmin.ini" "$InstanceDir" install $FileMode "$DefaultConfigDir/KFWebAdmin.ini" "$InstanceDir"
@ -243,9 +244,9 @@ function new_instance () # $*: InstanceName[s]
((MaxGamePort++)); ((MaxQueryPort++)); ((MaxWebAdminPort++)) ((MaxGamePort++)); ((MaxQueryPort++)); ((MaxWebAdminPort++))
multini -s "$InstanceDir/main.conf" '' 'PortGame' "$MaxGamePort" multini -s "$InstanceDir/instance.conf" '' 'PortGame' "$MaxGamePort"
multini -s "$InstanceDir/main.conf" '' 'PortQuery' "$MaxQueryPort" multini -s "$InstanceDir/instance.conf" '' 'PortQuery' "$MaxQueryPort"
multini -s "$InstanceDir/main.conf" '' 'PortWeb' "$MaxWebAdminPort" multini -s "$InstanceDir/instance.conf" '' 'PortWeb' "$MaxWebAdminPort"
multini -s "$InstanceDir/KFWeb.ini" "IpDrv.WebServer" "bEnabled" "true" multini -s "$InstanceDir/KFWeb.ini" "IpDrv.WebServer" "bEnabled" "true"
multini -s "$InstanceDir/LinuxServer-KFEngine.ini" "LogFiles" "PurgeLogsDays" "0" multini -s "$InstanceDir/LinuxServer-KFEngine.ini" "LogFiles" "PurgeLogsDays" "0"
@ -253,9 +254,7 @@ function new_instance () # $*: InstanceName[s]
multini -s "$InstanceDir/KFWebAdmin.ini" "WebAdmin.WebAdmin" "AuthenticationClass" "WebAdmin.MultiWebAdminAuth" multini -s "$InstanceDir/KFWebAdmin.ini" "WebAdmin.WebAdmin" "AuthenticationClass" "WebAdmin.MultiWebAdminAuth"
multini -s "$InstanceDir/KFWebAdmin.ini" "WebAdmin.WebAdmin" "bHttpAuth" "True" multini -s "$InstanceDir/KFWebAdmin.ini" "WebAdmin.WebAdmin" "bHttpAuth" "True"
multini -s "$InstanceDir/KFWebAdmin.ini" "WebAdmin.Chatlog" "Filename" "$Instance-chat" multini -s "$InstanceDir/KFWebAdmin.ini" "WebAdmin.Chatlog" "Filename" "$Instance-chat"
multini -s "$InstanceDir/KFWebAdmin.ini" "WebAdmin.Chatlog" "bIncludeTimeStamp" "True" multini -s "$InstanceDir/KFWebAdmin.ini" "WebAdmin.Chatlog" "bIncludeTimeStamp" "False"
# LOGGING?: LinuxServer-KFGame.ini bLog*
echo "Instance $Instance created. See /etc/$ScriptName/instances$BetaPostfix/$Instance for edit configuration" echo "Instance $Instance created. See /etc/$ScriptName/instances$BetaPostfix/$Instance for edit configuration"
done done
@ -303,16 +302,16 @@ function instance_status () # $1: InstanceName
else else
local IsRuning="stopped" local IsRuning="stopped"
fi fi
local Comment=$( multini -g "$InstanceConfigDir/$Instance/main.conf" '' "Comment") local Comment=$( multini -g "$InstanceConfigDir/$Instance/instance.conf" '' "Comment")
local GamePort=$( multini -g "$InstanceConfigDir/$Instance/main.conf" '' "PortGame") local GamePort=$( multini -g "$InstanceConfigDir/$Instance/instance.conf" '' "PortGame")
local WebAdminPort=$( multini -g "$InstanceConfigDir/$Instance/main.conf" '' "PortWeb") local WebAdminPort=$( multini -g "$InstanceConfigDir/$Instance/instance.conf" '' "PortWeb")
local QueryPort=$( multini -g "$InstanceConfigDir/$Instance/main.conf" '' "PortQuery") local QueryPort=$( multini -g "$InstanceConfigDir/$Instance/instance.conf" '' "PortQuery")
local GameType=$( multini -g "$InstanceConfigDir/$Instance/main.conf" '' "Game") local GameType=$( multini -g "$InstanceConfigDir/$Instance/instance.conf" '' "Game")
local GameLength=$( multini -g "$InstanceConfigDir/$Instance/main.conf" '' "Length") local GameLength=$( multini -g "$InstanceConfigDir/$Instance/instance.conf" '' "Length")
local GameDifficulty=$( multini -g "$InstanceConfigDir/$Instance/main.conf" '' "Difficulty") local GameDifficulty=$( multini -g "$InstanceConfigDir/$Instance/instance.conf" '' "Difficulty")
local Map=$( multini -g "$InstanceConfigDir/$Instance/main.conf" '' "Map") local Map=$( multini -g "$InstanceConfigDir/$Instance/instance.conf" '' "Map")
local Mutators=$( multini -g "$InstanceConfigDir/$Instance/main.conf" '' "Mutators") local Mutators=$( multini -g "$InstanceConfigDir/$Instance/instance.conf" '' "Mutators")
local Args=$( multini -g "$InstanceConfigDir/$Instance/main.conf" '' "Args") local Args=$( multini -g "$InstanceConfigDir/$Instance/instance.conf" '' "Args")
local DisplayGameType='' local DisplayGameType=''
local DisplayGameLength='' local DisplayGameLength=''
@ -395,9 +394,9 @@ function make_default_instance () # $1: Dir
{ {
local InstanceDir="$InstanceConfigDir/default" local InstanceDir="$InstanceConfigDir/default"
install -d -g "$SteamUser" -o "$SteamUser" -m 775 "$InstanceDir" install -d -g "$SteamUser" -o "$ForceIniGroup" -m 775 "$InstanceDir"
install -d -g "$SteamUser" -o "$SteamUser" -m 775 "$InstanceDir/LinuxServer" install -d -g "$SteamUser" -o "$ForceIniGroup" -m 775 "$InstanceDir/LinuxServer"
install -g "$SteamUser" -o "$SteamUser" -m 664 "$MainConfigTemplate" "$InstanceDir/main.conf" install -g "$SteamUser" -o "$ForceIniGroup" -m $ForceIniPermissions "$InstanceConfigTemplate" "$InstanceDir/instance.conf"
ln -s "$DefaultConfigDir/KFAI.ini" "$InstanceDir/KFAI.ini" ln -s "$DefaultConfigDir/KFAI.ini" "$InstanceDir/KFAI.ini"
ln -s "$DefaultConfigDir/KFWeb.ini" "$InstanceDir/KFWeb.ini" ln -s "$DefaultConfigDir/KFWeb.ini" "$InstanceDir/KFWeb.ini"
ln -s "$DefaultConfigDir/KFWebAdmin.ini" "$InstanceDir/KFWebAdmin.ini" ln -s "$DefaultConfigDir/KFWebAdmin.ini" "$InstanceDir/KFWebAdmin.ini"
@ -432,7 +431,7 @@ function fix_ini_permissions () # $1: Dir
{ {
find "$1" \( -type l -o -type f \) -name '*.ini' | \ find "$1" \( -type l -o -type f \) -name '*.ini' | \
xargs --max-procs=$(nproc) -I {} \ xargs --max-procs=$(nproc) -I {} \
sh -c "chmod 664 {}; chown $SteamUser:$SteamUser {}" sh -c "chmod $ForceIniPermissions {}; chown $SteamUser:$ForceIniGroup {}"
} }
function fix_ini_eol () # $1: Dir function fix_ini_eol () # $1: Dir
@ -452,34 +451,36 @@ function fix_steamclient_so ()
ln -s "/usr/share/steamcmd/linux64/steamclient.so" "$InstallDir/Binaries/Win64/lib64/steamclient.so" ln -s "/usr/share/steamcmd/linux64/steamclient.so" "$InstallDir/Binaries/Win64/lib64/steamclient.so"
} }
function create_map_dirs () function create_cache ()
{ {
# space saving if [[ -d "$DownloadDir" ]]; then
local InstallDirOrig="/usr/games/kf2-srv" if ! [[ -L "$DefaultDownloadDir" ]]; then
local InstallDirBeta="/usr/games/kf2-srv-beta" if [[ -d "$DefaultDownloadDir" ]]; then
local DownloadDirOrig="$InstallDirOrig/Binaries/Win64/steamapps/workshop/content/$AppClientNum" rm -rf "$DefaultDownloadDir" "$DownloadDir"
local CacheDirOrig="$InstallDirOrig/KFGame/Cache" ln -s "$DownloadDir" "$DefaultDownloadDir"
local DownloadDirBeta="$InstallDirBeta/Binaries/Win64/steamapps/workshop/content/$AppClientNum" else
local CacheDirBeta="$InstallDirBeta/KFGame/Cache" install -d -g "$SteamUser" -o "$SteamUser" -m 775 "$InstallDir/Binaries/Win64/steamapps"
ln -s "$DownloadDir" "$DefaultDownloadDir"
fi
fi
else
if [[ -L "$DefaultDownloadDir" ]]; then
install -d -g "$SteamUser" -o "$SteamUser" -m 775 "$DownloadDir"
elif [[ -d "$DefaultDownloadDir" ]]; then
mv -rf "$DefaultDownloadDir" "$DownloadDir"
ln -s "$DownloadDir" "$DefaultDownloadDir"
else
install -d -g "$SteamUser" -o "$SteamUser" -m 775 "$DownloadDir"
install -d -g "$SteamUser" -o "$SteamUser" -m 775 "$InstallDir/Binaries/Win64/steamapps"
ln -s "$DownloadDir" "$DefaultDownloadDir"
fi
fi
if [[ -z "$BetaPostfix" ]]; then # Orig if ! [[ -d "$CacheDir" ]]; then
sudo -u "$SteamUser" install -d -m 775 "$DownloadDirOrig" install -d -g "$SteamUser" -o "$SteamUser" -m 775 "$CacheDir"
if [[ -d "$CacheDirBeta" ]]; then
ln -s "$CacheDirBeta" "$CacheDirOrig"
rm -rf "$DownloadDirOrig"
ln -s "$DownloadDirBeta" "$DownloadDirOrig"
else
sudo -u "$SteamUser" install -d -m 775 "$CacheDirOrig"
fi
else # Beta
sudo -u "$SteamUser" install -d -m 775 "$DownloadDirBeta"
if [[ -d "$CacheDirOrig" ]]; then
ln -s "$CacheDirOrig" "$CacheDirBeta"
rm -rf "$DownloadDirBeta"
ln -s "$DownloadDirOrig" "$DownloadDirBeta"
else
sudo -u "$SteamUser" install -d -m 775 "$CacheDirBeta"
fi fi
if ! [[ -L "$DefaultCacheDir" ]]; then
ln -s "$CacheDir" "$DefaultCacheDir"
fi fi
} }
@ -490,8 +491,8 @@ function first_install ()
exit 1 exit 1
fi fi
rm -rf "$LogDir" rm -rf "$DefaultLogDir"
ln -s "/var/log/kf2-srv$BetaPostfix" "$LogDir" ln -s "$LogDir" "$DefaultLogDir"
echo "Creating base ini files" echo "Creating base ini files"
sudo -u "$SteamUser" $AppBin &> /dev/null & sudo -u "$SteamUser" $AppBin &> /dev/null &
@ -530,7 +531,7 @@ function first_install ()
multini -s "$DefaultConfigDir/KFWebAdmin.ini" "WebAdmin.WebAdmin" "bHttpAuth" "True" multini -s "$DefaultConfigDir/KFWebAdmin.ini" "WebAdmin.WebAdmin" "bHttpAuth" "True"
multini -s "$DefaultConfigDir/KFWebAdmin.ini" "WebAdmin.WebAdmin" "bChatLog" "True" multini -s "$DefaultConfigDir/KFWebAdmin.ini" "WebAdmin.WebAdmin" "bChatLog" "True"
multini -s "$DefaultConfigDir/KFWebAdmin.ini" "WebAdmin.Chatlog" "Filename" "default-chat" multini -s "$DefaultConfigDir/KFWebAdmin.ini" "WebAdmin.Chatlog" "Filename" "default-chat"
multini -s "$DefaultConfigDir/KFWebAdmin.ini" "WebAdmin.Chatlog" "bIncludeTimeStamp" "True" multini -s "$DefaultConfigDir/KFWebAdmin.ini" "WebAdmin.Chatlog" "bIncludeTimeStamp" "False"
echo "Wait while WebAdmin up" echo "Wait while WebAdmin up"
sudo -u "$SteamUser" $AppBin &> /dev/null & sudo -u "$SteamUser" $AppBin &> /dev/null &
@ -576,9 +577,9 @@ function first_install ()
do sleep 2; done do sleep 2; done
killall -KILL KFGameSteamServer.bin.x86_64; sleep 1 killall -KILL KFGameSteamServer.bin.x86_64; sleep 1
create_map_dirs create_cache
fix_steamclient_so fix_steamclient_so
ln -s "$InstanceConfigDir" "$InstanceConfigLnk" ln -s "$InstanceConfigDir" "$DefaultConfigDir/instances"
make_default_instance make_default_instance
echo "KF2 succesfully installed" echo "KF2 succesfully installed"
} }
@ -774,7 +775,7 @@ function workshop_list ()
for WorkshopID in $(workshop_list_ids) for WorkshopID in $(workshop_list_ids)
do do
local Cache="$CacheDir/$WorkshopID" local Cache="$CacheDir/$WorkshopID"
local Downl="$DownloadDir/$WorkshopID" local Downl="$DownloadDir/content/$AppClientNum/$WorkshopID"
local Url="https://steamcommunity.com/sharedfiles/filedetails/?id=$WorkshopID" local Url="https://steamcommunity.com/sharedfiles/filedetails/?id=$WorkshopID"
local WsName=$(name_by_workshopID "$WorkshopID") local WsName=$(name_by_workshopID "$WorkshopID")
if [[ -n "$WsName" ]]; then if [[ -n "$WsName" ]]; then
@ -822,7 +823,7 @@ function workshop_del () # $*: WorkshopID[s]
local WorkshopID=$(any_to_workshopID "$Map") local WorkshopID=$(any_to_workshopID "$Map")
local WsName=$(name_by_workshopID "$WorkshopID") local WsName=$(name_by_workshopID "$WorkshopID")
local Cache="$CacheDir/$WorkshopID" local Cache="$CacheDir/$WorkshopID"
local Downl="$DownloadDir/$WorkshopID" local Downl="$DownloadDir/content/$AppClientNum/$WorkshopID"
echo -e "Clear cache:\n$Cache\n$Downl" echo -e "Clear cache:\n$Cache\n$Downl"
rm -rf "$Cache" "$Downl" rm -rf "$Cache" "$Downl"
for Instance in $(show_instances) for Instance in $(show_instances)
@ -1129,8 +1130,8 @@ function admin_curl () # $1: Instance, $2: URL, $*: Request
{ {
local Instance="$1" local Instance="$1"
local URL="$2" local URL="$2"
local MainConf="$InstanceConfigDir/$Instance/main.conf" local InstanceConf="$InstanceConfigDir/$Instance/instance.conf"
local WebPort=$(multini --get "$MainConf" '' "PortWeb") local WebPort=$(multini --get "$InstanceConf" '' "PortWeb")
shift; shift shift; shift
curl -s -o "/dev/null" -u "$ServerBotLogin:$ServerBotPassword" "localhost:$WebPort/$URL" $* curl -s -o "/dev/null" -u "$ServerBotLogin:$ServerBotPassword" "localhost:$WebPort/$URL" $*
} }
@ -1235,13 +1236,18 @@ fi
InstallDir="/usr/games/kf2-srv$BetaPostfix" InstallDir="/usr/games/kf2-srv$BetaPostfix"
AppBin="$InstallDir/Binaries/Win64/KFGameSteamServer.bin.x86_64" AppBin="$InstallDir/Binaries/Win64/KFGameSteamServer.bin.x86_64"
DefaultConfigDir="$InstallDir/KFGame/Config" DefaultConfigDir="$InstallDir/KFGame/Config"
DownloadDir="$InstallDir/Binaries/Win64/steamapps/workshop/content/$AppClientNum" DefaultDownloadDir="$InstallDir/Binaries/Win64/steamapps/workshop"
CacheDir="$InstallDir/KFGame/Cache" DefaultCacheDir="$InstallDir/KFGame/Cache"
LogDir="$InstallDir/KFGame/Logs" DefaultLogDir="$InstallDir/KFGame/Logs"
DownloadDir="/var/cache/kf2-srv/workshop"
CacheDir="/var/cache/kf2-srv/cache"
LogDir="/var/log/kf2-srv$BetaPostfix"
InstanceConfigDir="/etc/kf2-srv/instances$BetaPostfix" InstanceConfigDir="/etc/kf2-srv/instances$BetaPostfix"
InstanceConfigLnk="$DefaultConfigDir/instances" InstanceConfigTemplate="/etc/kf2-srv/instance.conf.template"
MainConfigTemplate="/etc/kf2-srv/main.conf.template"
if [[ $# -eq 0 ]]; then show_help; exit 0; fi if [[ $# -eq 0 ]]; then show_help; exit 0; fi
case $1 in case $1 in

View File

@ -1,5 +1,7 @@
[Unit] [Unit]
Description=Check and Update Killing Floor 2 server Description=Check and Update Killing Floor 2 server
After=network-online.target
Requires=network-online.target
[Service] [Service]
Type=oneshot Type=oneshot

View File

@ -1,5 +1,8 @@
[Unit] [Unit]
Description=Killing Floor 2 Beta Server Daemon - %i Description=Killing Floor 2 Beta Server Daemon - %i
After=kf2-srv-force-attr.service
After=network-online.target
Wants=network-online.target
[Service] [Service]
User=steam User=steam
@ -8,7 +11,7 @@ Type=simple
StandardOutput=syslog StandardOutput=syslog
StandardError=syslog StandardError=syslog
SyslogIdentifier=kf2-srv-beta/%i SyslogIdentifier=kf2-srv-beta/%i
EnvironmentFile=/etc/kf2-srv/instances-beta/%i/main.conf EnvironmentFile=/etc/kf2-srv/instances-beta/%i/instance.conf
ExecStart=/usr/games/kf2-srv-beta/Binaries/Win64/KFGameSteamServer.bin.x86_64 ${Map}?Difficulty=${Difficulty}?GameLength=${Length}?Game=${Game}?Mutator=${Mutators}?${Args} configsubdir=instances/%i -webadminport=${PortWeb} -queryport=${PortQuery} -port=${PortGame} ExecStart=/usr/games/kf2-srv-beta/Binaries/Win64/KFGameSteamServer.bin.x86_64 ${Map}?Difficulty=${Difficulty}?GameLength=${Length}?Game=${Game}?Mutator=${Mutators}?${Args} configsubdir=instances/%i -webadminport=${PortWeb} -queryport=${PortQuery} -port=${PortGame}
Restart=always Restart=always

View File

@ -0,0 +1,43 @@
#!/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 <https://www.gnu.org/licenses/>.
declare -A ModeNames MutNames
source /etc/kf2-srv/kf2-srv.conf
DirLog="/var/log/kf2-srv"
DirLogBeta="/var/log/kf2-srv-beta"
DirInstances="/etc/kf2-srv/instances"
DirInstancesBeta="/etc/kf2-srv/instances-beta"
/usr/bin/inotifywait -qmr -e create -e moved_to --format %w%f \
"$DirLog" "$DirLogBeta" "$DirInstances" "$DirInstancesBeta" | \
while read File
do
if echo "$File" | grep -Piq "\.log$"; then
chmod "$ForceLogPermissions" "$File"
chown :"$ForceLogGroup" "$File"
elif echo "$File" | grep -Piq "\.ini$"; then
chmod "$ForceIniPermissions" "$File"
chown :"$ForceIniGroup" "$File"
fi
done

View File

@ -0,0 +1,18 @@
[Unit]
Description=kf2-srv force attr service
[Service]
Type=simple
StandardOutput=null
StandardError=null
ExecStart=/usr/sbin/kf2-srv-force-attr
Restart=always
NoNewPrivileges=yes
PrivateTmp=true
PrivateDevices=true
ProtectHome=true
ProtectSystem=true
[Install]
WantedBy=multi-user.target

View File

@ -1,5 +1,7 @@
[Unit] [Unit]
Description=Check and Update Killing Floor 2 server Description=Check and Update Killing Floor 2 server
After=network-online.target
Requires=network-online.target
[Service] [Service]
Type=oneshot Type=oneshot

View File

@ -3,7 +3,7 @@
DiffNames=('Normal' 'Hard' 'Suicide' 'Hell') DiffNames=('Normal' 'Hard' 'Suicide' 'Hell')
# Displays the number of waves # Displays the number of waves
# You can rename them as you like # You can rename them as you like (e.g. 'short' 'medium' 'long')
WaveNames=('4' '7' '10') WaveNames=('4' '7' '10')
# Add custom gamemodes to the end of the list, similar to what is already there: # Add custom gamemodes to the end of the list, similar to what is already there:
@ -16,7 +16,10 @@ ModeNames['KFGameContent.KFGameInfo_VersusSurvival']='Versus'
# Add mutators to the end of the list, similar to what is already there: # Add mutators to the end of the list, similar to what is already there:
MutNames['ServerExtMut.ServerExtMut']='RPG' MutNames['ServerExtMut.ServerExtMut']='RPG'
# Bot default password # These parameters are used when creating new instances.
# To change the password for the bot, you must do this here and in WebAdmin. # In order for the parameters to be applied to the files that the working server creates, the "kf2-srv-force-attr.service" must be active.
# Otherwise, the bot will stop working and some actions cannot be done on running servers ForceIniPermissions=664
ServerBotPassword=VerySecretBotPassword ForceLogPermissions=640
ForceIniGroup=steam
ForceLogGroup=steam

View File

@ -1,5 +1,8 @@
[Unit] [Unit]
Description=Killing Floor 2 Server Daemon - %i Description=Killing Floor 2 Server Daemon - %i
After=kf2-srv-force-attr.service
After=network-online.target
Wants=network-online.target
[Service] [Service]
User=steam User=steam
@ -8,7 +11,7 @@ Type=simple
StandardOutput=syslog StandardOutput=syslog
StandardError=syslog StandardError=syslog
SyslogIdentifier=kf2-srv/%i SyslogIdentifier=kf2-srv/%i
EnvironmentFile=/etc/kf2-srv/instances/%i/main.conf EnvironmentFile=/etc/kf2-srv/instances/%i/instance.conf
ExecStart=/usr/games/kf2-srv/Binaries/Win64/KFGameSteamServer.bin.x86_64 ${Map}?Difficulty=${Difficulty}?GameLength=${Length}?Game=${Game}?Mutator=${Mutators}?${Args} configsubdir=instances/%i -webadminport=${PortWeb} -queryport=${PortQuery} -port=${PortGame} ExecStart=/usr/games/kf2-srv/Binaries/Win64/KFGameSteamServer.bin.x86_64 ${Map}?Difficulty=${Difficulty}?GameLength=${Length}?Game=${Game}?Mutator=${Mutators}?${Args} configsubdir=instances/%i -webadminport=${PortWeb} -queryport=${PortQuery} -port=${PortGame}
Restart=always Restart=always

View File

@ -1,6 +1,7 @@
/var/log/kf2-srv/*.log /var/log/kf2-srv/*.log
/var/log/kf2-srv-beta/*.log /var/log/kf2-srv-beta/*.log
{ {
su root steam
daily daily
missingok missingok
rotate 7 rotate 7

View File

@ -1,8 +1,10 @@
global(parser.permitSlashInProgramName="on") global(parser.permitSlashInProgramName="on")
$template NAMED_LOG,"/var/log/%programname%.log" template(name="DynFile" type="string" string="/var/log/%programname%.log")
if ($programname startswith "kf2-srv") then
{
action(Type="omfile" DynaFile="DynFile" FileCreateMode="0640" Umask="0027" FileOwner="root" FileGroup="steam")
stop
}
$FileCreateMode 0644
$Umask 0022
if $programname startswith 'kf2-srv' then ?NAMED_LOG
& stop

View File

@ -1,7 +1,7 @@
%global steamuser steam %global steamuser steam
Name: kf2-srv Name: kf2-srv
Version: 0.11.1 Version: 0.13.0
Release: 1%{dist} Release: 1%{dist}
Summary: Killing Floor 2 server Summary: Killing Floor 2 server
Group: Amusements/Games Group: Amusements/Games
@ -14,7 +14,7 @@ Source3: %{name}.xml
Source4: %{name}@.service Source4: %{name}@.service
Source5: %{name}-update.service Source5: %{name}-update.service
Source6: %{name}-update.timer Source6: %{name}-update.timer
Source7: main.conf.template Source7: instance.conf.template
Source8: %{name}-beta@.service Source8: %{name}-beta@.service
Source9: %{name}-beta-update.service Source9: %{name}-beta-update.service
Source10: %{name}-beta-update.timer Source10: %{name}-beta-update.timer
@ -22,6 +22,9 @@ Source11: %{name}.conf
Source12: COPYING Source12: COPYING
Source13: rsyslog-%{name}.conf Source13: rsyslog-%{name}.conf
Source14: logrotate-%{name} Source14: logrotate-%{name}
Source15: bot.conf
Source16: %{name}-force-attr
Source17: %{name}-force-attr.service
Requires: systemd >= 219 Requires: systemd >= 219
Requires: steamcmd Requires: steamcmd
@ -38,6 +41,7 @@ Requires: gawk
Requires: multini >= 0.2.3 Requires: multini >= 0.2.3
Requires: rsyslog >= 8.25.0 Requires: rsyslog >= 8.25.0
Requires: logrotate Requires: logrotate
Requires: inotify-tools
Provides: %{name} Provides: %{name}
@ -52,6 +56,7 @@ Command line tool for managing a set of Killing Floor 2 servers.
rm -rf $RPM_BUILD_ROOT rm -rf $RPM_BUILD_ROOT
install -d %{buildroot}/%{_bindir} install -d %{buildroot}/%{_bindir}
install -d %{buildroot}/%{_sbindir}
install -d %{buildroot}/%{_prefix}/lib/systemd/system install -d %{buildroot}/%{_prefix}/lib/systemd/system
install -d %{buildroot}/%{_prefix}/lib/firewalld/services install -d %{buildroot}/%{_prefix}/lib/firewalld/services
install -d %{buildroot}/%{_sysconfdir}/%{name}/instances install -d %{buildroot}/%{_sysconfdir}/%{name}/instances
@ -64,6 +69,7 @@ install -d %{buildroot}/%{_prefix}/games/%{name}-beta
install -d %{buildroot}/%{_datadir}/licenses/%{name} install -d %{buildroot}/%{_datadir}/licenses/%{name}
install -d %{buildroot}/%{_localstatedir}/log/%{name} install -d %{buildroot}/%{_localstatedir}/log/%{name}
install -d %{buildroot}/%{_localstatedir}/log/%{name}-beta install -d %{buildroot}/%{_localstatedir}/log/%{name}-beta
install -d %{buildroot}/%{_localstatedir}/cache/kf2-srv
# access rights are used here to prevent warnings when building the package # access rights are used here to prevent warnings when building the package
install -m 755 %{SOURCE1} %{buildroot}/%{_bindir} install -m 755 %{SOURCE1} %{buildroot}/%{_bindir}
@ -80,28 +86,38 @@ install -m 644 %{SOURCE11} %{buildroot}/%{_sysconfdir}/%{name}
install -m 644 %{SOURCE12} %{buildroot}/%{_datadir}/licenses/%{name} install -m 644 %{SOURCE12} %{buildroot}/%{_datadir}/licenses/%{name}
install -m 644 %{SOURCE13} %{buildroot}/%{_sysconfdir}/rsyslog.d/%{name}.conf install -m 644 %{SOURCE13} %{buildroot}/%{_sysconfdir}/rsyslog.d/%{name}.conf
install -m 644 %{SOURCE14} %{buildroot}/%{_sysconfdir}/logrotate.d/%{name} install -m 644 %{SOURCE14} %{buildroot}/%{_sysconfdir}/logrotate.d/%{name}
install -m 644 %{SOURCE15} %{buildroot}/%{_sysconfdir}/%{name}
install -m 755 %{SOURCE16} %{buildroot}/%{_sbindir}
install -m 644 %{SOURCE17} %{buildroot}/%{_prefix}/lib/systemd/system
%check
bash -n %{buildroot}/%{_bindir}/%{name}
bash -n %{buildroot}/%{_bindir}/%{name}-beta
%clean %clean
rm -rf $RPM_BUILD_ROOT rm -rf $RPM_BUILD_ROOT
%files %files
%attr(775,root,%{steamuser}) %dir %{_prefix}/games/%{name} %attr(0775,root,%{steamuser}) %dir %{_prefix}/games/%{name}
%attr(775,root,%{steamuser}) %dir %{_prefix}/games/%{name}-beta %attr(0775,root,%{steamuser}) %dir %{_prefix}/games/%{name}-beta
%attr(775,root,%{steamuser}) %dir %{_sysconfdir}/%{name} %attr(0775,root,%{steamuser}) %dir %{_sysconfdir}/%{name}
%attr(775,root,%{steamuser}) %dir %{_sysconfdir}/%{name}/instances %attr(0775,root,%{steamuser}) %dir %{_sysconfdir}/%{name}/instances
%attr(775,root,%{steamuser}) %dir %{_sysconfdir}/%{name}/instances-beta %attr(0775,root,%{steamuser}) %dir %{_sysconfdir}/%{name}/instances-beta
%attr(775,root,%{steamuser}) %dir %{_sysconfdir}/%{name}/mapcycles %attr(0775,root,%{steamuser}) %dir %{_sysconfdir}/%{name}/mapcycles
%attr(775,root,%{steamuser}) %dir %{_localstatedir}/log/%{name} %attr(0770,root,%{steamuser}) %dir %{_localstatedir}/log/%{name}
%attr(775,root,%{steamuser}) %dir %{_localstatedir}/log/%{name}-beta %attr(0770,root,%{steamuser}) %dir %{_localstatedir}/log/%{name}-beta
%attr(644,root,%{steamuser}) %config(noreplace) %{_sysconfdir}/%{name}/main.conf.template %attr(0775,root,%{steamuser}) %dir %{_localstatedir}/cache/kf2-srv
%attr(644,root,%{steamuser}) %config(noreplace) %{_sysconfdir}/%{name}/%{name}.conf %attr(0664,root,%{steamuser}) %config(noreplace) %{_sysconfdir}/%{name}/instance.conf.template
%attr(644,root,root) %config(noreplace) %{_prefix}/lib/firewalld/services/%{name}.xml %attr(0664,root,%{steamuser}) %config(noreplace) %{_sysconfdir}/%{name}/%{name}.conf
%attr(755,root,root) %{_bindir}/%{name} %attr(0640,root,%{steamuser}) %config(noreplace) %{_sysconfdir}/%{name}/bot.conf
%attr(755,root,root) %{_bindir}/%{name}-beta %attr(0644,root,root) %config(noreplace) %{_prefix}/lib/firewalld/services/%{name}.xml
%attr(644,root,root) %{_prefix}/lib/systemd/system/* %attr(0755,root,root) %{_bindir}/%{name}
%attr(644,root,root) %doc %{_datadir}/licenses/%{name}/* %attr(0755,root,root) %{_bindir}/%{name}-beta
%attr(644,root,root) %{_sysconfdir}/rsyslog.d/%{name}.conf %attr(0755,root,root) %{_sbindir}/%{name}-force-attr
%attr(644,root,root) %{_sysconfdir}/logrotate.d/%{name} %attr(0644,root,root) %{_prefix}/lib/systemd/system/*
%attr(0644,root,root) %doc %{_datadir}/licenses/%{name}/*
%attr(0644,root,root) %{_sysconfdir}/rsyslog.d/%{name}.conf
%attr(0644,root,root) %{_sysconfdir}/logrotate.d/%{name}
%preun %preun
if [[ $1 -eq 0 ]] ; then # Uninstall if [[ $1 -eq 0 ]] ; then # Uninstall
@ -111,13 +127,32 @@ if [[ $1 -eq 0 ]] ; then # Uninstall
rm -rf %{_prefix}/games/%{name}-beta/* rm -rf %{_prefix}/games/%{name}-beta/*
rm -rf %{_sysconfdir}/%{name}/instances/default rm -rf %{_sysconfdir}/%{name}/instances/default
rm -rf %{_sysconfdir}/%{name}/instances-beta/default rm -rf %{_sysconfdir}/%{name}/instances-beta/default
rm -rf %{_localstatedir}/cache/kf2-srv/*
fi fi
%post %post
systemctl daemon-reload if [[ $1 == 1 ]]; then # Install
systemctl restart rsyslog.service systemctl daemon-reload
systemctl try-restart rsyslog.service
fi
%changelog %changelog
* Sun Jul 19 2020 GenZmeY <genzmey@gmail.com> - 0.13.0-1
- /var/cache to store the workshop cache;
- fixed endless downloading of workshop items that tripware gave us in PC Build 1099 patch;
- using ForcePermissions when creating instances;
- add %check section to specfile.
* Mon Jul 13 2020 GenZmeY <genzmey@gmail.com> - 0.12.1-1
- rename main.conf to instance.conf.
* Mon Jul 13 2020 GenZmeY <genzmey@gmail.com> - 0.12.0-1
- chat logs without timestamp;
- update rsyslog config - now logs will be create with steam group and 640 permissions;
- update logrotate config (fixed that logrotate does nothing);
- bot password in separate file without read permission to others;
- feat: force attr for log/ini files.
* Thu Jul 9 2020 GenZmeY <genzmey@gmail.com> - 0.11.1-1 * Thu Jul 9 2020 GenZmeY <genzmey@gmail.com> - 0.11.1-1
- fix syntax error in firewalld service. - fix syntax error in firewalld service.

1
TODO
View File

@ -4,6 +4,7 @@
- split the script into separate files - split the script into separate files
- man pages - man pages
- english help - english help
- check ban EGS players (mb bugs)
- ban history - ban history
- temporary ban - temporary ban
- understand what causes a "cpu hurricane" at startup - understand what causes a "cpu hurricane" at startup