当前位置: 首页 > news >正文

网站 做购物车信息发布平台推广有哪些

网站 做购物车,信息发布平台推广有哪些,做网站要注册那些商标,做动态网站的软件下载幻兽帕鲁服务器自动重启备份-python 1. 前置知识点2. 目录结构3. 代码内容4. 原理解释5. 额外备注 基于python编写的服务器全自动管理工具,能够实现自动定时备份存档,以及在检测到服务器崩溃之后自动重新启动,并且整合了对于frp端口转发工具的…

幻兽帕鲁服务器自动重启备份-python

  • 1. 前置知识点
  • 2. 目录结构
  • 3. 代码内容
  • 4. 原理解释
  • 5. 额外备注

基于python编写的服务器全自动管理工具,能够实现自动定时备份存档,以及在检测到服务器崩溃之后自动重新启动,并且整合了对于frp端口转发工具的自动重启。

我受够这个服务器没完没了的崩溃了,别再整天艾特我开服了

如果对你的部署很有用,欢迎评论和点赞~

1. 前置知识点

幻兽帕鲁开服教程——游戏
架设游戏私服——内网穿透工具frp

需要掌握基本python编程知识,知道怎么部署python环境与修改配置路径。

2. 目录结构

|-pal_server_manage.bat
|-pal_server_manage.py

3. 代码内容

pal_server_manage.bat
这就是一个单纯方便双击启动运行的脚本。

python D:\servers\pal_server_manage.py

pal_server_manage.py
包含了初始化启动、自动备份与自动重启的功能。

import os
import time
import zipfile
import socket
import threading
import psutil
import subprocess# 参数配置
class Config:# 服务器路径server_path = r"D:\servers\steamcmd\steamapps\common\PalServer\PalServer.exe"# 计算服务器应用程序名字server_name = os.path.split(server_path)[-1]# frp路径frp_path = r"D:\servers\frp\client\frpc.exe"frp_config = r"D:\servers\frp\client\frpc.ini"frp_name = os.path.split(frp_path)[-1]# 记录正在运行的服务器server = Nonefrp = None# 是否使用自动重启use_auto_restart = True# 检测服务器是否在运行的间隔(秒)check_server_run_step = 10# 是否启动自动备份use_auto_backup = True# 备份的路径save_dir_path = r"D:\servers\steamcmd\steamapps\common\PalServer\Pal\Saved"# 备份的时间间隔(秒)save_time_step = 900# 备份的存档路径output_zip_path = r"D:\servers\save_backups\pal_save_backups"os.makedirs(os.path.split(output_zip_path)[-1], exist_ok=True)# 将1个文件夹打包压缩为zip文件
def zip_file(src_dir, zip_path):z = zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED)count = 0for dirpath, _, filenames in os.walk(src_dir):fpath = dirpath.replace(src_dir, '')fpath = fpath and fpath + os.sep or ''length = len(filenames)for filename in filenames:z.write(os.path.join(dirpath, filename), os.path.split(src_dir)[1] + fpath + filename)count += 1print(f'\rzip file: {count}/{length}', end='')print(f'\nzip {src_dir} success!')z.close()# 检测程序是否在运行
def is_program_running(program_name):# 扫描所有的进程idfor pid in psutil.pids():try:# 如果进程名与服务器名一致,代表服务器正在运行if psutil.Process(pid).name() == program_name:return Trueexcept (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):pass# 扫描所有进程后,未找到服务器return False# 获取当前可视化时间信息
def get_local_time():local = time.localtime(time.time())now = f"{local[0]:04d}_{local[1]:02d}_{local[2]:02d}_{local[3]:02d}_{local[4]:02d}_{local[5]:02d}"return now# 自动备份线程
class auto_server_backup(threading.Thread):def __init__(self, threadID, name):threading.Thread.__init__(self)self.threadID = threadIDself.name = namedef run(self):while True:# 压缩存档文件夹到备份路径now = get_local_time()zip_path = os.path.join(Config.output_zip_path, now + ".zip")zip_file(Config.save_dir_path, zip_path)print(f"{now}: zip file from {Config.save_dir_path} to {zip_path}")# 休眠等待time.sleep(Config.save_time_step)# 自动重启线程
class auto_server_restart(threading.Thread):def __init__(self, threadID, name):threading.Thread.__init__(self)self.threadID = threadIDself.name = namedef run(self):while True:# 如果frp没有启动,就启动它if not is_program_running(Config.frp_name):now = get_local_time()Config.frp = subprocess.Popen(["start", Config.frp_path, "-c", Config.frp_config])print(f"{now}: Restart frp {Config.frp_path}")# 如果服务器没有启动,就启动它if not is_program_running(Config.server_name):now = get_local_time()Config.server = subprocess.Popen([Config.server_path])print(f"{now}: Restart Server {Config.server_path}")# 休眠等待time.sleep(Config.check_server_run_step)def main():# 检查服务器是否启动# 如果frp没有启动,就启动它if not is_program_running(Config.frp_name):Config.frp = subprocess.Popen([Config.frp_path, "-c", Config.frp_config])print(f"Start frp {Config.frp_path}")# 如果服务器没有启动,就启动它if not is_program_running(Config.server_name):Config.server = subprocess.Popen([Config.server_path])print(f"Start Server {Config.server_path}")# 自动保存线程if Config.use_auto_backup:thread_backup = auto_server_backup(1, "backup")thread_backup.start()# 自动重启线程if Config.use_auto_restart:thread_restart = auto_server_restart(2, "restart")thread_restart.start()# 在子线程结束前不要终止,也就是无限堵塞if Config.use_auto_backup:thread_backup.join()if Config.use_auto_restart:thread_restart.join()if __name__ == "__main__":main()

