cron isn't the tool for this. You need to set up an upstart job which executes during shutdown, preferably declaring a dependency so that it runs before any services it requires shut down. man 5 init for the details on how to properly define a startup or shutdown task; I can't help beyond that without more information, as it depends on what you're trying to do and what other upstart jobs it depends on.
in /etc/fstab, where the mount option noauto prevents tmpfs from being auto-mounted, which could be changed to auto to your preference. I leave it there to keep the whole upstart job in integrity.
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
As a simplified version of funicorn's answer.. an upstart job, either in /etc/init/foo.conf or as ~/.init/foo.conf :
start on starting rc RUNLEVEL=6
task
exec myscript
This will run, and block the entire shutdown until "myscript" exits.
That is all you need. Note that the user jobs (~/.init/foo.conf) are a very new feature and on my 12.04 system with ecryptfs /home do not work, so you may just have to put the job in /etc/init.
cron
isn't the tool for this. You need to set up anupstart
job which executes during shutdown, preferably declaring a dependency so that it runs before any services it requires shut down.man 5 init
for the details on how to properly define a startup or shutdown task; I can't help beyond that without more information, as it depends on what you're trying to do and what otherupstart
jobs it depends on.How about to put a script in the correct runlevel? I think runlevel 6 is shutdown, and then the directory to play in is
Try this one, replacing
$HOME
and$PROFILE
with vapid values and save it to~/.init
with permission644
.Before you do anything, make sure there is a line like
in
/etc/fstab
, where the mount optionnoauto
prevents tmpfs from being auto-mounted, which could be changed toauto
to your preference. I leave it there to keep the whole upstart job in integrity.As a simplified version of funicorn's answer.. an upstart job, either in /etc/init/foo.conf or as ~/.init/foo.conf :
This will run, and block the entire shutdown until "myscript" exits.
That is all you need. Note that the user jobs (~/.init/foo.conf) are a very new feature and on my 12.04 system with ecryptfs /home do not work, so you may just have to put the job in /etc/init.