시스템 서비스가 실행되고 있지 않습니다.

시스템 서비스가 실행되고 있지 않습니다.

수정했습니다이 스크립트rclone을 사용하여 폴더를 원격으로 지속적으로 동기화할 수 있도록 도와주세요. 해당 스크립트의 코드는 아래에 게시되어 있습니다. 내 문제는 처음 실행할 때 동기화가 잘 되는 것 같은데 잘못된 폴더를 동기화하고 있다는 것입니다. 그래서 프로세스를 종료하고 다시 실행해 보았더니 동기화가 중단되었습니다. 결국 전체 .config 폴더(서비스 파일이 보관되는 폴더)를 삭제하고 rclone 을 사용하여 새 rclone 원격을 만든 rclone config다음 시스템을 재부팅합니다. 지금은 스크립트가 처음 실행될 때만 동기화되고 그 이후에는 더 이상 동기화되지 않는 것 같습니다. 어떤 이유로 systemd 서비스가 실행되지 않는 것 같은데 그 이유를 이해할 수 없습니다. 어떤 도움이라도 대단히 감사하겠습니다.

#!/bin/bash
## One-way, immediate, continuous, recursive, directory synchronization
##  to a remote Rclone URL. ( S3, SFTP, FTP, WebDAV, Dropbox, etc. )
## Optional desktop notifications on sync events or errors.
## Useful only for syncing a SMALL number of files (< 8192).
##  (See note in `man inotifywait` under `--recursive` about raising this limit.)
## Think use-case: Synchronize Traefik TLS certificates file (acme.json)
## Think use-case: Synchronize Keepass (.kdbx) database file immediately on save.
## Think use-case: Live edit source code and push to remote server

## This is NOT a backup tool! 
## It will not help you if you delete your files or if they become corrupted.

## Setup: Install `rclone` from package manager.
## Run: `rclone config` to setup the remote, including the full remote
##   subdirectory path to sync to.
## MAKE SURE that the remote (sub)directory is EMPTY
##   or else ALL CONTENTS WILL BE DELETED by rclone when it syncs.
## If unsure, add `--dry-run` to the RCLONE_CMD variable below, 
##   to simulate what would be copied/deleted. 
## Copy this script any place, and make it executable: `chown +x sync.sh`
## Edit all the variables below, before running the script.
## Run: `./sync.sh systemd_setup` to create and enable systemd service.
## Run: `journalctl --user --unit rclone_sync.${RCLONE_REMOTE}` to view the logs.

## Edit the variables below, according to your own environment:

# RCLONE_SYNC_PATH: The path to COPY FROM (files are not synced TO here):
RCLONE_SYNC_PATH="/home/user/dav-sync"

# RCLONE_REMOTE: The rclone remote name to synchronize with.
# Identical to one of the remote names listed via `rclone listremotes`.
# Make sure to include the final `:` in the remote name, which
#   indicates to sync/delete from the same (sub)directory as defined in the URL.
# (ALL CONTENTS of the remote are continuously DELETED
#  and replaced with the contents from RCLONE_SYNC_PATH)
RCLONE_REMOTE="my-webdav-remote:"

# RCLONE_CMD: The sync command and arguments:
RCLONE_CMD="rclone -v sync ${RCLONE_SYNC_PATH} ${RCLONE_REMOTE}"

# WATCH_EVENTS: The file events that inotifywait should watch for:
WATCH_EVENTS="modify,delete,create,move"

# SYNC_DELAY: Wait this many seconds after an event, before synchronizing:
SYNC_DELAY=5

# SYNC_INTERVAL: Wait this many seconds between forced synchronizations:
SYNC_INTERVAL=3600

# NOTIFY_ENABLE: Enable Desktop notifications
NOTIFY_ENABLE=true

# SYNC_SCRIPT: dynamic reference to the current script path
SYNC_SCRIPT=$(realpath $0)

notify() {
    MESSAGE=$1
    if test ${NOTIFY_ENABLE} = "true"; then
        notify-send "rclone ${RCLONE_REMOTE}" "${MESSAGE}"
    fi
}

rclone_sync() {
    set -x
    # Do initial sync immediately:
    notify "Startup"
    ${RCLONE_CMD}
    # Watch for file events and do continuous immediate syncing
    # and regular interval syncing:
    while [[ true ]] ; do
    inotifywait --recursive --timeout ${SYNC_INTERVAL} -e ${WATCH_EVENTS} \
            ${RCLONE_SYNC_PATH} 2>/dev/null
    if [ $? -eq 0 ]; then
        # File change detected, sync the files after waiting a few seconds:
        sleep ${SYNC_DELAY} && ${RCLONE_CMD} && \
        notify "Synchronized new file changes"
    elif [ $? -eq 1 ]; then
        # inotify error occured
        notify "inotifywait error exit code 1"
        sleep 10
    elif [ $? -eq 2 ]; then
        # Do the sync now even though no changes were detected:
        ${RCLONE_CMD}
    fi
    done
}

systemd_setup() {
    set -x
    if loginctl show-user ${USER} | grep "Linger=no"; then
        echo "User account does not allow systemd Linger."
        echo "To enable lingering, run as root: loginctl enable-linger $USER"
        echo "Then try running this command again."
        exit 1
    fi
    mkdir -p ${HOME}/.config/systemd/user
    SERVICE_FILE=${HOME}/.config/systemd/user/rclone_sync.${RCLONE_REMOTE}.service
    if test -f ${SERVICE_FILE}; then
        echo "Unit file already exists: ${SERVICE_FILE} - Not overwriting."
    else
        cat <<EOF > ${SERVICE_FILE}
[Unit]
Description=rclone_sync ${RCLONE_REMOTE}

[Service]
ExecStart=${SYNC_SCRIPT}

[Install]
WantedBy=default.target
EOF
    fi
    systemctl --user daemon-reload
    systemctl --user enable --now rclone_sync.${RCLONE_REMOTE}
    systemctl --user status rclone_sync.${RCLONE_REMOTE}
    echo "You can watch the logs with this command:"
    echo "   journalctl --user --unit rclone_sync.${RCLONE_REMOTE}"
}

if test $# = 0; then
    rclone_sync
else
    CMD=$1; shift;
    ${CMD} $@
fi

관련 정보