copy initial logs from tmpfs to HostVG/Logging use lsof to find services with opened logfiles Signed-off-by: Alan Pevec <apevec at redhat.com> --- scripts/ovirt-functions | 42 +++++++++++++++++++++++++++++++++++++----- 1 files changed, 37 insertions(+), 5 deletions(-) diff --git a/scripts/ovirt-functions b/scripts/ovirt-functions index 5385843..ba11856 100755 --- a/scripts/ovirt-functions +++ b/scripts/ovirt-functions @@ -277,7 +277,23 @@ mount_config() { fi } +# stop any service which keeps /var/log busy +# keep the list of services +unmount_logging_services() { + # mapping command->service is lame, but works for most initscripts + services+ cd /etc/init.d + for prg in $(lsof -Fc +D /var/log|grep ^c|sort -u); do + srv=$(grep -l ${prg#c}$ *) + service $srv stop + services="$services $srv" + done + # debugging help + lsof +D /var/log +} + # mount logging partition +# this only gets executed when disk is re-partitioned, HostVG/Logging is empty mount_logging() { if grep -q " /var/log ext3" /proc/mounts; then return 0 @@ -286,11 +302,21 @@ mount_logging() { if [ -e /dev/HostVG/Logging ] ; then log "Mounting log partition" - mount /dev/HostVG/Logging /var/log + # temporary mount-point + mkdir -p /var/log2 + mount /dev/HostVG/Logging /var/log2 + unmount_logging_services + # save logs from tmpfs + cp -av /var/log/* /var/log2 # save temporary log - cp /tmp/ovirt.log /var/log/ovirt.log-tmp + if [ -e /tmp/ovirt.log ]; then + cp /tmp/ovirt.log /var/log2/ovirt.log-tmp + fi + mount --move /var/log2 /var/log restorecon -rv /var/log - service rsyslog restart + for srv in $services; do + service $srv start + done return 0 else @@ -306,13 +332,19 @@ unmount_logging() { fi log "Unmounting log partition" - service rsyslog stop # plymouthd keeps /var/log/boot.log plymouth --quit plymouth --wait + unmount_logging_services umount /var/log - service rsyslog start + rc=$? + if [ $rc -ne 0 ]; then + return $rc + fi + for srv in $services; do + service $srv start + done return 0 } -- 1.6.0.6
Darryl L. Pierce
2009-Feb-24 15:36 UTC
[Ovirt-devel] [PATCH node] fix /var/log persistence
On Tue, Feb 24, 2009 at 02:14:57AM +0100, Alan Pevec wrote:> copy initial logs from tmpfs to HostVG/Logging > use lsof to find services with opened logfiles > > Signed-off-by: Alan Pevec <apevec at redhat.com> > --- > scripts/ovirt-functions | 42 +++++++++++++++++++++++++++++++++++++----- > 1 files changed, 37 insertions(+), 5 deletions(-)ACK with one comment/question.> # mount logging partition > +# this only gets executed when disk is re-partitioned, HostVG/Logging is empty > mount_logging() { > if grep -q " /var/log ext3" /proc/mounts; then > return 0 > @@ -286,11 +302,21 @@ mount_logging() { > if [ -e /dev/HostVG/Logging ] ; then > log "Mounting log partition" > > - mount /dev/HostVG/Logging /var/log > + # temporary mount-point > + mkdir -p /var/log2Would it be better to use mktemp -d here to generate a path name? -- Darryl L. Pierce, Sr. Software Engineer @ Red Hat, Inc. Virtual Machine Management - http://www.ovirt.org/ Is fearr Gaeilge bhriste n? B?arla cliste. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 197 bytes Desc: not available URL: <http://listman.redhat.com/archives/ovirt-devel/attachments/20090224/d0175cb3/attachment.sig>