如何在运行时更新bash脚本或轻松地重新启动它? [英] How to update bash script whilst running or easily restart it?

查看:113
本文介绍了如何在运行时更新bash脚本或轻松地重新启动它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要一种方法来轻松地重新启动/替换bash脚本,而无需手动停止/重新开始该过程.

I require a method to easily restart/replace bash scripts without manually stopping/starting the process over again.

这是我当前脚本的工作方式:

Here's how my current script works:

#!/bin/sh
while true
do
  echo "1"
  java -server -Xms2G -jar game.jar nogui
done

基本上,如果游戏停止,它将自动重新启动,但是该脚本已经加载到内存中,因此,如果我要对其进行修改,则必须手动终止该脚本并重新启动它才能进行更改生效.我正在运行至少200个游戏服务器实例,因此手动执行此操作并杀死它,然后再次手动启动每个脚本并不明智.

Basically, if the game stops, it will automatically restart however, the script is already loaded into memory so if I was to modify it, I would have to manually kill the script and start it up again in order for the changes to take effect. I'm running at least 200 instances of the game server itself so, it would not be intelligent to do this manually and kill, then start each script manually again.

当游戏服务器停止时,我希望它更新脚本,这是我可能想做的一个例子:

When the game server stops, I wish for it to update the script, here is an example of what I may want to do:

#!/bin/sh
while true
do
  echo "1"
  echo "2"
  java -server -Xms2G -jar game.jar nogui
done

但是,我需要物理停止脚本并自己重新启动它才能添加新的'echo"2"',我需要一种更简单的方法来替换正在运行的脚本.

However, I'd need to physically stop the script and start it again myself in order for it to add the new 'echo "2"', I need an easier way to replace the running script.

脚本本身将在游戏停止时下载更新的脚本(因此它将自动重新开始.

The script itself will download the updated script when the game stops (so it will automatically start again.

如何使脚本从内存中卸载并使用新脚本?

How can I make the script unload itself from memory, and use the new script?

如果我不能这样做,您是否可以建议其他替代方法?

If I cannot do this, is there any alternative method you can suggest?

推荐答案

调用以下文件myscript.sh.每当游戏停止时,它将自身重新加载到内存中:

Call the following file myscript.sh. It reloads itself into memory every time that the game stops:

#!/bin/sh
java -server -Xms2G -jar game.jar nogui
exec /path/to/myscript.sh

这篇关于如何在运行时更新bash脚本或轻松地重新启动它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