ark_systemd
This commit is contained in:
parent
ff2d2f1668
commit
9c38ed40e8
119
hlna.py
119
hlna.py
@ -15,17 +15,14 @@ dir_unit = f"{home_dir}/.config/systemd/user/"
|
||||
dir_server = f"{home_dir}/Servers/"
|
||||
dir_logs = f"{dir_config}logs/"
|
||||
|
||||
dir_server_ark = f"{dir_server}/ARK/"
|
||||
dir_server_ark = f"{dir_server_ark}ShooterGame/Binaries/Linux/"
|
||||
dir_server_ark = f"{dir_server}ARK/"
|
||||
dir_server_exec = f"{dir_server_ark}ShooterGame/Binaries/Linux/"
|
||||
|
||||
|
||||
dir_maps_ark = f"{dir_config}/ARK"
|
||||
dir_maps_ark = f"{dir_config}/ARK/"
|
||||
dir_deactivated = f"{dir_maps_ark}deactivated/"
|
||||
|
||||
dir_server_7days = f"{dir_server}/7Days/"
|
||||
|
||||
|
||||
|
||||
mods_id = ""
|
||||
now = datetime.datetime.now()
|
||||
date = now.strftime("%Y-%m-%d")
|
||||
@ -49,8 +46,6 @@ create_dir(dir_config)
|
||||
create_dir(dir_logs)
|
||||
|
||||
|
||||
|
||||
|
||||
def find_file(path):
|
||||
"""Находим все конфиги в зависимости от пути"""
|
||||
arr = next(os.walk(path), (None, None, []))[2] # [] if no file
|
||||
@ -123,8 +118,8 @@ def config_ark(list_config=list_config):
|
||||
if count_cluster == 1:
|
||||
cluster_server = True
|
||||
cluster_id = input("Укажите id для кластера, любое сочетание символов: \n")
|
||||
create_dir(dir_server + cluster_id)
|
||||
cluster_dir_override = (dir_server + cluster_id)
|
||||
create_dir(dir_server_ark + cluster_id)
|
||||
cluster_dir_override = (dir_server_ark + cluster_id)
|
||||
else:
|
||||
cluster_server = False
|
||||
|
||||
@ -243,7 +238,6 @@ def config_ark(list_config=list_config):
|
||||
query_port = 27015
|
||||
print("Query Port=", query_port)
|
||||
|
||||
|
||||
rcon_enabled = True
|
||||
if rcon_p == []:
|
||||
rcon_port = 27020
|
||||
@ -258,9 +252,9 @@ def config_ark(list_config=list_config):
|
||||
|
||||
print("Передавать сервер в глобальный список серверов steam?")
|
||||
listen_server_amount = check_int("""\n
|
||||
1. Да
|
||||
2. Нет
|
||||
:""")
|
||||
1. Да
|
||||
2. Нет
|
||||
:""")
|
||||
if listen_server_amount == 1:
|
||||
listen_server = True
|
||||
elif listen_server_amount == 2:
|
||||
@ -268,7 +262,8 @@ def config_ark(list_config=list_config):
|
||||
else:
|
||||
listen_server = True
|
||||
|
||||
yaml_create(game:="ARK", cluster_server, map_s, list_config[-1], port_server, query_port, rcon_enabled, rcon_port,
|
||||
yaml_create(game := "ARK", cluster_server, map_s, list_config[-1], port_server, query_port, rcon_enabled,
|
||||
rcon_port,
|
||||
adminpassword_server, password_server, max_players, cluster_id, cluster_dir_override, listen_server)
|
||||
|
||||
|
||||
@ -285,12 +280,13 @@ def config_7daystodie():
|
||||
print_line("Запрещённые символы")
|
||||
else:
|
||||
xml_parser()
|
||||
systemd_unit_create(game:="7Days", config_7days)
|
||||
systemd_unit_create(game := "7Days", config_7days)
|
||||
|
||||
|
||||
def xml_parser():
|
||||
print("Я не умею парсить))")
|
||||
|
||||
|
||||
def yaml_create(game, cluster_server, map_s, name_server, port_server, query_port, rcon_enabled, rcon_port,
|
||||
adminpassword_server, password_server, max_players, cluster_id, cluster_dir_override, listen_server):
|
||||
settings_hlna = [
|
||||
@ -307,7 +303,7 @@ def yaml_create(game, cluster_server, map_s, name_server, port_server, query_por
|
||||
'MaxPlayers': max_players,
|
||||
'ModsId': mods_id,
|
||||
'Listen': listen_server,
|
||||
'ServerPath': dir_server,
|
||||
'ServerPath': dir_server_ark,
|
||||
'clusterid': cluster_id,
|
||||
'clusterdir': cluster_dir_override
|
||||
}
|
||||
@ -324,13 +320,15 @@ def systemd_unit_create(game, config_7days="", name_server=list_config):
|
||||
for i in name_server:
|
||||
data = read_yaml(i)
|
||||
ntff = "" if not data['Cluster'] else "-NoTransferFromFiltering"
|
||||
systemd_unit_exec = f"{dir_server_ark}ShooterGameServer {data['map']}?listen={data['Listen']}?SessionName={data['SessionName']}?Port={data['Port']}?QueryPort={data['QueryPort']}?RCONEnabled={data['RCONEnabled']}?RCONPort={data['RCONPort']}?ServerAdminPassword={data['ServerAdminPassword']}?MaxPlayers={data['MaxPlayers']} -clusterid={data['clusterid']} -ClusterDirOverride={data['clusterdir']} {ntff}"
|
||||
unit_file = f"{dir_unit}ARK_{data['SessionName']}.service"
|
||||
unit_dir_server = dir_server_ark
|
||||
systemd_unit_exec = f"{dir_server_exec}ShooterGameServer {data['map']}?listen={data['Listen']}?SessionName={data['SessionName']}?Port={data['Port']}?QueryPort={data['QueryPort']}?RCONEnabled={data['RCONEnabled']}?RCONPort={data['RCONPort']}?ServerAdminPassword={data['ServerAdminPassword']}?MaxPlayers={data['MaxPlayers']} -clusterid={data['clusterid']} -ClusterDirOverride={data['clusterdir']} {ntff}"
|
||||
unit_file = f"{dir_unit}ark_{data['SessionName']}.service".lower()
|
||||
elif game == "7Days":
|
||||
id_game = "294420"
|
||||
#сюда дописать обращение к xml для получения уникального имени сервера
|
||||
# сюда дописать обращение к xml для получения уникального имени сервера
|
||||
unit_dir_server = dir_server_7days
|
||||
systemd_unit_exec = f"{dir_server_7days}startserver.sh -configfile={config_7days}.xml"
|
||||
unit_file = f"{dir_unit}7Days.service"
|
||||
unit_file = f"{dir_config}7days.service".lower()
|
||||
|
||||
unit_text = f'''[Unit]
|
||||
Description={game}: Server
|
||||
@ -338,7 +336,7 @@ Wants=network-online.target
|
||||
After=syslog.target network.target nss-lookup.target network-online.target
|
||||
|
||||
[Service]
|
||||
ExecStartPre=/usr/bin/steamcmd +force_install_dir {dir_server} +login anonymous +app_update {id_game} +quit
|
||||
ExecStartPre=/usr/bin/steamcmd +force_install_dir {unit_dir_server} +login anonymous +app_update {id_game} +quit
|
||||
TimeoutStartSec=99999
|
||||
ExecStart={systemd_unit_exec}
|
||||
LimitNOFILE=100000
|
||||
@ -350,23 +348,24 @@ WantedBy=default.target
|
||||
'''
|
||||
with open(unit_file, 'w') as systemd_unit:
|
||||
systemd_unit.write(unit_text)
|
||||
os.system(f"systemctl --user unmask {unit_file}")
|
||||
os.system(f"systemctl --user enable {unit_file}")
|
||||
unit_name = unit_file.split("/")[-1]
|
||||
os.system(f"systemctl --user unmask {unit_name}")
|
||||
os.system('systemctl --user daemon-reload')
|
||||
os.system(f"systemctl --user enable {unit_name}")
|
||||
|
||||
|
||||
def test_mod_install():
|
||||
pathTest = f"{dir_server}ShooterGame/Saved/Config/LinuxServer/"
|
||||
if os.path.exists(pathTest):
|
||||
os.chdir(pathTest)
|
||||
# "Добавить файл в Game.ini, если модов несколько добавляем еще строку ModIDS=<ModId> [ModInstaller] ModIDS=<ModID>"
|
||||
# c этим не разобрался
|
||||
os.system("echo ActiveMods=2943454417 >> GameUserSettings.ini")
|
||||
else:
|
||||
print_line("Сервер не установлен")
|
||||
|
||||
|
||||
test_mod_install()
|
||||
# def test_mod_install():
|
||||
# pathTest = f"{dir_server_ark}ShooterGame/Saved/Config/LinuxServer/"
|
||||
# if os.path.exists(pathTest):
|
||||
# os.chdir(pathTest)
|
||||
# # "Добавить файл в Game.ini, если модов несколько добавляем еще строку ModIDS=<ModId> [ModInstaller] ModIDS=<ModID>"
|
||||
# # c этим не разобрался
|
||||
# os.system("echo ActiveMods=2943454417 >> GameUserSettings.ini")
|
||||
# else:
|
||||
# print_line("Сервер не установлен")
|
||||
#
|
||||
#
|
||||
# test_mod_install()
|
||||
|
||||
|
||||
@hlna.command()
|
||||
@ -396,7 +395,8 @@ def enablemap(m, e):
|
||||
if data['QueryPort'] in query_p:
|
||||
print("Заменить query port?")
|
||||
continue
|
||||
x = os.system(f"mv {dir_deactivated}{i} {dir_maps_ark} >> {dir_logs}{date} 2>&1") # Добавить текущее время
|
||||
x = os.system(
|
||||
f"mv {dir_deactivated}{i} {dir_maps_ark} >> {dir_logs}{date} 2>&1") # Добавить текущее время
|
||||
with open(f"{dir_logs}{date}.log", "a") as f:
|
||||
f.write(f"[{time}] File {i} has been moved to {dir_maps_ark}\n")
|
||||
if x == 0:
|
||||
@ -430,7 +430,7 @@ def enablemap(m, e):
|
||||
def servers(map_server=list_config):
|
||||
# Добавить сортивку по кластерам и вывод несколько столбиков
|
||||
if map_server == [] and delist_config == []:
|
||||
print("Сервера не установлены")
|
||||
print("Сервера не сконфигурированы")
|
||||
else:
|
||||
for i in map_server:
|
||||
data = read_yaml(i)
|
||||
@ -474,9 +474,11 @@ def servers(map_server=list_config):
|
||||
|
||||
|
||||
@hlna.command(help='Для запуска, сконфигурированного сервера или кластера')
|
||||
@click.option('-g', help="Название игры для запуска. (ark, 7days")
|
||||
@click.option('-m', default='all', help="Название карты для запуска или all для запуска все карт")
|
||||
@click.option('-b', default='', help="")
|
||||
def start(m, b, name_server=list_config):
|
||||
def start(g, m, b, name_server=list_config):
|
||||
if g == "ark":
|
||||
dict_mapname = {}
|
||||
dict_allmapname = []
|
||||
for i in name_server:
|
||||
@ -501,7 +503,44 @@ def start(m, b, name_server=list_config):
|
||||
|
||||
for i in names_serverstart:
|
||||
data = read_yaml(i)
|
||||
os.system(f"systemctl --user start ARK_{data['SessionName']}.service")
|
||||
x = os.system(f"systemctl --user start ark_{data['SessionName'].lower()}.service")
|
||||
print_line(x)
|
||||
else:
|
||||
print("Ни одной карты не установлено")
|
||||
|
||||
@hlna.command(help='Для остановки серверов')
|
||||
@click.option('-g', help="Название игры для остановки. (ark, 7days")
|
||||
@click.option('-m', default='all', help="Название карты для остановки или all для запуска все карт")
|
||||
@click.option('-b', default='', help="")
|
||||
def stop(g, m, b, name_server=list_config)
|
||||
if g == "ark":
|
||||
dict_mapname = {}
|
||||
dict_allmapname = []
|
||||
for i in name_server:
|
||||
data = read_yaml(i)
|
||||
print_line(f"Название сервера: {i} | Карта: {data['map']} | Кластер: {data['clusterid']}")
|
||||
dict_mapname[data['SessionName']] = data['map']
|
||||
dict_allmapname.append(data['SessionName'])
|
||||
print_line(f"Словарь названия сервера и карты {dict_mapname}")
|
||||
names_serverstart = []
|
||||
for ns, v in dict_mapname.items():
|
||||
print_line(f"переменные v и m {v} & {m}")
|
||||
if v in m:
|
||||
names_serverstart.append(ns)
|
||||
print_line(f"Карта которая запускается {ns}")
|
||||
if name_server != []:
|
||||
if b == '':
|
||||
if m == "all":
|
||||
names_serverstart = dict_allmapname
|
||||
print(f"Запускаем все активные карты {names_serverstart}")
|
||||
else:
|
||||
names_serverstart = choose_map(names_serverstart)
|
||||
|
||||
for i in names_serverstart:
|
||||
data = read_yaml(i)
|
||||
rcon(m, "SaveWorld")
|
||||
x = os.system(f"systemctl --user stop ark_{data['SessionName'].lower()}.service")
|
||||
print_line(x)
|
||||
else:
|
||||
print("Ни одной карты не установлено")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user