1

编辑:我正在关注这个例子

试图为 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]
4

1 回答 1

1

Syntax error.

I used $> instead of &> on the line:

[ -z "$PID" ] && $DAEMON $ARGS $> /dev/null
于 2012-08-03T14:03:05.347 回答