삽질

우분투 서버에 팰월드 서버 설치

maengis 2024. 1. 24. 21:52

https://developer.valvesoftware.com/wiki/SteamCMD#Linux

 

SteamCMD - Valve Developer Community

From Valve Developer Community The Steam Console Client or SteamCMD is a command-line version of the Steam Client. Its primary use is to install and update various dedicated servers available on Steam using a command-line interface. It works with games tha

developer.valvesoftware.com

 

https://tech.palworldgame.com/dedicated-server-guide#linux

 

Palworld tech guide

 

tech.palworldgame.com

 

https://github.com/ValveSoftware/steam-for-linux/issues/10215#issuecomment-1905137318

 

Project Zomboid server fails to find steamservice.so · Issue #10215 · ValveSoftware/steam-for-linux

Your system information Steam client version (build number or date): steam-runtime_0.20231024.64411 Distribution (e.g. Ubuntu): Pop OS 22.04 LTS (Ubuntu-based OS) Opted into Steam client beta?: [Ye...

github.com

 

https://github.com/A1RM4X/HowTo-Palworld

 

GitHub - A1RM4X/HowTo-Palworld: Set up a Palworld dedicated server on Linux

Set up a Palworld dedicated server on Linux. Contribute to A1RM4X/HowTo-Palworld development by creating an account on GitHub.

github.com

 

* 메모리 누수가 심해서 사용량 체크 해서 재시작 하는 스크립트를 돌리고 있다.\

 

import subprocess
import requests
import os

COUNT_FILE = '/home/app/palworld_chk_cnt'
RESTART_WAIT = 4
MEMORY_LIMIT = 7516192768

# 텔레그램 봇 설정
TELEGRAM_TOKEN = '텔레그램토큰'
TELEGRAM_CHAT_ID = '메시지보낼챗방아이디'

def send_telegram_message(message):
    # 텔레그램 API를 통해 메시지 전송
    url = f'https://api.telegram.org/bot{TELEGRAM_TOKEN}/sendMessage'
    payload = {
        'chat_id': TELEGRAM_CHAT_ID,
        'text': message
    }
    print(requests.post(url, data=payload))

def get_memory_usage():
    # free -b 명령어 실행
    result = subprocess.run(['free', '-b'], stdout=subprocess.PIPE)
    output = result.stdout.decode()

    # awk를 사용하여 used 메모리 양 추출
    memory_used = subprocess.run(['awk', '/^Mem:/ {print $3}'], input=output, stdout=subprocess.PIPE, text=True)
    return int(memory_used.stdout.strip())

def restart_service():
    subprocess.run(['sudo', 'service', 'palworld', 'restart'])

# 메모리 사용량 확인
used_memory = get_memory_usage()

cnt = int(os.popen(f'cat {COUNT_FILE}').read())

# 사용량을 초과하는 경우 서비스 재시작
if used_memory > MEMORY_LIMIT:
    cnt_minute = RESTART_WAIT - cnt - 1
    cnt_minute_str = str(cnt_minute)

    if cnt_minute > 0:
        send_telegram_message(f'메모리 사용량을 초과하여 PalWorld가 {cnt_minute_str}분 뒤 재시작 됩니다.')
        save_cnt = cnt + 1
        save_cnt = str(save_cnt)
        os.popen(f'echo {save_cnt} > {COUNT_FILE}')
    else:
        os.popen(f'echo 0 > {COUNT_FILE}')
        send_telegram_message('PalWorld를 재시작 하겠습니다.')
        restart_service()
        send_telegram_message('PalWorld가 재시작 되었습니다.')
elif cnt > 0:
    send_telegram_message('메모리 사용량이 초과 수치 이하로 내려갔습니다. 재시작은 하지 않지만 곧 재발 할 수 있습니다.')
    os.popen(f'echo 0 > {COUNT_FILE}')
else:
    os.popen(f'echo 0 > {COUNT_FILE}')

 

반응형