Find the answer to your Linux question:
Results 1 to 4 of 4
I'm writing a little script using instructions from here to start and stop some bits and pieces when my system boots. Code: #! /bin/sh # /etc/init.d/bensbits # # Carry out ...
  1. #1
    Linux User stokes's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    274

    Debian init.d startup & shutdown scripts

    I'm writing a little script using instructions from here to start and stop some bits and pieces when my system boots.

    Code:
    #! /bin/sh
    # /etc/init.d/bensbits
    #
    
    # Carry out specific functions when asked to by the system
    case "$1" in
      start)
        echo "Starting PostgreSQL"
    
    su postgres
    /usr/local/pgsql/bin/postmaster -D /usr/local/pgsql/data >/tmp/logfile 2>&1 &
    exit
    
        echo "Starting PHP DNS Updater"
    
    php updateip.php >/dev/null &
    
        ;;
      stop)
        echo "Stopping script blah"
        echo "Could do more here"
        ;;
      *)
        echo "Usage: /etc/init.d/bensbits {start|stop}"
        exit 1
        ;;
    esac
    
    exit 0
    My question is, how can I gracefully end the processes I started? I know I can use ps | aux to get the process numbers and then kill them, but how can I automate this?
    Registered Linux user #389109
    My Semi-Linux Blog

  2. #2
    Linux Engineer Zelmo's Avatar
    Join Date
    Jan 2006
    Location
    Riverton, UT, USA
    Posts
    1,001
    The easier thing might be to use the killall command. It kills processes by name rather that PID.
    Stand up and be counted as a Linux user!

  3. #3
    Linux User stokes's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    274
    So if this is my process:
    Code:
    ps aux | grep php
    root     22308  0.0  0.5   8200  2332 ?        S    Apr19   0:00 php updateip.php
    Would this work?

    Code:
    killall "php updateip.php"
    Registered Linux user #389109
    My Semi-Linux Blog

  4. #4
    Linux Engineer Zelmo's Avatar
    Join Date
    Jan 2006
    Location
    Riverton, UT, USA
    Posts
    1,001
    Ooh, that's a tricky one, huh? I don't know if it would just kill the ipupdate thing, or all things related to php, or nothing at all. You might have to give the killall command a "live" test-run to see if it does the right thing.
    Stand up and be counted as a Linux user!

Posting Permissions

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