Pages

Friday, April 19, 2013

How to create service in Linux


Sometimes we need to make our program automatically run when computer started.
To do this, we need to make our program as service and make it started when computer booted.
This time, we will discuss about how to create service in linux using httpd compiled as sample :
  1. login as root
  2. create new file in /etc/init.d/ using this command :
    # cd /etc/init.d/
    # vi httpd
    
  3. write this code below
    #!/bin/bash
    #
    # httpd: This shell script handle starting and stopping
    #
    # chkconfig: 35 80 30
    # description: httpd a application daemon, to handle web request dan response
    
    . /etc/rc.d/init.d/functions
    
    case "$1" in
    start)
            echo $"starting httpd"
            /usr/local/httpd/bin/apachectl start        
    ;;
    stop)
            echo $"stopping httpd"
            /usr/local/httpd/bin/apachectl stop
    ;;
    *)
            echo $"usage: $0 {start|stop}"
    esac
    
  4. save this file
  5. set file to be executable using this command
    # chmod +x httpd
    
  6. install as service
    chkconfig httpd on
    

No comments:

Post a Comment

Don't Forget To Join Our Community
×
Widget