目录

Raspberry pi 上安装 btsync(rslsync) 并设置服务

目录
  1. 创建独立用户
1
sudo adduser --quiet --system --group --disabled-password rslsync
  1. 下载 rslsync 并解压缩到 /home/rslsync/.rslsync

  2. 使用 –dump-sample-config 指令参数导出样例配置文件,并进行进一步配置

  3. 创建服务运行脚本

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
#! /bin/sh
### BEGIN INIT INFO
# Provides: rslsync daemon
# Required-Start: $syslog
# Required-Stop: $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: RSLSync server daemon
# Description: Daemon script to run a RSLSync permanent peer
# Placed in /etc/init.d.
### END INIT INFO
# Author: Nicolas Bernaerts < nicolas.bernaerts@laposte.net>
# Version:
#  V1.0, 06/09/2013 - Creation
#  V1.1, 09/09/2013 - Use under-priviledged system user

# description variables
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="RSLSync server"
NAME="rslsync"
PIDNAME="sync.pid"
USER=$NAME
# DAEMON=/usr/local/sbin/$NAME
ROOT=/home/$NAME
DAEMON=$ROOT/.rslsync/$NAME
# PIDFILE=$ROOT/$NAME.pid
PIDFILE=$ROOT/.rslsync/.sync/$PIDNAME
CONFIGFILE=$ROOT/.rslsync/pi_sync.conf

# Exit if rslsync program is not installed
if [ ! -x "$DAEMON" ] ; then
echo "Binary $DAEMON does not exist. Aborting"
exit 0
fi

# Exit if rslsync user home directory doesn't exist
if [ ! -d "$ROOT" ]; then
echo "User $USER does not exist. Aborting"
exit 0
fi

# Function that starts the daemon/service
# 0 - daemon started
# 1 - daemon already running
# 2 - daemon could not be started
do_start()
{
# If needed, start the daemon
if [ -f "$PIDFILE" ]
then
    echo "$NAME already running"
    RETVAL="1"
else
    start-stop-daemon --start --quiet --chuid $USER --name $NAME --exec $DAEMON -- --config $CONFIGFILE
    RETVAL="$?"
    [ "$RETVAL" = "0" ] && echo "$NAME started"
fi

return "$RETVAL"
}

# Function that stops the daemon/service
# 0 - daemon stopped
# 1 - daemon already stopped
# 2 - daemon could not be stopped
do_stop()
{
# Stop the daemon
start-stop-daemon --stop --quiet --retry=TERM/30/KILL/5 --pidfile $PIDFILE --name $NAME
RETVAL="$?"
[ "$RETVAL" = "0" ] && echo "$NAME stopped"
[ "$RETVAL" = "1" ] && echo "$NAME was not running"

# remove pid file
rm -f $PIDFILE

return "$RETVAL"
}

# deal with different parameters : start, stop & status
case "$1" in
# start service
start)
    do_start
    ;;
# stop service
stop)
    do_stop
    ;;
# restart service
restart)
    do_stop
    do_start
    ;;
# unknown command, display help message
*)
    echo "Usage : $SCRIPTNAME {start|stop|restart}" >&2
    exit 3
    ;;
esac
  1. 将以上文件保存在 /etc/init.d/rslsync,并添加可执行权限

  2. 启动服务

1
sudo service rslsync start
  1. 添加系统启动时自动运行
1
sudo update-rc.d rslsync defaults