首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为什么这个Debian服务不会自动启动?启动后手动启动服务。

为什么这个Debian服务不会自动启动?启动后手动启动服务。
EN

Stack Overflow用户
提问于 2014-07-29 19:45:19
回答 1查看 376关注 0票数 0

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

代码语言:javascript
复制
#!/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

该机构有755个分支机构,归根所有。设置权限后,我做了(没有错误):

代码语言:javascript
复制
update-rc.d mnt defaults

当我在启动后立即手动启动服务时,它运行良好。

问题可能在哪里?使用此服务作为自动启动Samba的必要先决条件也是很好的--它有可能吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-08-18 10:07:49

解决办法很简单。我只将truecrypt安装为二进制文件,并且只为用户设置了truecrypt环境变量路径,而不是根用户或用于自动启动的任何其他系统用户。

解决方案是将truecrypt命令更改为/path_to_truecrypt/truecrypt

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25023676

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档