Find the answer to your Linux question:
Results 1 to 2 of 2
We need to create a Linux service which has to be run in the background. The service should run a java code. Startup and stop of this service should be ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Jun 2007
    Posts
    1

    How to create a Linux service(daemon)


    We need to create a Linux service which has to be run in the background.
    The service should run a java code. Startup and stop of this service should be able to control manually.

    Please help me out on this. It will be helpful if you provide the basic commands to create a service.

  2. #2
    Linux User cyberinstru's Avatar
    Join Date
    Jan 2007
    Location
    India
    Posts
    362
    Try this....


    Replace <myservice> with your daemon and put this script in /etc/init.d folder.

    Code:
    #!/bin/sh
    #
    # myservice     This shell script takes care of starting and stopping
    #               the <myservice>
    #
    
    # Source function library
    . /etc/rc.d/init.d/functions
    
    
    # Do preliminary checks here, if any
    #### START of preliminary checks #########
    
    
    ##### END of preliminary checks #######
    
    
    # Handle manual control parameters like start, stop, status, restart, etc.
    
    case "$1" in
      start)
        # Start daemons.
    
        echo -n $"Starting <myservice> daemon: "
        echo
        daemon <myservice>
        echo
        ;;
    
      stop)
        # Stop daemons.
        echo -n $"Shutting down <myservice>: "
        killproc <myservice>
        echo
    
        # Do clean-up works here like removing pid files from /var/run, etc.
        ;;
      status)
        status <myservice>
    
        ;;
      restart)
        $0 stop
        $0 start
        ;;
    
      *)
        echo $"Usage: $0 {start|stop|status|restart}"
        exit 1
    esac
    
    exit 0
    ---------------------------------
    Registered Linux User #440311
    HI2ARUN _AT_ GMAIL _DOT_ COM
    ---------------------------------

Posting Permissions

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