Results 1 to 10 of 10

Thread: Auto restarting daemon

  1. #1
    Join Date
    Sep 2005
    Beans
    19

    Auto restarting daemon

    I am trying to setup an SMS gateway using GAMMU. I have my phone and SMSD (sms daemon) configured properly. However, I wanted a way to autostart the daemon each time it stops. I searched around and found the following :

    I created a script at /usr/local/bin/smsd.sh with the following content :
    Code:
    #!/bin/sh
    export LANG=en_US
    /usr/bin/gammu-smsd -d
    Next, I created a file in /etc/init for upstart and named it as smsd.conf with the following content :

    Code:
    # smsd
    #
    # This service maintains the SMS Daemon from the point the system is
    # started until it is shut down again.
    
    description	"SMSD daemon"
    
    start on runlevel 3
    start on runlevel 4
    start on runlevel 5
    
    stop on runlevel 0
    stop on runlevel 1
    stop on runlevel 2
    stop on runlevel 6
    
    respawn
    exec /usr/local/bin/smsd.sh
    I tried starting SMS daemon via the command sudo /sbin/initctl start smsd but got the error :
    initctl: Job failed to start

    sudo /sbin/initctl status smsd gives me :
    smsd stop/waiting

    What am I doing wrong here? I need the daemon to run always so that it can grab messages off my connected phone at all times. Any help would be great at this point.

    UPDATE:
    I've updated the smsd.conf as follows :
    Code:
    # smsd
    #
    # This service maintains the SMS Daemon from the point the system is
    # started until it is shut down again.
    
    description	"SMSD daemon"
    
    start on runlevel [345]
    
    stop on runlevel [0126]
    
    respawn
    exec "/usr/local/bin/smsd.sh"
    sudo /sbin/initctl start smsd now gives me :
    smsd start/running, process 2870

    This means it executes the script and starts the daemon. Now, immediately when I run sudo /sbin/initctl status smsd, I get :
    smsd stop/waiting

    I'm confused!
    Last edited by uthfull; November 9th, 2009 at 08:46 PM.

  2. #2
    Join Date
    Feb 2007
    Location
    Romania
    Beans
    Hidden!

    Re: Auto restarting daemon

    The default runlevel in Ubuntu is 2, you probably don't want to stop your daemon on runlevel 2

    Code:
    # smsd
    #
    # This service maintains the SMS Daemon from the point the system is
    # started until it is shut down again.
    
    description	"SMSD daemon"
    
    start on runlevel [2345]
    
    stop on runlevel [016]
    
    respawn
    exec "/usr/local/bin/smsd.sh"

  3. #3
    Join Date
    Sep 2005
    Beans
    19

    Re: Auto restarting daemon

    I tried what you said and changed the runlevels accordingly and started the daemon but when I check the status it still gives me stop/waiting.

  4. #4
    Join Date
    Feb 2007
    Location
    Romania
    Beans
    Hidden!

    Re: Auto restarting daemon

    remove the quotes and add console output to redirect the output of your script to /dev/console:
    Code:
    # smsd
    #
    # This service maintains the SMS Daemon from the point the system is
    # started until it is shut down again.
    
    description	"SMSD daemon"
    
    start on runlevel [2345]
    
    stop on runlevel [016]
    
    respawn
    exec /usr/local/bin/smsd.sh
    console output
    Last edited by sisco311; November 9th, 2009 at 09:25 PM.

  5. #5
    Join Date
    Sep 2005
    Beans
    19

    Re: Auto restarting daemon

    As soon as I remove the quotes, I get nitctl: Job failed to start
    . If I put them back along with console output, I still get just smsd start/running, process 2739 and when I check the status it comes back as stop/waiting. Baffles me!

  6. #6
    Join Date
    Feb 2007
    Location
    Romania
    Beans
    Hidden!

    Re: Auto restarting daemon

    remove the -d flag from your script
    Code:
    #!/bin/sh
    export LANG=en_US
    /usr/bin/gammu-smsd
    or even better use the script stanza:
    Code:
    # smsd
    #
    # This service maintains the SMS Daemon from the point the system is
    # started until it is shut down again.
    
    description	"SMSD daemon"
    
    start on runlevel [2345]
    
    stop on runlevel [016]
    
    respawn
    
    script
      export LANG=en_US
      /usr/bin/gammu-smsd
    end script

  7. #7
    Join Date
    Sep 2005
    Beans
    19

    Re: Auto restarting daemon

    Some progress!! Removing "-d" flag does indeed keep the process running after it starts. But from the documentation of my script, I need to use to "-d" switch to daemonize the process. Any inputs here?

  8. #8
    Join Date
    Feb 2007
    Location
    Romania
    Beans
    Hidden!

    Re: Auto restarting daemon

    Quote Originally Posted by uthfull View Post
    Some progress!! Removing "-d" flag does indeed keep the process running after it starts. But from the documentation of my script, I need to use to "-d" switch to daemonize the process. Any inputs here?
    deamonize means to run it in the background, that's exactly what upstart does.

    check if gammu-smsd is working.
    Last edited by sisco311; November 9th, 2009 at 10:17 PM.

  9. #9
    Join Date
    Sep 2005
    Beans
    19

    Re: Auto restarting daemon

    Oops! Sorry for being kinda stupid there! Thanks for all the help. You're a lifesaver. I guess the problem is sort of resolved here. Now that the process runs in the background, my work will be easier. Thanks again!

  10. #10
    Join Date
    Oct 2010
    Beans
    1

    Re: Auto restarting daemon

    Quote Originally Posted by sisco311 View Post
    remove the -d flag from your script
    Code:
    #!/bin/sh
    export LANG=en_US
    /usr/bin/gammu-smsd
    or even better use the script stanza:
    Code:
    # smsd
    #
    # This service maintains the SMS Daemon from the point the system is
    # started until it is shut down again.
    
    description    "SMSD daemon"
    
    start on runlevel [2345]
    
    stop on runlevel [016]
    
    respawn
    
    script
      export LANG=en_US
      /usr/bin/gammu-smsd
    end script


    i try but not work in my lucid , what wrong?

Tags for this Thread

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
  •