可以用一个新的版本替换bash脚本导致脚本的运行实例失败 [英] Could replacing a bash script with a new version cause a running instance of the script to fail

查看:202
本文介绍了可以用一个新的版本替换bash脚本导致脚本的运行实例失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从一台服务器上的Java程序运行bash脚本。我刚刚上传脚本打算脚本使用的版本在下次运行的新版本。我不是故意打断脚本的现有的,正在运行的实例。不过,我刚刚接到超过100通报的崩溃从我的300台服务器。我猜更换运行bash脚本用新版本导致此。然而,这将要求在运行bash脚本从盘读出,因为它得到每个新步骤。这究竟是怎么运作的?

I am running bash scripts from java programs on a server. I just uploaded a new version of the script intending the next run of the script to use the version. I did not mean to interrupt the existing, running instances of the script. However, I just received over 100 notifications of crashes from my 300 servers. I'm guessing replacing the running bash script with a new version caused this. However, this would require that the running bash script is reading from the disk as it gets to each new step. Is this how it works?

在bash脚本的运行版本上运行一些光线追踪软件。每次运行需要2个小时。分步骤花5分钟和1.5小时之间。该脚本始终报告完成的脚本中的步骤之后崩溃。它永远不会崩溃报告已经在运行的子步骤。有些崩溃报告中未发现我不能在脚本中找到的命令。不同的崩溃报告不同的地方。

The running versions of the bash script run some ray tracing software. Each run takes 2 hours. Sub-steps take between 5 minutes and 1.5 hours. The script always reports crashing after finishing a step in the script. It never reports crashing an already running sub-step. Some crashes report not finding commands that I cannot find in the script. Different crashes report different places.

帮助!

编辑:我复制脚本使用scp所有300台服务器。该文件被替换的文件系统上。这不是一个共享文件。

I copied the script to all 300 servers using scp. The file was replaced on the file system. This is not a shared-file.

推荐答案

SiegeX是说对了一半 - 庆典将加载整个脚本到内存中,这样一个脚本可以继续即使运行,如果它的源文件被删除,而这个过程是运行。但也庆典将检查脚本运行时的源文件是否更新。如果已经,庆典将<击>重新加载它,并继续从当前位置运行它重新打开文件,寻找到脚本的当前位置,并继续从该点运行脚本。

SiegeX is half right - bash will load an entire script into memory, so a script can continue to run even if it's source file is deleted while the process is running. But bash will also check whether the source file is updated while the script is running. If it has been, bash will reload it and continue running it from the current position reopen the file, seek to the current position of the script, and continue running the script from that point.

下面是验证概念的脚本:

Here's a proof-of-concept script:

# If you modify a script, will it change the behavior of
# processes that are currently running that script?
# Does this script print "Foo" or "Bar"?

cat >foo.sh <<EOF
sleep 5
echo Foo
EOF

bash foo.sh &
sleep 2

cat >foo.sh <<EOF
sleep 5
echo Bar
EOF

wait

所以,如果你关心当前正在运行该脚本过程的结果是不改变的bash脚本的源文件。

So the upshot is don't modify the source files of bash scripts if you care about the processes that are currently running that script.

(该脚本,但是,显示富的bash脚本的。当前位置始终是在一行的开头或结尾)。

(This script, however, displays "Foo". The "current position" of the bash script is always at the beginning or end of a line.)

echo "sleep 5 ; echo Foo" > foo.sh
bash foo.sh &
sleep 2
echo "sleep 5 ; echo Bar" > foo.sh
wait

这篇关于可以用一个新的版本替换bash脚本导致脚本的运行实例失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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