问题
While a Chef recipe is executing, I want to determine if there is sufficient free disk space available to perform an operation.
How best to do this?
回答1:
Ohai detects certain properties of a a node each time it is run. These properties are captured as automatic attributes and are available to you as node attributes.
The attribute node['filesystem'] contains information about each of the devices on your system. To get the space available in kb, for a specific device:
node['filesystem']['/dev/xvda1']['kb_available']
The following is an example of the filesystem attribute JSON from Ohai:
"filesystem": {
"/dev/xvda1": {
"kb_size": "521882300",
"kb_used": "119914572",
"kb_available": "375474240",
"percent_used": "25%",
"mount": "/",
"fs_type": "ext4",
"mount_options": [
"rw"
],
"uuid": "248b8180-f75f-48fc-a8be-e3ff3506c4d6"
},
"tmpfs": {
"kb_size": "1987292",
"kb_used": "0",
"kb_available": "1987292",
"percent_used": "0%",
"mount": "/dev/shm",
"fs_type": "tmpfs",
"mount_options": [
"rw",
"rootcontext=\"system_u:object_r:tmpfs_t:s0\""
]
}
}
回答2:
cron 'cron for checking disk space' do
minute '00'
hour '12'
command 'disk_space_check.sh'
user 'smj'
end
来源:https://stackoverflow.com/questions/14286709/how-can-i-find-the-disk-available-in-a-chef-recipe