How can I tell Solaris to delete all files (and subfolders) in directory /tmp
just before shutdown. The stuff should not be deleted manually by the user but automatically by the system.
If it easier zu achieve a delete at next startup/boot time whould be acceptable as well.
How does that work?
/tmp is a tmpfs filesystem on Solaris which means that it is not persistent over reboot. So this happens automatically.
Anything you see in /tmp after a reboot is because it has been newly created.
/var/tmp is not a tmpfs filesystem and does persist over reboot.
It would perhaps be more accurate to say that BY DEFAULT /tmp is a tmpfs filesystem which is not persistent across reboots. However, this doesn't have to be the case and given that the question is being asked this may not be the case on the host in question. if the system's /etc/vfstab contains something like the following line:
swap - /tmp tmpfs - yes -
then your /tmp is in memory and is not persistent. If that is not the case, restoring this line will restore the default behavior of storing /tmp in memory and making it non-persistent. If this is what you want, great. The contents of /tmp get deleted automatically when you reboot. [You may also want to consider putting a limit on the size of /tmp on this line - see the mount_tmpfs manual page for details.]
There are circumstances where you may prefer to not keep /tmp in memory and use file storage space instead. In that case you may want to have a script to delete files. You can do this at boot (or shutdown) using a SMF service or a legacy /etc/rc*.d script if you don't understand SMF. If you can use tmpfs that is easier.
While technically true, that is not a configuration that the Solaris installation methods supports creating. I'm also not sure if we would consider it a supported configuration any more. I'll check with some of my other senior Solaris engineering colleagues and see what the consensus is on wither a non tmpfs /tmp is supportable.
I've discussed the issue of a non tmpfs /tmp with my colleagues and we agreed that /tmp must be on tmpfs anything else is not
a supported configuration. While it isn't explicit that /tmp is tmpfs the filesystem(5) man page does say this:
Directory that contains temporary files that are removed
during a boot operation.
Now compare that to what it says about /var/tmp
Directory that contains files that vary in size or pres-
ence during normal system operations. The content of
this directory is not removed during a boot operation.
It is possible to change the default behavior for
/var/tmp to clear all of the files except editor tem-
porary files by setting the clean_vartmp property value
of the rmtmpfiles service. This is done with the follow-
# svccfg -s svc:/system/rmtmpfiles setprop\
options/clean_vartmp = "true"
# svcadm refresh svc:/system/rmtmpfiles:default
The solaris.smf.value.rmtmpfiles authorization is
required to modify this property.
A future release of Solaris may well enforce that /tmp is tmpfs because it may change when it gets mounted, similar to what has been done with /var/run -> /system/volatile (which is mounted by the kernel before init starts).
Senior Principal Engineer
Solaris Core Technologies
Thanks for clarifying this.
We use tmpfs at our site and my original comments were prompted by the consideration that by asking the question the user indicated that /tmp wasn't cleared upon reboot and therefore tmpfs probably wasn't being used at that site. I've been admininstering for Solaris for a long time and when tmpfs started being used here we ran into problems because some of our users had processing which involved dumping lots of data into /tmp which caused excessive paging. We resolved the problem by setting a limit on the size of /tmp and asking them to change their processing to use /var/tmp or other areas. Of course we could have decided that tmpfs is causing the problem so we'll just comment it out of /etc/vfstab. Apparently, we made the right choice at the time but it could have gone the other way. Particularly if we had had less control over our user activities.
It would appear that using tmpfs is the best choice if it is at all possible. And that avoids the need for cleanup scripts.