diff --git a/README.md b/README.md index 3b352a7..21fface 100644 --- a/README.md +++ b/README.md @@ -83,6 +83,44 @@ To see what would be deployed without actually deploying: ./compose-sync -config /path/to/config.yml ``` +### Systemd Service and Timer (Automatic Execution) + +To run compose-sync automatically using systemd: + +1. **Install the binary** (if not already installed): + ```bash + sudo cp compose-sync /usr/local/bin/ + ``` + +2. **Edit the service file** (`compose-sync.service`): + - Replace `youruser` with the actual user that should run compose-sync (make sure this user has the correct permissions) + - Adjust paths if needed (binary location, config file, etc.) + +3. **Copy the service and timer files**: + ```bash + sudo cp compose-sync.service compose-sync.timer /etc/systemd/system/ + ``` + +4. **Reload systemd and enable the timer**: + ```bash + sudo systemctl daemon-reload + sudo systemctl enable compose-sync.timer + sudo systemctl start compose-sync.timer + ``` + +5. **Check status**: + ```bash + sudo systemctl status compose-sync.timer + sudo systemctl status compose-sync.service + ``` + +6. **View logs**: + ```bash + sudo journalctl -u compose-sync.service -f + ``` + +The timer will run compose-sync every 5 minutes. To change the interval, edit `compose-sync.timer` and modify the `OnUnitActiveSec` value. + ## How It Works 1. **Host Detection**: The tool uses the system hostname to identify the current host diff --git a/systemd/compose-sync.service b/systemd/compose-sync.service new file mode 100644 index 0000000..e849771 --- /dev/null +++ b/systemd/compose-sync.service @@ -0,0 +1,17 @@ +[Unit] +Description=compose-sync - Sync and deploy Docker Compose stacks from git +After=network-online.target docker.service +Wants=network-online.target + +[Service] +Type=oneshot +# Replace 'youruser' with the actual user that should run compose-sync +User=youruser +# Path to compose-sync binary (adjust if installed elsewhere) +# If config.yml is not in the default location, add: -config /path/to/config.yml +ExecStart=/usr/local/bin/compose-sync +Environment="HOME=/home/youruser" +WorkingDirectory=/home/youruser +StandardOutput=journal +StandardError=journal + diff --git a/systemd/compose-sync.timer b/systemd/compose-sync.timer new file mode 100644 index 0000000..8877f33 --- /dev/null +++ b/systemd/compose-sync.timer @@ -0,0 +1,12 @@ +[Unit] +Description=Run compose-sync every 5 minutes +Requires=compose-sync.service + +[Timer] +OnBootSec=5min +OnUnitActiveSec=5min +AccuracySec=1min + +[Install] +WantedBy=timers.target +