我是新来的新手,我想知道是否有办法告诉新手只有在系统启动时执行特定的命令,而不是当应用程序随后从命令行重新启动。 例如,我有以下的新贵configuration:
#!upstart description "Hello World" author "me" start on (local-filesystems and net-device-up) stop on shutdown script export HOME="/root" echo $$ > /var/run/hello-world.pid exec /usr/local/bin/hello-world end script pre-start script # Date format same as (new Date()).toISOString() for consistency echo "[`date -u +%Y-%m-%dT%T.%3NZ`] Hello World Starting" >> /var/log/hello-world.sys.log end script pre-stop script rm /var/run/hello-world.pid echo "[`date -u +%Y-%m-%dT%T.%3NZ`] Hello World Stopping" >> /var/log/hello-world.sys.log end script
在启动时成功启动应用程序。 如果我执行:
/sbin/start hello-world
这将再次启动应用程序:我只想在系统启动时执行特定命令,而不是在启动应用程序时执行特定命令,如:
第一次执行:
第二次执行使用/sbin/start hello-world :
有没有办法做到这一点?
我有一个解决scheme,但它很丑陋。
所以.. /proc/uptime包含启动以来的秒数。
$ cat /proc/uptime 350735.47 234388.90
第一个数字是秒数,第二个数字是空闲秒数。
所以..
$UPTIME=$(cut -f1 -d' '< /proc/uptime) if [ $UPTIME -le 300 ] then /start/pre-run/script.sh fi
如果系统刚刚启动(或者300秒没有工作),将运行预运行脚本。 你可以调整300s到你的系统准备好的实际时间。
这是肮脏的地狱,但值得一试,对不对?
在/var/run *下面使用“cookie文件”。 只有当cookie文件不存在时才执行特定的启动脚本,并在成功执行后创build它。
*) 文件系统层次结构标准2.3
Files under this directory must be cleared (removed or truncated as appropriate) at the beginning of the boot process.