Method One,
Edit/etc/rc.d/rc.local File
Format is program name program path
such as a.sh/home/a.sh
The second method
Just replace the your_prog_name with the name of your actual script or execution file, and set the Prog_path to a specific path.
| The code is as follows |
Copy Code |
|
# Vim/etc/init.d/your_prog_name
#!/bin/bash
#
# Comments to support Chkconfig
# Chkconfig:-98 02
# description:your_prog_name Service Script
#
# Source function library.
. /etc/init.d/functions
### Default variables
Prog_name= "Your_prog_name"
Prog_path= "/usr/bin/${prog_name}"
Pidfile= "/var/run/${prog_name}.pid"
Options= "-C Your_conf_file"
# Check If requirements are met
[-X "${prog_path}"] | | Exit 1
Retval=0
Start () {
Echo-n $ "Starting $prog _name:"
Daemon $prog _path $options
Retval=$?
pid=$ (Pidof ${prog_path})
[!-Z ' ${pid} '] && echo ${pid} > ${pidfile}
Echo
[$RETVAL-eq 0] && touch/var/lock/subsys/$prog _name
Return $RETVAL
}
Stop () {
Echo-n $ "Shutting down $prog _name:"
Killproc-p ${pidfile}
Retval=$?
Echo
[$RETVAL-eq 0] && rm-f/var/lock/subsys/$prog _name
Return $RETVAL
}
Restart () {
Stop
Start
}
Case "$" in
Start
Start
;;
Stop
Stop
;;
Restart)
Restart
;;
Status
Status $prog _path
Retval=$?
;;
*)
echo $ "Usage: $ {Start|stop|restart|status}"
Retval=1
Esac
Exit $RETVAL
# chmod +x/etc/init.d/your_prog_name
# Chkconfig Your_prog_name on
|