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 :
- login as root
- create new file in /etc/init.d/ using this command :
# cd /etc/init.d/ # vi httpd
- 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
- save this file
- set file to be executable using this command
# chmod +x httpd
- install as service
chkconfig httpd on