Results 1 to 7 of 7

Thread: startup script won't start at bootup

  1. #1
    Join Date
    Feb 2007
    Location
    Seattle, WA
    Beans
    146
    Distro
    Ubuntu 10.10 Maverick Meerkat

    startup script won't start at bootup

    I have a little script that pings 4.2.2.2 and increments a counter every 60 seconds. If the internet is down >= 10 minutes, a reboot command is issued to the system. The script works perfectly. I put my script in /usr/sbin. I can run it manually and see that it works. I created an entry in /etc/init.d to start the script at startup. I initialized it with update-rc.d wanwatchdogstart defaults. I can see its entries under /etc/rc*.d. However, the script doesn't appear to be running at all. I have some echo's in the script as a test. In other scripts these will appear in tty7.

    Any ideas what would cause a startup script to just not run?

  2. #2
    Join Date
    May 2008
    Location
    my(@HOME, -$NJ)
    Beans
    296
    Distro
    Ubuntu 14.04 Trusty Tahr

    Re: startup script won't start at bootup

    Try this name your file starting with K99 and save it to /etc/rc0.d

    don't know why but it worked for me...

    and just a question why have it reboot instead of restarting your network service?

    /etc/init.d/networking restart

  3. #3
    Join Date
    May 2010
    Location
    uk
    Beans
    9,249
    Distro
    Xubuntu 14.04 Trusty Tahr

    Re: startup script won't start at bootup

    Hi

    The usual technique is to put the actual script itself into /etc/init.d and use update-rc.d to create links to the actual script and not any references to it.

    Also, the scripts are run by root and, consequently, don't have your user environment. So use full paths and set up things like displays.

    Kind regards
    Last edited by matt_symes; December 7th, 2010 at 04:14 AM.
    If you believe everything you read, you better not read. ~ Japanese Proverb

    If you don't read the newspaper, you're uninformed. If you read the newspaper, you're mis-informed. - Mark Twain

    Thinking about becoming an Ubuntu Member?

  4. #4
    Join Date
    Jun 2006
    Location
    Melbourne, Australia
    Beans
    265
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: startup script won't start at bootup

    Quick and simple answer is to put your script in /etc/rc.local

  5. #5
    Join Date
    May 2010
    Location
    uk
    Beans
    9,249
    Distro
    Xubuntu 14.04 Trusty Tahr

    Re: startup script won't start at bootup

    Hi

    ..or have it as a cron job and let that handle calling the script every 60 seconds You've got to love Linux.

    This will still apply though...

    Also, the scripts are run by root and, consequently, don't have your user environment.
    Kind regards
    Last edited by matt_symes; December 7th, 2010 at 06:54 AM.
    If you believe everything you read, you better not read. ~ Japanese Proverb

    If you don't read the newspaper, you're uninformed. If you read the newspaper, you're mis-informed. - Mark Twain

    Thinking about becoming an Ubuntu Member?

  6. #6
    Join Date
    Feb 2007
    Location
    Seattle, WA
    Beans
    146
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: startup script won't start at bootup

    Quote Originally Posted by alienprdkt View Post
    Try this name your file starting with K99 and save it to /etc/rc0.d

    don't know why but it worked for me...

    and just a question why have it reboot instead of restarting your network service?

    /etc/init.d/networking restart
    Thanks for all of the suggestions thus far. Firstly, this is a mini itx computer running shorewall as a router with a Verizon aircard as its WAN interface. The problem that I've run into is that since they started rolling out the LTE network changes, all of the modems have started sporadically getting stuck in a state where they "think" they are connected, yet I can't get to their static I.P.'s and they can't get out to anyone on the internet. The only way to fix this is to power cycle the aircard, which is most easily done by rebooting the machine.

    I tried renaming the rc2.d folder's symlink to my starter script and it has booted now. Before it begin with S20, I believe. Anyway, I will test that it's actually doing what it was designed to do and post back with all of my scripts for reference.

    Also, I decided to break the scripts out into two different places so that I could call the script manually if I wanted to, but it could also be started from within the init.d scripts. So, my /etc/init.d/wanwatchdogstart follows the basic debian startup script rules(I think anyway) and can be called to startup, shutdown etc. All of the actual coding and changes then are in my real script, /usr/sbin/wanwatchdog .

  7. #7
    Join Date
    Feb 2007
    Location
    Seattle, WA
    Beans
    146
    Distro
    Ubuntu 10.10 Maverick Meerkat

    Re: startup script won't start at bootup

    I have determined that my /etc/init.d/wanwatchdogstart script runs if another script I have is stopped. This script, which I call usbmodemstart, automatically starts and manages the aircard using wvdial.

    Let me start from the beginning. I have a script at /etc/init.d/usbmodemstart

    Code:
    #! /bin/sh
    
    APP_PATH=/usr/sbin/monusbmodem
    
    # script name
    NAME=usbmodemstart
    
    # app name
    DESC=usb modem startup script
    
    #exit automatically if some variable isn't set
    set -e
    
    
    case "$1" in
      start)
            echo -n "Starting $DESC: "
            /usr/sbin/monusbmodem
    	;;
    
      stop)
            echo -n "Stopping $DESC: "
            start-stop-daemon --stop --name sh monusbmodem
    	;;
    
      restart|force-reload)
            echo -n "Restarting $DESC: "
    	start-stop-daemon --stop --name sh monusmodem
    	sleep 5
            /usr/sbin/monusbmodem
            ;;
      *)
            N=/etc/init.d/$NAME
            echo "Usage: $N {start|stop|restart|force-reload}" >&2
            exit 1
            ;;
    esac
    
    exit 0
    I put this script as a startup item by running:

    Code:
    sudo update-rc.d usbmodemstart defaults
    That script calls the program /usr/sbin/monusbmodem

    Code:
    while [ 1 ] 
    sleep 5
    do
    	running=`ps -C wvdial | grep wvdial`
    	if [ -z $running ]; then
    		echo "wvdial NOT working"
    		sleep 30
    		running2=`ps -C  wvdial | grep wvdial`
    		if [ -z $running2 ]; then
    			echo "starting wvdial now"
    			killall wvdial
    			/usr/sbin/usbmodem
    		fi
    
    	else 
    		echo "wvdial working"
    	fi
    
    done
    Which monitors for the wvdial process. If it is running then it waits 5 seconds and runs again. If it is not, it waits another 30 seconds and if it's still not running it kills any instances of wvdial just to be sure, and then starts the usbmodem script

    Code:
    eject /dev/sr0
    wvdial &
    sleep 10
    route del default
    route add default dev ppp0
    shorewall start
    This script ejects the aircards mountable disk if applicable, runs wvdial, and sets up the firewall so that everyone can access the internet through this machine. These scripts have been doing their job for months without any real problems. That is, until our aircards suddenly started getting into a state where they think they're connected, but no real WAN connectivity exists.

    When I stop the usbmodemstart, my wanwatchdog scripts starts. I do notice that the monusbmodem and usbmodem scripts are still active in the processes. Something is wrong, I'm just not sure what.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •