方法就三步秉剑。
一:將可執(zhí)行程序放入/usr/sbin/
中凄杯。
二:創(chuàng)建服務(wù)文件
服務(wù)文件是Linux shell文件麻掸,
位置是/etc/init.d/
,這里面的文件大多都是服務(wù)啟動(dòng)文件织狐,按照這些改寫骗绕。
三:創(chuàng)建連接文件
還需要?jiǎng)?chuàng)建一個(gè)指向服務(wù)文件的符號(hào)連接文件芹血,位置是/etc/rc3.d/
執(zhí)行Linux命令ln -sf 指向文件名 連接文件名
連接文件名的命名規(guī)則最好是S**指向文件名
贮泞,其中**代表的是啟動(dòng)順序(數(shù)字)。
創(chuàng)建服務(wù)文件示例:
#! /bin/sh
#注釋:上一句為指定執(zhí)行shell的語(yǔ)句
#chkconfig: 2345 40 40
#注釋:?jiǎn)?dòng)順序
#description: SimpleService is a simple game UDP service.
#注釋:服務(wù)描述
#processname: SService
#注釋:服務(wù)名稱
. /etc/rc.d/init.d/functions
#注釋:引入functions文件幔烛,其中包括daemon,killproc,status,必要
SSER_BIN="/usr/sbin/sser"
RETVAL=0
prog="SService"
case "$1" in
start)
echo -n $"Starting $prog: "
daemon SSER_BIN
#注釋:將程序啟動(dòng)為守護(hù)程序(服務(wù))
;;
stop)
echo -n $"Shutting down $prog: "
killproc $SSER_BIN
#注釋:將程序殺死
;;
restart)
$0 stop
$0 start
;;
status)
status $prog
#注釋:查看服務(wù)程序的狀態(tài)啃擦,程序中的標(biāo)準(zhǔn)輸出此時(shí)可見
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
RETVAL=1
esac
exit $RETVAL