#1 2008-10-30 15:14:22
系統啟動檔的另類做法
我的硬碟有兩顆
$ mount
/dev/root on / type squashfs (ro)
none on /dev type devfs (rw)
proc on /proc type proc (rw)
ramfs on /tmp type ramfs (rw)
usbfs on /proc/bus/usb type usbfs (rw)
/dev/discs/disc0/part5 on /tmp/mnt/disc0_5 type ext3 (rw,noatime)
/dev/discs/disc4/part5 on /tmp/mnt/disc4_5 type ext3 (rw,noatime)
/dev/discs/disc4/part5 on /opt type ext3 (rw,noatime)
/dev/discs/disc0/part5 on /mnt type ext3 (rw,noatime)
pre-mount, 檢查磁碟
$ cat /usr/local/sbin/pre-mount
#!/bin/sh
Opt=/dev/discs/disc4/part5
Mnt=/dev/discs/disc0/part5
_fscheck() {
test -b $Opt && fsck.ext3 -p $Opt 2>> /tmp/syslog.log
test -b $Mnt && fsck.ext3 -p $Mnt 2>> /tmp/syslog.log
}
_fscheck
post-mount, 虛擬記憶體, 掛載硬碟, 執行自己的script
$ cat /usr/local/sbin/post-mount
#!/bin/sh
TmpMnt=/tmp/mnt/disc4_5
Opt=/dev/discs/disc4/part5
Swap=/dev/discs/disc4/part6
Mnt=/dev/discs/disc0/part5
_mount() {
test -b $Opt && mount $Opt /opt 2>> /tmp/syslog.log
test -b $Mnt && mount $Mnt /mnt 2>> /tmp/syslog.log
}
_swapon() {
test -b $Swap && swapon $Swap 2>> /tmp/syslog.log
}
if [ -d $TmpMnt ] ; then
_swapon
_mount
fi
if [ -d /opt/MyScript ] ; then
for s in /opt/MyScript/run*.sh ; do
if [ -x $s ] ; then
echo -e "\nRun My $s ..." >> /tmp/syslog.log
$s
echo -e "Done.\n" >> /tmp/syslog.log
fi
done
fi
自訂編號執行順序
$ ls -al /opt/MyScript/
drwxr-xr-x 2 admin root 1024 Oct 30 15:03 .
drwxr-xr-x 17 admin root 1024 Oct 30 08:44 ..
-rwxr-xr-x 1 admin root 259 Oct 30 12:13 run01optware.sh
-rw-r--r-- 1 admin root 0 Oct 30 15:03 test.sh
要執行的Optware
$ ls -al /opt/etc/init.d/
drwxr-xr-x 2 admin root 1024 Oct 30 08:16 .
drwxr-xr-x 5 admin root 1024 Oct 30 08:16 ..
-rwxr-xr-x 1 admin root 809 Oct 24 04:07 S80lighttpd
執行Optware
$ cat /opt/MyScript/run01optware.sh
#!/bin/sh
if [ -d /opt/etc/init.d ] ; then
for s in /opt/etc/init.d/S* ; do
if [ -x $s ] ; then
echo -e "\tStarting Optware $s ..." >> /tmp/syslog.log
$s start 1> /dev/null 2>> /tmp/syslog.log
echo -e "\tFinish." >> /tmp/syslog.log
fi
done
fi
Status & Log - System Log
...
Jan 1 08:00:44 kernel: Adding Swap: 65036k swap-space (priority -1)
Run My /opt/MyScript/run01optware.sh ...
Starting Optware /opt/etc/init.d/S80lighttpd ...
Finish.
Done.
Jan 1 08:00:52 pppd[287]: no device specified and stdin is not a tty
...
若您了解上述檔案的過程, 可再自己修改post-firewall, pre-shutdown等
離線