#!/bin/sh # /etc/init.d/rslsync #set -x ### BEGIN INIT INFO # Provides: rslsync daemon # Required-Start: $remote_fs $syslog # Required-Stop: $remote_fs $syslog # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Resilio Sync server daemon # Description: This service is used to support the Resilio Sync. # Placed in /etc/init.d/ ### END INIT INFO
# Original Author: Nicolas Bernaerts <nicolas.bernaerts@laposte.net> # Current Author: FOOLMAN <tinyvane@gmail.com> # Version: # Ori V1.0, 06/09/2013 - Creation # Ori V1.1, 09/09/2013 - Use under-priviledged system user # Ori V1.0, 07/12/2016 - Localized into China Raspberry Pi Users # Ori V2.0, 07/22/2016 - Change daemon user from btsync to pi # Cur V3.0, 08/25/2016 - Change pid file location and delete pidmake parameter from start-stop-daemon # Cur V3.1, 08/30/2016 - Necessary change of service name from btsync for rslsync . /lib/lsb/init-functions
# Exit if rslsync program is not installed if [ ! -x "${DAEMON_PATH}" ] ; then echo"Binary ${DAEMON_PATH} does not exist. Aborting" exit 0 fi
# Exit if rslsync user home directory doesn't exist, is "pi" in this script. if [ ! -d "/home/${DAEMON_USER}" ]; then echo"User /home/${DAEMON_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() { local result
pidofproc -p "${DAEMON_PID}""${DAEMON_PATH}" > /dev/null if [ $? -eq 0 ]; then log_warning_msg "${DAEMON_NAME} is already started" result=0 else log_daemon_msg "Starting ${DAEMON_DESC}""${DAEMON_NAME}" touch "${DAEMON_LOG}" chown $DAEMON_USER"${DAEMON_LOG}" chmod u+rw "${DAEMON_LOG}" if [ -z "${DAEMON_USER}" ]; then start-stop-daemon --start --quiet \ --exec"${DAEMON_PATH}" -- --config /etc/rslsync.conf result=$? else start-stop-daemon --start --quiet \ --chuid "${DAEMON_USER}" \ --exec"${DAEMON_PATH}" -- --config /etc/rslsync.conf result=$? fi log_end_msg $result fi return$result }
# Function that stops the daemon/service # 0 - daemon stopped # 1 - daemon already stopped # 2 - daemon could not be stopped
do_stop() { # Stop the daemon local result
pidofproc -p "${DAEMON_PID}""${DAEMON_PATH}" > /dev/null if [ $? -ne 0 ]; then log_warning_msg "${DAEMON_NAME} is not started" result=0 else log_daemon_msg "Stopping ${DAEMON_DESC}""${DAEMON_NAME}" pkill -p "${DAEMON_PID}""${DAEMON_PATH}" result=$? log_end_msg $result # remove pid file rm -f "${DAEMON_PID}" fi return$result }
do_restart() { local result do_stop result=$? if [ $result = 0 ]; then do_start result=$? fi return$result }
do_status() { local result status_of_proc -p "${DAEMON_PID}""${DAEMON_PATH}""${DAEMON_NAME}" result=$? return$result }
{ "device_name": "Pi in Beijing", "listening_port" : 0, // 0 - randomize port
/* storage_path dir contains auxilliary app files if no storage_path field: .sync dir created in current working directory */ "storage_path" : "/home/pi/.sync", //这个地方如果注释掉的话,RslSync会在rslsync可执行程序的同级目录下建立.sync目录,不是很直观
/* set location of pid file */ //"pid_file" : "/home/btsync/btsync.pid", //我把这句给注释掉地了,因为和控制脚本中的makepid冲突了,具体原因,大家可以自己感受一下
/* use UPnP for port mapping */ "use_upnp" : true,
/* limits in kB/s. 0 - no limit */ "download_limit" : 0, "upload_limit" : 0,
/* proxy configuration */ // "proxy_type" : "socks4", // Valid types: "socks4", "socks5", "http_connect". Any other value means no proxy // "proxy_addr" : "192.168.1.2", // IP address of proxy server. // "proxy_port" : 1080, // "proxy_auth" : false, // Use authentication for proxy. Note: only username/password for socks5 (RFC 1929) is supported, and it is not really secure // "proxy_username" : "user", // "proxy_password" : "password",
"webui" : { "listen" : "0.0.0.0:8888" // remove field to disable WebUI
/* directory_root path defines where the WebUI Folder browser starts (linux only). Default value is / */ // ,"directory_root" : "/home/pi/MySharedFolders/"
/* directory_root_policy defines how directory_root is used (linux only). Valid values are: "all" - accepts directory_root and its subdirectories for 'getdir' and 'adddir' actions "belowroot" - accepts directory_root's subdirectories for 'getdir' and 'adddir' actions, but denies attempts to use 'adddir' to create directories directly within directory_root Default value is "all". */ // ,"directory_root_policy" : "all"
/* dir_whitelist defines which directories can be shown to user or have folders added (linux only) relative paths are relative to directory_root setting */ // ,"dir_whitelist" : [ "/home/user/MySharedFolders/personal", "work" ] }
/* !!! if you set shared folders in config file WebUI will be DISABLED !!! shared directories specified in config file override the folders previously added from WebUI. */ /*, "shared_folders" : [ { "secret" : "MY_SECRET_1", // required field - use --generate-secret in command line to create new secret "dir" : "/home/user/bittorrent/sync_test", // * required field "use_relay_server" : true, // use relay server when direct connection fails "use_tracker" : true, "search_lan" : true, "use_sync_trash" : true, // enable SyncArchive to store files deleted on remote devices "overwrite_changes" : false, // restore modified files to original version, ONLY for Read-Only folders "known_hosts" : // specify hosts to attempt connection without additional search [ "192.168.1.2:44444" ] } ] */
/* Advanced preferences can be added to config file. Info is available at "http://help.getsync.com/customer/portal/articles/1902048-sync-advanced-preferences--more-options" For example see folder_rescan_interval below */ //, "folder_rescan_interval" : "86400"
}
有几个地方一定要注意
“device_name”: “Pi in Beijing” #这个是你服务器的标示,改一个比较容易记的
df -l | grep "13db65cc-f3f1-4158-8cc6-118602a6a7dc" if [ $? -ne 0 ] then echo"$(date)$(time) Everthing seems to be fine...." >> $logFile exit 1 else echo"$(date)$(time) WTF! Pi could not find portable hd again! Let's do something:....." umount /media/pi/13db65cc-f3f1-4158-8cc6-118602a6a7dc umount -lf /mnt/hd250g mount UUID="13db65cc-f3f1-4158-8cc6-118602a6a7dc" /mnt/hd250g echo"$(date)$(time) Portable HD remount. Glad to know everything got back to normal!" >> $logFile exit 1 fi