1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Startup Script running twice. Causes higher CPU usage.

Discussion in 'Tomato Firmware' started by but2002, Jun 10, 2010.

  1. but2002

    but2002 Networkin' Nut Member

    This script was taken off of the DD-WRT wiki, but the commands are fully features in Tomato (gpio is the only real one here)

    It's a script that shows router CPU through the SES light.

    Code:
    mkdir /var/wwwext
    cp /jffs/* /var/wwwext
    
    gpio="gpio"
    
    amber=3
    white=2
    
    delay=1
    
    meltdown=400
    overload=100
    highload=70
    medload=30
    
    while sleep $delay;do
     gpio enable 1
      set -- $(cat /proc/loadavg)
      load="${1%.*}${1#*.}"
    
      if [ $load -gt $meltdown ];then
        $gpio disable $amber
        usleep 50000
        $gpio disable $white
        usleep 50000
        reboot
      elif [ $load -gt $overload ];then
        $gpio disable $amber
        usleep 50000
       elif [ $load -gt $highload ];then
        $gpio disable $amber
        usleep 12500
        $gpio enable $amber
        usleep 12500
        $gpio disable $amber
        usleep 12500
        $gpio enable $amber
      elif [ $load -gt $medload ];then
        $gpio enable $amber
        $gpio disable $white
        usleep 25000
        $gpio enable $white
        usleep 25000
        $gpio disable $white
        usleep 25000
        $gpio enable $white
        usleep 25000
      else
        $gpio disable $white
        usleep 50000
      fi
    done


    Here's the issue.

    Sometimes, (more often than not) the script executes TWICE, causing higher than normal / needed CPU usage in the router.
    (I know this through SSH access, and I see two instances, and I have to kill one of them.)
    What's causing the script to execute twice? How can I make it kill it if it IS executing twice?

    The script is in the Init section of the scripts.
     
  2. rhester72

    rhester72 Network Guru Member

    Init is not guaranteed to run only once - once your script starts, it should create some sort of "check file" in /tmp or similar, and you should check for the presence of that file and silently exit if found to prevent this sort of thing.

    Rodney
     
  3. but2002

    but2002 Networkin' Nut Member

    I haven't the slightest clue on how to do that. Want to help me?


    EDIT:

    Here is my new script. Does it look good to you guys?

     
  4. rhester72

    rhester72 Network Guru Member

    This is (verbatim) what you have in Init?

    Rodney
     
  5. but2002

    but2002 Networkin' Nut Member

    That is the script that I have in the init section under script.

    The "initrunning" file is blank..
     
  6. rhester72

    rhester72 Network Guru Member

    It's not a very good idea to put Init itself in a loop like that because it will never end. I'd recommending using init to fire a script in the background that does the same thing, I posted an example script of just such a thing (a LED-based "CPU meter") quite some time ago that should be searchable. It doesn't operate -exactly- the same way as yours (in terms of how the LEDs are changed) but can be easily adapted.

    Rodney
     
  7. TexasFlood

    TexasFlood Network Guru Member

Share This Page