在/etc/init.d 下新建服务启停脚本
#!/bin/bash
#
# /etc/rc.d/init.d/myserviced
#
# Starts the at daemon
# Source function library.
. /etc/init.d/functions
test -x /usr/bin/myserviced || exit 0
RETVAL=0
#
# See how we were called.
#
prog="myserviced"
start() {
# Check if atd is already running
if [ ! -f /var/lock/subsys/myserviced ]; then
echo -n $"Starting $prog: "
/usr/bin/myserviced && success || failure
RETVAL=$?
touch /var/lock/subsys/myserviced
echo
fi
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc /usr/bin/myserviced
RETVAL=$?
rm -f /var/lock/subsys/myserviced
echo
return $RETVAL
}
restart() {
stop
sleep 1
start
}
reload() {
restart
}
status_at() {
status /usr/bin/myserviced
}
case "$1" in
start)
start
;;
stop)
stop
;;
boot)
start
;;
shutdown)
stop
;;
reload|restart)
restart
;;
condrestart)
if [ -f /var/lock/subsys/myserviced ]; then
restart
fi
;;
status)
status_at
;;
*)
echo $"Usage: $0 {start|stop|restart|condrestart|status}"
exit 1
esac
exit $?
exit $RETVAL
服务启动和停止:
service myserviced start/restart/stop/status