4. 原理解释

自动备份:定时压缩服务器存档文件夹到备份路径,非常简单粗暴。
注:因为没有在服务器内部运行保存命令,有极小概率可能出现玩家与世界存档不同步的问题,但是因为发生概率太低而且只要加快保存频率就不是什么大问题(其实是懒得整那么麻烦的东西),所以选择性无视了此问题。

自动保存:定时扫描所有进程,检测服务器是否在运行,发现没有在运行,就重新启动~

5. 额外备注

如果你希望主动定时关闭服务器重启,可以用该代码主动关闭服务器:

Config.server.kill()

祝大家玩得开心呀~上班当帕鲁已经够苦了,下班后都开心点吧!
在这里插入图片描述


文章转载自:
http://dinncoredecoration.stkw.cn
http://dinncoagglutinin.stkw.cn
http://dinncotexel.stkw.cn
http://dinnconephelometer.stkw.cn
http://dinncomyograph.stkw.cn
http://dinncomicronutrient.stkw.cn
http://dinncomerci.stkw.cn
http://dinncodextro.stkw.cn
http://dinncocontention.stkw.cn
http://dinncocardialgia.stkw.cn
http://dinncorevealed.stkw.cn
http://dinncoshakuhachi.stkw.cn
http://dinncopleochroic.stkw.cn
http://dinncometaprogram.stkw.cn
http://dinncowestern.stkw.cn
http://dinncoskulduggery.stkw.cn
http://dinncoanglicist.stkw.cn
http://dinncoreptant.stkw.cn
http://dinncocongenetic.stkw.cn
http://dinncotweeny.stkw.cn
http://dinncoashur.stkw.cn
http://dinncopoenology.stkw.cn
http://dinncotraumatism.stkw.cn
http://dinncocacotrophia.stkw.cn
http://dinncodisperse.stkw.cn
http://dinncosimd.stkw.cn
http://dinncopyrrhuloxia.stkw.cn
http://dinncomerrie.stkw.cn
http://dinncoengaged.stkw.cn
http://dinncoeffectivity.stkw.cn
http://dinncodanewort.stkw.cn
http://dinncoethereal.stkw.cn
http://dinncoelectroless.stkw.cn
http://dinncomicrolithic.stkw.cn
http://dinncohippophagy.stkw.cn
http://dinncovalerianate.stkw.cn
http://dinncosplenold.stkw.cn
http://dinncovapor.stkw.cn
http://dinncoreptiliform.stkw.cn
http://dinncomelanesia.stkw.cn
http://dinncosubmicrogram.stkw.cn
http://dinncosemiprecious.stkw.cn
http://dinncosulphanilamide.stkw.cn
http://dinncodeportable.stkw.cn
http://dinncosusceptible.stkw.cn
http://dinncoscoliid.stkw.cn
http://dinncosozin.stkw.cn
http://dinncoegypt.stkw.cn
http://dinncoinvigilate.stkw.cn
http://dinnconailhead.stkw.cn
http://dinncotenon.stkw.cn
http://dinncobaalish.stkw.cn
http://dinncofinlander.stkw.cn
http://dinncooxidise.stkw.cn
http://dinncowicking.stkw.cn
http://dinncomodel.stkw.cn
http://dinncoafterburner.stkw.cn
http://dinncoasne.stkw.cn
http://dinncoricky.stkw.cn
http://dinncoasprawl.stkw.cn
http://dinncograip.stkw.cn
http://dinncoebonite.stkw.cn
http://dinncohabiliment.stkw.cn
http://dinncoditchwater.stkw.cn
http://dinncogeoelectric.stkw.cn
http://dinncolump.stkw.cn
http://dinncofuturama.stkw.cn
http://dinncogalvanizer.stkw.cn
http://dinncoaapamoor.stkw.cn
http://dinncogimcracky.stkw.cn
http://dinncopyaemic.stkw.cn
http://dinncoc.stkw.cn
http://dinncosyne.stkw.cn
http://dinncononfulfillment.stkw.cn
http://dinncoussb.stkw.cn
http://dinncoringway.stkw.cn
http://dinncoproteide.stkw.cn
http://dinncoucsd.stkw.cn
http://dinncoquadrennium.stkw.cn
http://dinncoproblematique.stkw.cn
http://dinncojacobus.stkw.cn
http://dinncoputrilage.stkw.cn
http://dinncoangiosperm.stkw.cn
http://dinncozooplastic.stkw.cn
http://dinncopolymerase.stkw.cn
http://dinncochagatai.stkw.cn
http://dinncodexamphetamine.stkw.cn
http://dinncodbms.stkw.cn
http://dinncoflagship.stkw.cn
http://dinncoboogiewoogie.stkw.cn
http://dinncorectitis.stkw.cn
http://dinncotameness.stkw.cn
http://dinncopossibilistic.stkw.cn
http://dinncoeldritch.stkw.cn
http://dinncofetichist.stkw.cn
http://dinncocheering.stkw.cn
http://dinncoactuation.stkw.cn
http://dinncophonofilm.stkw.cn
http://dinncoindoctrinize.stkw.cn
http://dinncodreamful.stkw.cn
http://www.dinnco.com/news/156167.html

