我使用的是无头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该机构有755个分支机构,归根所有。设置权限后,我做了(没有错误):
update-rc.d mnt defaults当我在启动后立即手动启动服务时,它运行良好。
问题可能在哪里?使用此服务作为自动启动Samba的必要先决条件也是很好的--它有可能吗?
发布于 2014-08-18 10:07:49
解决办法很简单。我只将truecrypt安装为二进制文件,并且只为用户设置了truecrypt环境变量路径,而不是根用户或用于自动启动的任何其他系统用户。
解决方案是将truecrypt命令更改为/path_to_truecrypt/truecrypt。
https://stackoverflow.com/questions/25023676
复制相似问题