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 (to
~/.local/bin; usePAKYAS_INSTALL_DIR=/usr/local/binwith root for a system-wide install):Terminal window curl -fsSL https://pakyas.com/install.sh | sh - Authenticate (not needed if you ping with
--public-id):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.shCreate the check first, for example pakyas check create db-backup --cron "0 2 * * *". Checks are not created automatically: if the slug can’t be resolved, pakyas monitor prints a warning, still runs the script, and exits with code 3 so the problem is visible.
3. Handling Output
Section titled “3. Handling Output”pakyas monitor passes the job’s stdout and stderr through unchanged, so cron mails (or logs) them as before. On failure, the tail of stderr (or stdout, if stderr is empty) is also sent to Pakyas and shown in the dashboard.
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), wrap the command in ExecStart.
Example: Oneshot Service
Section titled “Example: Oneshot Service”[Unit]Description=Daily Cleanup
[Service]Type=oneshot# Ping by public ID: no API key needed in the serviceExecStart=/usr/local/bin/pakyas monitor --public-id 550e8400-e29b-41d4-a716-446655440000 -- /usr/local/bin/cleanup.py# Or by slug, with an API key:# Environment="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 and PATH. Use the absolute path to the binary (~/.local/bin/pakyas by default, or /usr/local/bin/pakyas for a system-wide install).
Authentication
Section titled “Authentication”pakyas login stores credentials in the logged-in user’s config directory (~/.config/pakyas/ on Linux).
If your cron job runs as root or another user, it won’t see them.
Solution 1 (recommended): Use the check’s public ID with --public-id. No API key and no API calls are needed.
0 2 * * * /usr/local/bin/pakyas monitor --public-id 550e8400-e29b-41d4-a716-446655440000 -- /path/to/scriptFind the public ID in the PUBLIC_ID column of pakyas check list.
Solution 2: Set PAKYAS_API_KEY. The organization is taken from the key, so nothing else is needed.
0 2 * * * PAKYAS_API_KEY=pk_live_... /usr/local/bin/pakyas monitor db-backup -- /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 /usr/local/bin/pakyas monitor hourly-sync -- /opt/jobs/sync.shSee Also
Section titled “See Also”- monitor - Exit codes and failure output
- CLI Configuration - Cron and CI setup