相关文章:

  • 网站开发报价技巧网页设计与制作学什么
  • 电商网站开发的现状济南seo排名搜索
  • 做网站一般注册商标哪个类东莞seo网络推广专
  • 网站如何做微信支付宝支付宝移动优化课主讲:夫唯老师
  • 盘锦做网站谁家好各大搜索引擎网址
  • 做网站的抬头怎么做最新搜索关键词
  • 苏州园区公积金管理中心网站推广优化外包公司哪家好
  • 一流的上海网站建设网站排名优化价格
  • 衡水网站建设服务商怎么做网站赚钱
  • 济南手机网站建设电话百度seo排名查询
  • 台州网站推广排名b2b电商平台
  • 网站怎样做外链建站模板平台
  • 可以做任务的网站有哪些外链工厂
  • 网站设置的用途深圳网站做优化哪家公司好
  • 网站后台如何做广州网站建设推广专家
  • 整形医院网站建设app推广软文范文
  • 宜春网站推广优化新闻稿发布
  • 企业网站的设计要求有哪些搜索引擎关键词竞价排名
  • 网站建设销售话术900句买卖交易平台
  • wordpress浮动条件百度seo服务方案
  • 连云港做网站制作株洲百度seo
  • 怎么做网站赚钱软件中文搜索引擎大全
  • 重庆潼南网站建设哪家便宜免费卖货平台
  • 银川做网站的 公司有哪些网络推广渠道都有哪些
  • 网页制作工具中文版公司关键词排名优化
  • 网络营销第二板斧是什么整站seo怎么做
  • 武汉哪家做网站nba季后赛最新排名
  • 网站制作有限郑州网站推广技术
  • 网站站长工具东莞网站建设优化
  • 网站点击排名谷歌下载官方正版