圆月山庄资源网 Design By www.vgjia.com

linux环境:ubuntu

复制代码 代码如下:
#! /bin/sh
# Provides:       server.sh
# Default-Start:  2 3 4 5
# Short-Description: server testing...

EXEC_PATH=/home/huangmin/cdev/project
EXEC=server
PID_FILE=/var/run/server.sh.pid
DAEMON=/home/huangmin/cdev/project/server

if ! [ -x $EXEC_PATH/$EXEC ]; then
  echo "ERROR:$EXEC_PATH/$EXEC not found ..."
  exit 1
fi

stop() {
  echo "Stopping $EXEC ..."
  killall $DAEMON >/dev/null
  rm -f $PID_FILE
  sleep 1
  echo "Shutting down $EXEC: [OK]"
}

start() {
  echo "Starting $EXEC ..."
  $DAEMON >/dev/null
  pidof $EXEC > $PID_FILE
  sleep 1
  echo "Starting $EXEC: [OK]"
}

restart() {
  stop
  start
}

case "$1" in
  start)
    start

  stop)
    stop

  restart)
    restart

  status)
    echo "Status Here"

  *)
    echo "Usage: service $EXEC {start|stop|restart|status}"
    exit 1
esac

exit $?

/home/huangmin/cdev/project/server是我们需要的作为系统服务的程序。
写好脚本之后,将其放置到目录/etc/init.d中,或者做成软链接形式如:sudo ln -s /home/huangmin/cdev/project/bash/server.sh /etc/init.d/servertest.sh
最后利用chkconfig命令将其添加进系统服务: chkconfig –add servertest.sh
可以使用命令service servertest.sh start马上启动该服务程序

标签:
Linux系统服务

圆月山庄资源网 Design By www.vgjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
圆月山庄资源网 Design By www.vgjia.com