Add scheduled X post fetcher deployment
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
[Unit]
|
||||
Description=Fetch selected X posts into SQLite
|
||||
After=network-online.target
|
||||
Wants=network-online.target
|
||||
|
||||
[Service]
|
||||
Type=oneshot
|
||||
User=fetchx
|
||||
WorkingDirectory=/opt/fetch-x
|
||||
EnvironmentFile=/etc/fetch-x/fetch-x.env
|
||||
ExecStart=/usr/bin/python3 /opt/fetch-x/fetch_x_posts.py @OpenAI @XDevelopers
|
||||
StandardOutput=journal
|
||||
StandardError=journal
|
||||
|
||||
# Avoid a hung API request blocking a subsequent scheduled run indefinitely.
|
||||
TimeoutStartSec=10min
|
||||
NoNewPrivileges=true
|
||||
PrivateTmp=true
|
||||
ProtectSystem=strict
|
||||
ProtectHome=true
|
||||
ReadWritePaths=/opt/fetch-x
|
||||
@@ -0,0 +1,10 @@
|
||||
[Unit]
|
||||
Description=Run X post fetcher every day
|
||||
|
||||
[Timer]
|
||||
OnCalendar=*-*-* 09:00:00
|
||||
Persistent=true
|
||||
Unit=fetch-x.service
|
||||
|
||||
[Install]
|
||||
WantedBy=timers.target
|
||||
Executable
+33
@@ -0,0 +1,33 @@
|
||||
#!/usr/bin/env bash
|
||||
# Run as root from the project directory on Debian/Ubuntu-like Linux hosts.
|
||||
set -euo pipefail
|
||||
|
||||
APP_DIR=/opt/fetch-x
|
||||
CONFIG_DIR=/etc/fetch-x
|
||||
SERVICE_USER=fetchx
|
||||
|
||||
if [[ ${EUID} -ne 0 ]]; then
|
||||
echo "Run with sudo: sudo bash deploy/install-linux.sh" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [[ ! -f fetch_x_posts.py || ! -f deploy/fetch-x.service ]]; then
|
||||
echo "Run this from the fetch_x project directory." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
id -u "$SERVICE_USER" >/dev/null 2>&1 || useradd --system --create-home --shell /usr/sbin/nologin "$SERVICE_USER"
|
||||
install -d -o "$SERVICE_USER" -g "$SERVICE_USER" -m 0750 "$APP_DIR"
|
||||
install -o "$SERVICE_USER" -g "$SERVICE_USER" -m 0640 fetch_x_posts.py "$APP_DIR/fetch_x_posts.py"
|
||||
install -d -m 0750 "$CONFIG_DIR"
|
||||
|
||||
if [[ ! -f "$CONFIG_DIR/fetch-x.env" ]]; then
|
||||
install -m 0600 /dev/null "$CONFIG_DIR/fetch-x.env"
|
||||
echo "Created $CONFIG_DIR/fetch-x.env. Add X_BEARER_TOKEN=... before starting the service."
|
||||
fi
|
||||
|
||||
install -m 0644 deploy/fetch-x.service /etc/systemd/system/fetch-x.service
|
||||
install -m 0644 deploy/fetch-x.timer /etc/systemd/system/fetch-x.timer
|
||||
systemctl daemon-reload
|
||||
systemctl enable --now fetch-x.timer
|
||||
systemctl list-timers fetch-x.timer --no-pager
|
||||
Reference in New Issue
Block a user