systemd はスクリプトに必要な環境変数を読みません。

systemd はスクリプトに必要な環境変数を読みません。

バックアップにborgバックアップとタイマーを使用したいです。systemd私はborgを使っていくつかの修正を経て私のウェブサイトのスクリプトをバックアップしています。元の写真を見ることができます。ここ私のスクリプトは次のとおりです。

#!/bin/sh

# Setting this, so the repo does not need to be given on the commandline:
export [email protected]:/path/to/repo

# See the section "Passphrase notes" for more infos.
export BORG_PASSPHRASE=SecretPassphrase

# some helpers and error handling:
info() { printf "\n%s %s\n\n" "$( date )" "$*" >&2; }
trap 'echo $( date ) Backup interrupted >&2; exit 2' INT TERM

info "Starting backup"

# Backup the most important directories into an archive named after
# the machine this script is currently running on:

borg create                            \
    --remote-path=/usr/local/bin/borg  \
    --verbose                          \
    --filter AME                       \
    --list                             \
    --stats                            \
    --show-rc                          \
    --compression lz4                  \
    --exclude-caches                   \
                                       \
    ::'{hostname}-{now}'               \
    ~/.ssh                             \
    ~/db/dump_*                        \

backup_exit=$?

info "Pruning repository"

# Use the `prune` subcommand to maintain 7 daily, 4 weekly and 6 monthly
# archives of THIS machine. The '{hostname}-' prefix is very important to
# limit prune's operation to this machine's archives and not apply to
# other machines' archives also:

borg prune                             \
    --remote-path=/usr/local/bin/borg  \
    --list                             \
    --prefix '{hostname}-'             \
    --show-rc                          \
    --keep-daily    7                  \
    --keep-weekly   4                  \
    --keep-monthly  6                  \

prune_exit=$?

# use highest exit code as global exit code
global_exit=$(( backup_exit > prune_exit ? backup_exit : prune_exit ))

if [ ${global_exit} -eq 0 ]; then
    info "Backup and Prune finished successfully"
elif [ ${global_exit} -eq 1 ]; then
    info "Backup and/or Prune finished with warnings"
else
    info "Backup and/or Prune finished with errors"
fi

exit ${global_exit}

ATMタイマーなしでサービスを設定したいです。

次の内容n.serviceで(ジョブ名)を作成しました。/etc/systemd/system

[Unit]
Description=Example Service

[Service]
Type=simple
User=callmebob
Group=callmebob
Environment="[email protected]:/path/to/repo"
Environment="BORG_PASSPHRASE=SecretPassphrase"
ExecStart=/bin/sh /home/callmebob/backup.sh

[Install]
WantedBy=multi-user.targetshell

今コンソールから:

sudo systemctl daemon-reload
sudo systemctl start n
sudo systemctl status n

サービスが正常に実行されているようですが、環境変数を読み取れません。

May 18 05:45:31 mydomain systemd[1]: Started Example Service.
May 18 05:45:31 mydomain sh[213874]: Wed 18 May 05:45:31 UTC 2022 Starting backup
May 18 05:45:38 mydomain sh[213903]: passphrase supplied in BORG_PASSPHRASE, by BORG_PASSCOMMAND or via BORG_PASSPHRASE_FD is incorrect.
May 18 05:45:38 mydomain sh[213903]: terminating with error status, rc 2

引用符なしでそこにキーと値のペアを入れて試してみましたEnvironmentFileが、それも機能しませんでした。使ってPassEnvironmentも効果はありません。私も成功せずに様々な種類のサービスを試しました。

ここで何を見逃しているのか知っていますか?

ベストアンサー1

おすすめ記事