Plan 9 from Bell Labs’s /usr/web/sources/patch/applied/fshalt-drain/fshalt.orig

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#!/bin/rc
# halt - sync (flush) and, if possible, halt all file servers
rfork e
path=(/bin)
builtin cd /

f=`{ls /srv/fscons*>[2]/dev/null}
k=`{ls /srv/kfs*cmd >[2]/dev/null|sort -r}

echo -n syncing...
for(i in $f){
	echo -n $i...
	{
		echo fsys all sync
		if(! dial/expect -t 120 ': ')
			echo -n 'not synced...' > /dev/cons
	} < $i >> $i
}

echo -n venti...
venti/sync >[2]/dev/null

for (i in $k){
	echo -n $i... 
	switch($i){
	case /srv/kfs.cmd
		disk/kfscmd sync
	case *
		disk/kfscmd -n `{echo $i | sed -n 's%/srv/kfs.(.*).cmd%\1%p'} sync
	}
	sleep 2
}

# halting (binaries we run can't be on the fs we're halting)
ramfs
builtin cd /tmp
cp /bin/dial/expect /tmp
cp /bin/echo /tmp
cp /bin/disk/kfscmd /tmp
cp /bin/rc /tmp
cp /bin/sed /tmp
cp /bin/ns /tmp
cp /bin/iostats /tmp
mkdir /tmp/lib
cp /rc/lib/rcmain /tmp/lib
bind /tmp /rc
bind /tmp /bin

# put this in a shell function so this rc script doesn't get read
# when it's no longer accessible
fn x {
	echo
	echo -n halting...
	for(i in $f){
		echo -n $i...
		{
			echo fsys all halt
			if(! expect -t 60 ': ')
				echo -n 'not halted...' > /dev/cons
		} < $i >> $i
	}
	
	for (i in $k){
		echo -n $i... 
		switch($i){
		case /srv/kfs.cmd
			kfscmd halt
		case *
			kfscmd -n `{echo $i | sed -n 's%/srv/kfs.(.*).cmd%\1%p'} halt
		}
	}
	echo
	echo done
}

x

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.