diff --git a/README.md b/README.md index 88f3ccf..694833d 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,16 @@ To change maxmimum file size to 50 MB add to the docker start command +### RUNAS_USER + +This variable (along with RUNAS_UID, RUNAS_GROUP and RUNAS_GID) provide a way to control which user will run Resilio Sync and own the synced files. +Useful when dealing with shared volumes. + +### LOG_TO_STDOUT + +The default logging uses file /var/log/rslsync.log. +By defining the LOG_TO_STDOUT variable the Resilio Sync logs are outputted to stdout. + ### syncing local files Inside the container the /data is the default sync directory, to link this to a local file system you can use the **-v** flag diff --git a/root/etc/run_once/config_rslsync b/root/etc/run_once/config_rslsync index ec36b4d..31f8d6c 100755 --- a/root/etc/run_once/config_rslsync +++ b/root/etc/run_once/config_rslsync @@ -21,18 +21,36 @@ if [ -z $RSLSYNC_PATH ]; then RSLSYNC_PATH="/data" fi +# prepare to run as a different user + +if [ -z $RUNAS_USER ]; then + USER_HOME="/root" +else + USER_HOME="/home/$RUNAS_USER" + addgroup -g $RUNAS_GID -S $RUNAS_GROUP + adduser -u $RUNAS_UID -D -S -G $RUNAS_GROUP $RUNAS_USER + + chown -R $RUNAS_USER /etc/rslsync + if [ -z $LOG_TO_STDOUT ]; then + touch /var/log/rslsync.log + chown -R $RUNAS_USER /var/log/rslsync.log + fi + + chown -R $RUNAS_USER $RSLSYNC_PATH +fi + # create base configuration cat < /etc/rslsync/rslsync.conf { - "storage_path" : "/root", + "storage_path" : "$USER_HOME", "listening_port" : 33333, "use_upnp" : false, "vendor" : "docker", "max_file_size_for_versioning" : $RSLSYNC_SIZE, "sync_trash_ttl" : $RSLSYNC_TRASH_TIME, "device_name" : "$RSLSYNC_NAME", - "pid_file" : "/var/run/rslsync.pid", + "pid_file" : "$USER_HOME/rslsync.pid", EOT # check to see if webui should be activated diff --git a/root/etc/sv/rslsync/run b/root/etc/sv/rslsync/run index bd3263d..bfe7de6 100755 --- a/root/etc/sv/rslsync/run +++ b/root/etc/sv/rslsync/run @@ -1,3 +1,8 @@ #!/bin/sh exec 2>&1 -exec /usr/local/bin/rslsync --config /etc/rslsync/rslsync.conf --log /var/log/rslsync.log --nodaemon +source /etc/envvars +LOG_LOCATION="" +if [ -z $LOG_TO_STDOUT ]; then + LOG_LOCATION=" --log /var/log/rslsync.log " +fi +su -c "/usr/local/bin/rslsync --config /etc/rslsync/rslsync.conf $LOG_LOCATION --nodaemon" -s /bin/sh $RUNAS_USER