Service 为什么Debian Linux服务赢得';自动启动?启动工作完成后手动启动服务

Service 为什么Debian Linux服务赢得';自动启动?启动工作完成后手动启动服务,service,debian,autostart,Service,Debian,Autostart,我使用的是无头RaspberryPi(Raspbian),我希望在系统启动时自动启动此服务: #!/bin/bash ### BEGIN INIT INFO # Provides: mnt # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-De

我使用的是无头RaspberryPi(Raspbian),我希望在系统启动时自动启动此服务:

#!/bin/bash
### BEGIN INIT INFO
# Provides:          mnt
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: mount/unmount volumes from /etc/fstab
### END INIT INFO

#VARIABLES for the truecrypt volume
PROTECT_HIDDEN=no
KEYFILES=""
PASSWORD_FILE=/etc/truecrypt

mount_all(){
    slot=0
    while read line;
    do
        read -a fields <<< $line
        VOLUME_PATH=${fields[0]}
        MOUNT_DIRECTORY=${fields[1]}
        FILESYSTEM=${fields[2]}
        OPTIONS=${fields[3]}
        slot=$((slot+1))

        truecrypt \
          --text \
          --verbose \
          --keyfiles=$KEYFILES \
          --protect-hidden=$PROTECT_HIDDEN \
          --slot=${slot} \
          --fs-options=$OPTIONS \
          --filesystem=$FILESYSTEM $VOLUME_PATH $MOUNT_DIRECTORY \
          < <(grep $VOLUME_PATH $PASSWORD_FILE | sed "s,^${VOLUME_PATH}:,,")  \
          | grep -v "Enter password for"

    done < <(grep '^##truecrypt' /etc/fstab | sed 's/##truecrypt://g')

}
# Function to redirect the output to syslog
log_to_syslog(){
    # Temporal file for a named pipe
    script_name=$(basename "$0")
    named_pipe=$(mktemp -u --suffix=${script_name}.$$)

    # On exit clean up
    trap "rm -f ${named_pipe}" EXIT

    # create the named pipe
    mknod ${named_pipe} p

    # start syslog and redirect the named pipe
    # append the script name before the messages
    logger <${named_pipe} -t $0 &

    # Redirect stout and stderr to the named pipe
    exec 1>${named_pipe} 2>&1
}

# If the script does not run on a terminal then use syslog
set_log_output(){
    if [ ! -t 1 ]; then
        log_to_syslog
    fi
}

case "$1" in
    ''|start)
        EXITSTATUS=0
        set_log_output
        mount_all || EXITSTATUS=1
        exit $EXITSTATUS
        ;;
    stop)
        EXITSTATUS=0
        set_log_output
        truecrypt --verbose --force --dismount || EXITSTATUS=1
        exit $EXITSTATUS
        ;;
    restart|force-reload)
        EXITSTATUS=0
        $0 stop || EXITSTATUS=1
        $0 start || EXITSTATUS=1
        exit $EXITSTATUS
        ;;
    status)
        EXITSTATUS=0
        truecrypt --list 2>/dev/null || echo "No truecrypt volumes mounted"
        exit $EXITSTATUS
        ;;
    *)
        echo "Usage: $0 [start|stop|restart]"
        exit 3
        ;;
esac
当我在启动后立即手动启动服务时,它运行良好


问题出在哪里?将此服务作为自动启动Samba所需的先决条件也很好-可能吗?

解决方案非常简单。我只将truecrypt作为二进制文件安装,并且我只为用户设置了truecrypt的环境变量路径,而不是root用户或任何其他用于autostart的系统用户

解决方案是将
truecrypt
命令改为
/path\u改为\u truecrypt/truecrypt

update-rc.d mnt defaults