Page 1 of 2 12 LastLast
Results 1 to 10 of 17

Thread: How to make a process run at startup

  1. #1
    Join Date
    Dec 2010
    Location
    Ankara, Turkey
    Posts
    250

    Default How to make a process run at startup

    Hi,

    I am trying to make a file run at startup (e.g. runlevel 5). Here is what I done;

    Copied file to /etc/init.d/rc5.d with these permissions:

    -rwx------ 1 root root 274 Mar 17 08:33 noip2.sh

    Contents of this file is:

    Code:
    #! /bin/sh
    # . /etc/rc.d/init.d/functions  # uncomment/modify for your killproc
    case "$1" in
    start)
    echo "Starting noip2."
    /usr/local/bin/noip2
    ;;
    stop)
    echo -n "Shutting down noip2."
    killproc -TERM /usr/local/bin/noip2
    ;;
    *)
    echo "Usage: $0 {start|stop}"
    exit 1
    esac
    exit 0
    And the file this is supposed to run is in /usr/local/bin/noip2 with the permissions as:

    -rwxr-xr-x 1 root root 80431 Mar 17 08:16 noip2

    However, this didn't worked for me. What can I do?

    Edit: I can run shell file by invoking it with terminal. So there is no problem with the file
    Last edited by yasar11732; 17-Mar-2011 at 00:41. Reason: Addition
    The only problem with troubleshooting is that sometimes trouble shoots back.
    My blog (in Turkish): http://yasar.serveblog.net

  2. #2

    Default Re: How to make a process run at startup

    You're missing some parts. Your script has to be LSB (and better also chkconfig) compliant. Look at that one:
    automatically recompile kernel modules after kernel update.
    You can look at any script in /etc/init.d as an example, but that one is simple. There should also be a sample script somewhere ... don't remember how it's called.

  3. #3

    Default Re: How to make a process run at startup

    I also have a function (part of a larger script) which makes any foreign init script LSB compliant. I haven't used it yet on 11.4 as all scripts looked fine. I don't need to explain it to you, as I know you are good.

    Code:
    function lsb {
    
    for iscript in `find /etc/init.d -maxdepth 1 -type f -executable ! -name "*.local" ! -name "*.orig"` ; do
    	[ -f ${iscript}.orig ] && continue
    	grep -q '### BEGIN INIT INFO' $iscript && continue
    	case $(basename $iscript) in
    		single|halt|powerfail|rc|boot) continue ;;
    		*)
    		cp $iscript{,.orig}
    		echo "- making $iscript LSB compliant" 
    		s=$(basename $iscript)
    		sed -n '1,/^[^# ]/p' $iscript.orig | sed '$d' > $iscript
    		cat >> $iscript << EOFLSB
    # LSB compliant service control script
    #
    ### BEGIN INIT INFO
    # Provides:			$s
    # Required-Start:		\$remote_fs \$all
    # Should-Start:			
    # Required-Stop:		
    # Should-Stop:			
    # Default-Start:		3 5
    # Default-Stop:			0 1 2 6
    # Short-Description:		$s
    # Description:			Starts and stops $s
    ### END INIT INFO
    
    EOFLSB
    		sed -n '/^[^# ]/,$p' $iscript.orig >> $iscript
    		;;
    	esac
    done
    }
    IMHO This thread belongs to the development forum.

  4. #4
    Join Date
    Dec 2010
    Location
    Ankara, Turkey
    Posts
    250

    Default Re: How to make a process run at startup

    Thanks for your kind replies, but what you are saying is kind of too advanced for me. I also checked the link you gave, but it really didn't ring any bells for me. Can you explain it as "Making LSB compliant init script for dummies", or better yet, if it is not very time consuming to do, can you produce final product using your codes?
    The only problem with troubleshooting is that sometimes trouble shoots back.
    My blog (in Turkish): http://yasar.serveblog.net

  5. #5
    Join Date
    Feb 2009
    Location
    Spain
    Posts
    25,547

    Default Re: How to make a process run at startup

    On 2011-03-17 09:06, yasar11732 wrote:
    >
    > Hi,
    >
    > I am trying to make a file run at startup (e.g. runlevel 5). Here is
    > what I done;


    Reading material:

    man init.d
    /etc/init.d/README
    /etc/init.d/skeleton
    > http://doc.opensuse.org/products/ope...#sec.boot.init


    --
    Cheers / Saludos,

    Carlos E. R.
    (from 11.2 x86_64 "Emerald" at Telcontar)

  6. #6

    Default Re: How to make a process run at startup

    You script should look like that. That's what I said that you were missing some parts. Replace the text in red. I thought you would have come to that conclusion after taking a look at the other script I linked to.

    Code:
    #! /bin/sh
    # uncomment/modify for your killproc
    
    #: Title       :  bla bla bla
    #: Date Created: Thu Mar 17 03:40:41 PDT 2011
    #: Last Edit   : Thu Mar 17 03:40:41 PDT 2011
    #: Author      : yasar11732
    #: Version     : 1.0
    #: Description : bla bla bla
    
    
    # chkconfig: 35 30 70
    # description: bla bla bla
    #
    ### BEGIN INIT INFO
    # Provides:       this script 
    # Required-Start: $syslog
    # Required-Stop:
    # Default-Start:  2 3 5
    # Default-Stop:   0 1 6
    # Short-Description: bla bla bla
    ### END INIT INFO
    
    # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    case "$1" in
    start)
    echo "Starting noip2."
    /usr/local/bin/noip2
    ;;
    stop)
    echo -n "Shutting down noip2."
    killproc -TERM /usr/local/bin/noip2
    ;;
    *)
    echo "Usage: $0 {start|stop}"
    exit 1
    esac
    exit 0

  7. #7
    Join Date
    Feb 2009
    Location
    Spain
    Posts
    25,547

    Default Re: How to make a process run at startup

    On 2011-03-17 11:36, yasar11732 wrote:
    >
    > Thanks for your kind replies, but what you are saying is kind of too
    > advanced for me. I also checked the link you gave, but it really didn't
    > ring any bells for me. Can you explain it as "Making LSB compliant init
    > script for dummies", or better yet, if it is not very time consuming to
    > do, can you produce final product using your codes?


    It is easier than you think. Just copy and modify the skeleton script.

    --
    Cheers / Saludos,

    Carlos E. R.
    (from 11.2 x86_64 "Emerald" at Telcontar)

  8. #8
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,240

    Default Re: How to make a process run at startup

    Quote Originally Posted by please_try_again View Post
    There should also be a sample script somewhere ... don't remember how it's called.
    /etc/init.d/skeleton
    Henk van Velden

  9. #9
    Join Date
    Dec 2010
    Location
    Ankara, Turkey
    Posts
    250

    Default Re: How to make a process run at startup

    My new script:

    Resides as: -rwxr-xr-x 1 root root 1283 Mar 17 13:20 noip2 (in /etc/init.d)
    Code:
    #! /bin/sh
    # . /etc/rc.d/init.d/functions  # uncomment/modify for your killproc
    
    ### BEGIN INIT INFO
    # Provides:     noip
    # Required-Start:       network
    # Should-Start:
    # Required-Stop:        network
    # Default-Start:        5
    # Default-Stop: 0 1 2 6
    # Short-Description: noip2 daemon for reporting ip changes
    # Description: Reports ip address on change, so that dns record can be updated
    ### END INIT INFO
    NO_IP_BIN = /usr/local/bin/noip2
    test -x $NO_IP_BIN || {echo "No ip isn't installed";
            if[ "$1" = "stop" ]; then exit 0;
            else exit 5; fi}
    
    . /etc/rc.status
    rc_reset
    
    case "$1" in
    start)
    echo -n "Starting noip2."
    /sbin/startproc $NO_IP_BIN
    rc_status -v
    ;;
    stop)
    echo -n "Shutting down noip2."
    /sbin/killproc $NO_IP_BIN
    rc_status -v
    ;;
    try-restart|condrestart)
    if test "$1" = "condrestart"; then
    echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}"
    fi
    $0 status
    if test $? = 0; then
    $0 restart
    else
    rc_reset
    fi
    rc_status
    ;;
    restart)
    $0 stop
    $0 start
    rc_status
    force-reload)
    echo -n "Reload service noip"
    /sbin/killproc -HUP $NO_IP_BIN
    rc_status -v
    ;;
    reload)
    echo -n "Reload service noip"
    /sbin/killproc -HUP $NO_IP_BIN
    rc_status -v
    ;;
    status)
    echo -n "Checking for service noip"
    /sbin/checkproc $NO_IP_BIN
    rc_status -v
    ;;
    *)
    echo "Usage: $0 {start|stop}"
    exit 1
    esac
    rc_exit
    lrwxrwxrwx 1 root root 8 Mar 17 13:25 K13noip2 -> ../noip2
    lrwxrwxrwx 1 root root 8 Mar 17 13:25 S13noip2 -> ../noip2

    Is there anything else I need to check? Like some config files maybe?
    The only problem with troubleshooting is that sometimes trouble shoots back.
    My blog (in Turkish): http://yasar.serveblog.net

  10. #10
    Join Date
    Jun 2008
    Location
    Netherlands
    Posts
    25,240

    Default Re: How to make a process run at startup

    You should not make those links, only the script file itself in /etc/init.d.
    Then you can go to YaST > Software > Software services (runlevel) and you will find the name of your script in the list. Start from there and YaST will make all links accvording to your specifications in the LSB section.
    Henk van Velden

Page 1 of 2 12 LastLast

Posting Permissions

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