如何在机器自动关闭之前运行命令?
如何在机器自动关闭之前运行命令?
如何将脚本放在正确的运行级别? 我认为运行级别6是关闭的,然后要播放的目录是
/etc/rc6.d/
cron
不是这个的工具。 您需要设置一个在关机期间执行的upstart
作业,最好声明一个依赖项,以便它在需要关闭的任何服务之前运行。 man 5 init
有关如何正确定义启动或关闭任务的详细信息; 如果没有更多的信息,我无法帮助,因为这取决于你想要做什么以及它依赖的其他upstart
工作。
试试这个,将$HOME
和$PROFILE
替换$HOME
vapid值,并使用权限644
将其保存到~/.init
。
在你做任何事之前,确保有一条线
firefox /home/your_name/.mozilla/firefox/your_profile.default tmpfs size=128M,noauto,user,exec,uid=1000,gid=100 0 0
在/etc/fstab
,mount选项noauto
阻止tmpfs自动挂载,可以根据您的喜好更改为auto
。 我把它留在那里,以保持整体的新贵工作。
description "automatic firefox profile ram caching" start on started mountall stop on stopping mountall env HOME="/home/your_name" env PROFILE="your_profile.default" script if test -z "$(mount | grep -F "${HOME}/.mozilla/firefox/${PROFILE}" )" then mount "${HOME}/.mozilla/firefox/${PROFILE}" fi end script post-start script cd "${HOME}/.mozilla/firefox" if test -f packed.tar then tar xpf packed.tar echo "$(date): firefox profile unpacked to ram" >> unpack.log else tar xpf packed.tar.old echo "$(date): backup profile unpacked to ram" >> unpack.log fi touch "${PROFILE}/.unpacked" end script pre-stop script cd "${HOME}/.mozilla/firefox" if test -f "${PROFILE}/.unpacked" then tar --exclude '.unpacked' -cpf packed.tmp.tar "$PROFILE" mv packed.tar packed.tar.old mv packed.tmp.tar packed.tar rm "$PFORILE/.unpacked" echo "$(date) firefox profile packed from ram" >> pack.log else echo ".unpacked is missing. pack current session data to newfile" tar -cpf packed-$(date +%Y%m%d%H%M).tar "$PROFILE" fi end script
作为funicorn的答案的简化版本..一个新贵的工作,在/etc/init/foo.conf或〜/ .init / foo.conf:
start on starting rc RUNLEVEL=6 task exec myscript
这将运行,并阻止整个关闭,直到“myscript”退出。
这就是你所需要的一切。 请注意,用户作业(〜/ .init / foo.conf)是一个非常新的function,在我的12.04系统上使用ecryptfs / home不起作用,因此您可能只需将作业放在/ etc / init中。