定制服务的制作和接口
我已经搜索这个有一段时间了,我不确定是否我没有使用正确的搜索词,或者答案是否真的很难找到。
我想做的是从批处理文件为游戏服务器创建一个新的 Windows 服务,然后让一个任务每 30 分钟或更长时间运行另一个批处理文件,这将在游戏服务器的命令行上运行两个命令并执行一些操作档案工作。
具体来说,我正在使用 Bukkit 为我帮助运行的游戏社区运行 Minecraft 服务器,并且我想确保该服务器始终正常运行,除非我专门告诉它停止(如服务)。 Bukkit 直接从批处理文件运行,并且有自己的命令行在其上运行。
有人告诉我,您可以将此类事物作为服务运行,但命令行将从视图和/或交互中隐藏。这是我的查询的第二部分。我有一个方便的小 backup.bat 文件,它将所有世界文件和用户数据文件复制到备份目录中,对其进行 7zip 压缩,然后删除该目录。唯一的问题是,《我的世界》喜欢始终打开世界的区域文件并随时写入,这意味着如果我直接运行它,可能会导致地图损坏。作为补偿,我需要在服务器上运行命令“save-off”以暂时禁用文件挂钩,运行备份,完成后立即运行“save-on”,以便游戏可以继续而不会丢失数据。
关于第二个,我想知道的是,是否可以通过批处理文件与游戏服务交互,或者我是否需要创建一个应用程序来执行此操作?如果是后者,具体该如何做呢?我有一定的 C++ 知识(直到大学里的第二门 OO-C++ 课程),如果绝对必要的话,我可以学习另一种语言。
所以,简而言之,有两个问题: 1. 是否可以以及如何将 BAT 文件作为 Windows 服务运行? 2. 如何通过 BAT 文件与所述服务交互,如果不可能,我需要编写什么样的应用程序(重定向到或编写教程对我有用)。
预先感谢您提供的任何帮助!
I've been searching for this for awhile now, and I am not sure if I am just not using the correct search terms or if the answer is really that hard to find.
What I am trying to do is to create a new Windows service for a game server from a batch file, and then have a task run another batch file every 30 minutes or more that would run two commands on the game server's command line and do some file work.
Specifically, I am running a Minecraft server using Bukkit for a gaming community I help run, and I want to make sure that the thing is always up unless I specifically tell it to stop (like a service). Bukkit is run directly from a batch file and has it's own command line thing running on it.
I am told that you CAN run this type of thing as a service, but the command line will be hidden from view and/or interaction. This is the second part of my query. I have a handy little backup.bat file that copies all the world files and userdata files into a backup directory, 7zips it, and deletes the directory. The only thing is, is that Minecraft likes to always have the worlds' region files open and writing at all times, meaning that it could cause map corruption if I just run it straight off. To compensate, I need to run the command "save-off" on the server to disable the file hooks temporarily, run the backup, and as soon as it finishes, run "save-on" so that the game can continue without lost data.
What I would like to know about this second one is, is it possible to interface with the game service through a batch file, or do I need to create an application to do that? If the latter, how exactly does one go about doing that? I have moderate C++ knowledge (up through my second OO-C++ course in college), and can possibly learn another language if absolutely necessary.
So, in short, two questions:
1. Is it possible to, and how to run a BAT file as a Windows Service?
2. How to interface with said service via BAT files, and if not possible, what kind of application do I need to write (redirection to or writing a tutorial works for me).
Thank you in advance for any and all help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
老问题,用户帐户似乎不再活跃了,但是嘿,如果您因为遇到类似的问题而偶然发现这一点:
既然我们正在谈论 Bukkit Minecraft 服务器,请转向 Bukkit 的“Essentials”插件。
它现在包含一个备份功能,它完全符合OP的要求,即停止保存,以便可以在不损坏的情况下操作文件,启动脚本,然后再次启动。
该脚本可以是备份脚本(链接页面中提供的示例),但可用于对世界文件运行任何操作。
Old question, user account doesn't seem active on SO anymore, but hey, if you stumble upon this because you have a similar problem:
Since we are speaking about a Bukkit Minecraft server, turn to the "Essentials" plugin for Bukkit.
It now includes a Backup function that does exactly what the OP asks for, namely stop the save so the files can be manipulated without corruption, launch a script, then starts again.
The script can be a backup one (examples provided in the linked page) but can be used to run any operation on the world's files.