tracd init script

2017-03-15  本文已影响14人  9682f4e55d71

将下面脚本命名未 tracd
放到 /etc/init.d/ 目录下
则可使用命令 service管理 服务, 如 service tracd start

#!/bin/bash
# desc: start and stop tracd

# source function library
. /etc/rc.d/init.d/functions

name=tracd  # 服务的命令, 如 php-fpm, nginx, redis-server 等
exec="/usr/bin/$name"
lockfile=/var/lock/subsys/$name
pidfile=/var/run/$name.pid 
options="--port 8000 /data/trac/myporject -d"

start() # 函数名必须要是 start
{
    echo -n $"staring $name: "
    daemon $exec $options --pidfile=${pidfile}
    retval=$?
    echo
    [ $retval -eq 0 ] && touch $lockfile
    return $retval
}

stop() # 函数名必须是 stop
{
    echo -n $"stopping $name: "
    #cat $pidfile | xargs kill -9
    killproc -p $pidfile $name
    retval=$?
    echo
    [ $retval -eq 0 ] && rm -f $lockfile $pidfile
    return $retval
}

rh_status()  # 获取状态函数不能使用 status, 否则会与引入文件同名冲突
{
    status -p $pidfile $name
}


restart()
{
    stop
    start
}

usage()
{
    echo $"Usage: $0 {start|stop|restart|status}"
    exit 2
}


case $1 in
    start)
        start
        ;;
    stop)
        stop
        ;;
    restart)
        restart
        ;;
    status)
        rh_status
        ;;
    *)
        usage
esac
exit $?

参考

  1. https://trac.edgewall.org/ticket/4352
  2. http://hao360.blog.51cto.com/5820068/1720699
  3. http://www.yolinux.com/TUTORIALS/LinuxTutorialInitProcess.html
  4. http://www.linux.com/feature/46892
上一篇下一篇

猜你喜欢

热点阅读