Skip to content

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.

  1. Install the CLI (to ~/.local/bin; use PAKYAS_INSTALL_DIR=/usr/local/bin with root for a system-wide install):
    Terminal window
    curl -fsSL https://pakyas.com/install.sh | sh
  2. Authenticate (not needed if you ping with --public-id):
    Terminal window
    pakyas login

The classic use case is wrapping a cron job so you know if it fails or stops running.

Suppose you have a backup script running nightly:

Terminal window
0 2 * * * /usr/local/bin/backup-db.sh

Simply prepend pakyas monitor <slug> --:

Terminal window
0 2 * * * pakyas monitor db-backup -- /usr/local/bin/backup-db.sh

Create 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.

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:

Terminal window
0 2 * * * pakyas monitor db-backup -- /usr/local/bin/backup-db.sh >/dev/null 2>&1

For systemd services (oneshot or timers), wrap the command in ExecStart.

[Unit]
Description=Daily Cleanup
[Service]
Type=oneshot
# Ping by public ID: no API key needed in the service
ExecStart=/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.py

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).

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.

Terminal window
0 2 * * * /usr/local/bin/pakyas monitor --public-id 550e8400-e29b-41d4-a716-446655440000 -- /path/to/script

Find 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.

Terminal window
0 2 * * * PAKYAS_API_KEY=pk_live_... /usr/local/bin/pakyas monitor db-backup -- /path/to/script

If your job takes longer than its schedule interval, you might have overlapping runs. Use flock to prevent this:

Terminal window
0 * * * * flock -n /var/lock/myjob.lock /usr/local/bin/pakyas monitor hourly-sync -- /opt/jobs/sync.sh