Linux Servers & Cron
Pakyas is perfect for monitoring traditional cron jobs and systemd services on Linux servers. The simplest way to integrate is using the pakyas monitor command wrapper.
Prerequisites
Section titled “Prerequisites”- Install the CLI:
Terminal window curl -fsSL https://pakyas.com/install.sh | bash - Authenticate:
Terminal window pakyas login
Cron Jobs
Section titled “Cron Jobs”The classic use case is wrapping a cron job so you know if it fails or stops running.
1. Identify your job
Section titled “1. Identify your job”Suppose you have a backup script running nightly:
0 2 * * * /usr/local/bin/backup-db.sh2. Wrap it with Pakyas
Section titled “2. Wrap it with Pakyas”Simply prepend pakyas monitor <slug> --:
0 2 * * * pakyas monitor db-backup -- /usr/local/bin/backup-db.shEnsure db-backup matches the slug of a check you’ve created in Pakyas. If the check doesn’t exist, Pakyas will return an error (or auto-create it if configured).
3. Handling Output
Section titled “3. Handling Output”By default, cron emails output to the system user. Pakyas captures stdout and stderr and sends the tail of the logs to the dashboard upon failure.
To silence cron emails but keep Pakyas monitoring:
0 2 * * * pakyas monitor db-backup -- /usr/local/bin/backup-db.sh >/dev/null 2>&1Systemd Services
Section titled “Systemd Services”For systemd services (oneshot or timers), you can use ExecStart.
Example: Oneshot Service
Section titled “Example: Oneshot Service”[Unit]Description=Daily Cleanup
[Service]Type=oneshot# Set API key for reliable auth in background servicesEnvironment="PAKYAS_API_KEY=pk_live_..."ExecStart=/usr/local/bin/pakyas monitor cleanup-job -- /usr/local/bin/cleanup.pyCommon Pitfalls
Section titled “Common Pitfalls”User Environment
Section titled “User Environment”Cron runs with a minimal environment. Ensure pakyas is in the PATH or use the absolute path (e.g., /usr/local/bin/pakyas).
Authentication
Section titled “Authentication”Interactive login (pakyas login) stores credentials in the user’s home directory (~/.config/pakyas/).
If your cron job runs as root or another user, it won’t have access to your token.
Solution 1: Use the PAKYAS_API_KEY environment variable.
0 2 * * * PAKYAS_API_KEY=pk_live_... pakyas monitor db-backup -- /path/to/scriptSolution 2: Use the check’s public UUID with --public_id (no API key required).
0 2 * * * PAKYAS_PUBLIC_ID=550e8400-... pakyas monitor --public_id "$PAKYAS_PUBLIC_ID" -- /path/to/scriptOverlapping Jobs
Section titled “Overlapping Jobs”If your job takes longer than its schedule interval, you might have overlapping runs. Use flock to prevent this:
0 * * * * flock -n /var/lock/myjob.lock pakyas monitor hourly-sync -- ./sync.sh