2012-08-03 56 views
1

编辑:我正在关注this examplerc.d脚本在/ run/daemons中查找我的二进制文件

试图为mongod编写archlinux rc.d脚本。我把我的二进制文件放在/usr/bin。以下是我走到这一步:

#!/bin/bash 

# import predefined functions 
. /etc/rc.conf 
. /etc/rc.d/functions 

# Point to the binary 
DAEMON=/usr/bin/mongod 

# Get the ARGS from the conf 
. /etc/conf.d/crond 

# Function to get the process id 
PID=$(get_pid $DAEMON) 

case "$1" in 
    start) 
    stat_busy "Starting $DAEMON" 
    # Check the PID exists - and if it does (returns 0) - do no run 
    [ -z "$PID" ] && $DAEMON $ARGS $> /dev/null 
    if [ $? = 0 ]; then 
     add_daemon $DAEMON 
     stat_done 
    else 
     stat_fail 
     exit 1 
    fi 
    ;; 
    stop) 
     stat_busy "Stopping $DAEMON" 
    kill -HUP $PID &>/dev/null 

    rm_daemon $DAEMON 
    stat_done 
    ;; 
    restart) 
     $0 stop 
    sleep 1 
    $0 start 
    ;; 
    *) 
     echo "usage: $0 {start|stop|restart}" 
esac 

的问题是,当我做sudo rc.d start mongod,我得到以下错误:

:: Starting /usr/bin/mongod                     
[BUSY] /etc/rc.d/functions: line 203: /run/daemons//usr/bin/mongod: No such file or directory 
                               [DONE] 
+1

什么是'的/ etc/rc.d中/ functions'线203:

我上线使用$>代替&>? – 2012-08-03 14:00:58

+1

没关系!问题是我使用'$>'而不是'&>'。 – drozzy 2012-08-03 14:02:37

回答

1

语法错误。

[ -z "$PID" ] && $DAEMON $ARGS $> /dev/null