Linux脚本在启动时设置运行级别并在网络启动之前启动

Linux脚本在启动时设置运行级别并在网络启动之前启动

我正在 init.d 中安装一个 Linux 脚本文件(SetUpScript),并在每个 rcX.d(包装符号链接)中将其运行级别设置为最低优先级,方法如下:-

#creating symbolic links of SetUpScript

ln -s /etc/init.d/SetUpScript /etc/rc0.d/K01SetUpScript
ln -s /etc/init.d/SetUpScript /etc/rc1.d/K01SetUpScript
ln -s /etc/init.d/SetUpScript /etc/rc6.d/K01SetUpScript
ln -s /etc/init.d/SetUpScript /etc/rc2.d/S99SetUpScript
ln -s /etc/init.d/SetUpScript /etc/rc3.d/S99SetUpScript
ln -s /etc/init.d/SetUpScript /etc/rc4.d/S99SetUpScript
ln -s /etc/init.d/SetUpScript /etc/rc5.d/S99SetUpScript

但问题是,当我的系统无法使用互联网时,它会很晚启动,但当互联网可用时,它会在 5-10 秒内启动。因此,我的所有依赖于 SetUpScript 的服务将在 15-20 分钟内很晚启动。所以我的问题是,当互联网不可用时,我如何才能从正常时间开始。我的程序通过访问某些硬件的Setupscript启动,因此我不想更改我的脚本运行级别并在5-10秒内启动它,就像系统可以使用互联网时一样。

我的 install.sh 文件是:

#!/bin/sh

sh uninstall.sh
if [ ! -f SoundMaxQ10-1101Setup.tar.gz ]; then
    echo "SoundMaxQ10-1101Setup.tar.gz doesn't exist"
    return
fi
DIR=SoundMaxQ10-1101Setup
HOMEDIR=/home/ubuntu
PMFOLDER=/usr/lib/pm-utils/sleep.d
ETC=/etc/init.d

# copy entire setup 


tar -xf SoundMaxQ10-1101Setup.tar.gz -C .
mv $DIR/SoundMaxQ10-1101 $HOMEDIR
mv $DIR/Setups $HOMEDIR
mv $DIR/SoundMaxStation $HOMEDIR


mv $DIR/StartGPIOread  $PMFOLDER/99StartGPIOread
mv $DIR/SetUpScript $ETC
mv $DIR/libAAC.so /usr/lib
mv $DIR/libATC_PreProcessor.so /usr/lib
mv $DIR/libmp3enc.so /usr/lib


rm -rf SoundMaxQ10-1101Setup
#rm -rf SoundMaxQ10-1101Setup.tar.gz

#changing permissions of scripts & elfs
chmod +x $HOMEDIR/Setups/dhcp.sh $HOMEDIR/Setups/static.sh $HOMEDIR/Setups/GetDhcpStatus.sh
chmod +x $HOMEDIR/Setups/SoundMaxDaemon $HOMEDIR/Setups/SoundMaxTFT $HOMEDIR/Setups/GpioReadScript
chmod +x $HOMEDIR/Setups/GPIORead
chmod +x $PMFOLDER/99StartGPIOread
chmod +x $ETC/SetUpScript
chmod +x $HOMEDIR/SoundMaxQ10-1101/daemon
chmod +x $HOMEDIR/SoundMaxQ10-1101/TFT
chmod +x $HOMEDIR/SoundMaxQ10-1101/rtpp

#creating symbolic links of SetUpScript

ln -s $ETC/SetUpScript /etc/rc0.d/K01SetUpScript
ln -s $ETC/SetUpScript /etc/rc1.d/K01SetUpScript
ln -s $ETC/SetUpScript /etc/rc6.d/K01SetUpScript
ln -s $ETC/SetUpScript /etc/rc2.d/S99SetUpScript
ln -s $ETC/SetUpScript /etc/rc3.d/S99SetUpScript
ln -s $ETC/SetUpScript /etc/rc4.d/S99SetUpScript
ln -s $ETC/SetUpScript /etc/rc5.d/S99SetUpScript
ldconfig -n -v /usr/lib

Setscript 文件是:

#!/bin/bash
PMFOLDER=/home/ubuntu/Setups
start()
{
   #pm-suspend
   if [ ! -d /sys/class/gpio/gpio200 ]; then
   echo 200 > /sys/class/gpio/export
   fi
   echo out > /sys/class/gpio/gpio200/direction
   echo 1 > /sys/class/gpio/gpio200/value
   echo performance > /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
   echo performance > /sys/devices/system/cpu/cpu1/cpufreq/scaling_governor
   echo performance > /sys/devices/system/cpu/cpu2/cpufreq/scaling_governor
   echo performance > /sys/devices/system/cpu/cpu3/cpufreq/scaling_governor
   iptables -P INPUT DROP
   iptables -A INPUT -p tcp --dport 15472 -j ACCEPT
   iptables -A INPUT -p tcp --dport 14334 -j ACCEPT
   iptables -A INPUT -p tcp --dport 14041 -j ACCEPT
   iptables -A INPUT -p tcp --dport 22 -j ACCEPT
   iptables -A INPUT -p udp --dport 20001 -j ACCEPT
   iptables -A INPUT -p tcp -m tcp --sport 8000 -j ACCEPT

   iptables -A INPUT -i lo -j ACCEPT
   sudo cp /usr/share/zoneinfo/Asia/Kolkata /etc/localtime
   sudo rm -rf /home/ubuntu/*.pid
   $PMFOLDER/StartGPIOread resume
   /home/ubuntu/Setups/SoundMaxDaemon start
   /home/ubuntu/Setups/SoundMaxTFT start
}
stop()
{
    $PMFOLDER/StartGPIOread suspend
    /home/ubuntu/Setups/SoundMaxDaemon stop
    /home/ubuntu/Setups/SoundMaxTFT stop
}
case $1 in
start)
  start
  ;;
stop)
  stop
  ;;
*) exit;;
esac

相关内容