创建linux服务,使得test client可以开机启动,步骤如下:
1.创建目录/usr/local/test/
2.复制testc到/usr/local/test/
3.编写文件/etc/init.d/testc.sh
testc.sh
--------------------begin(not included)-----------------------
#! /bin/sh
#
### BEGIN INIT INFO
# Provides: test
# Required-Start: $local_fs $network
# Required-Stop: $local_fs $network
# Should-Start: $named
# Should-Stop: $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Linux test Client
### END INIT INFO
NAME=testc.sh
DAEMON=/usr/local/test/testc
. /lib/lsb/init-functions
PATH=/bin:/usr/bin:/sbin:/usr/sbin
[ -x $DAEMON ] || exit 0
#
# Try to increase the # of filedescriptors we can open.
#
start () {
log_daemon_msg "Start Linux Client"
sleep 10s
#use the current network interface card.
ifup eth0
sleep 10s
#use the current virtual site,username and password.
nohup /usr/local/test/testc 192.168.49.20 t t &
return $?
}
stop () {
log_daemon_msg "Stop Linux Client"
nohup /usr/local/test/testc stop
}
case "$1" in
start)
log_daemon_msg "Starting Linux Client" "test"
if start ; then
log_end_msg $?
else
log_end_msg $?
fi
;;
stop)
log_daemon_msg "Stopping Linux Client" "test"
if stop ; then
log_end_msg $?
else
log_end_msg $?
fi
;;
*)
echo "Usage: /etc/init.d/$NAME {start|stop}"
exit 3
;;
esac
exit 0
--------------------end(not included)-------------------------------
4.生成链接
ln -s /etc/init.d/testc.sh /etc/rc2.d/S99testc.sh
ln -s /etc/init.d/testc.sh /etc/rc3.d/S99testc.sh
ln -s /etc/init.d/testc.sh /etc/rc4.d/S99testc.sh
ln -s /etc/init.d/testc.sh /etc/rc5.d/S99testc.sh