Launch Modes
Launch modes in Ptah.sh determine how and when workers within a service are started. They provide flexibility in managing your application’s behavior and resource utilization. This page explains the available launch modes and how to use them effectively.
Available Launch Modes
Ptah.sh offers four launch modes for workers:
- Daemon or Queue Worker
- Schedule: Cronjob
- Backup: create a backup
- Backup: restore a backup
Let’s explore each of these in detail.
1. Daemon or Queue Worker
This is the default launch mode for most workers. In this mode, the worker runs continuously as a background process.
Use cases:
- Web servers
- Database servers
- Message queues
- Long-running background tasks
Configuration: To set a worker to run as a daemon or queue worker, simply select this option in the worker’s launch mode settings.
2. Schedule: Cronjob
This launch mode allows you to run workers on a predefined schedule, similar to a cron job in Unix-like operating systems.
Use cases:
- Periodic data updates
- Scheduled backups
- Report generation
- Cleanup tasks
Configuration: When selecting this launch mode, you have two options for setting the schedule:
-
Choose from pre-defined expressions:
- Every minute
- Every five minutes
- Every hour
- Every day at midnight
- Every Sunday at midnight
-
Enter a custom cron expression:
0 0 * * *
- Run daily at midnight*/15 * * * *
- Run every 15 minutes0 0 * * MON
- Run every Monday at midnight
3. Backup: create a backup
This launch mode is specifically designed for creating backups of your service data. It functions similarly to the “Schedule: Cronjob” mode but with additional backup-specific features.
Use cases:
- Regular data backups
- Pre-update snapshots
- Scheduled backup creation
Configuration: When using this launch mode, you’ll need to provide:
- A backup command that creates the backup file(s)
- The archive type: tar.gz or zip
- A schedule for the backup (required)
Scheduling: Like the “Schedule: Cronjob” mode, you must set a schedule for your backups. You can either:
- Choose from pre-defined expressions (e.g., every day at midnight, every Sunday at midnight)
- Enter a custom cron expression (e.g.,
0 0 * * *
for daily at midnight)
Special Environment Variable:
Ptah.sh defines a special environment variable $PTAH_BACKUP_DIR
where your backup command should store the files to be uploaded to the selected S3 storage.
Backup Management: All backups created using this launch mode will be displayed on the “Backups” page of the service. From there, you can manage your backups and initiate restore operations when needed.
4. Backup: restore a backup
This launch mode is used to restore service data from a previously created backup.
Use cases:
- Disaster recovery
- Rolling back to a previous state
- Migrating data to a new environment
Configuration: For this launch mode, you’ll need to specify:
- A restore command that processes the backup file and restores the data
Special Environment Variable:
Ptah.sh defines a special environment variable $PTAH_BACKUP_DIR
where the selected backup files will be placed for restoration.
Execution: Workers in this launch mode are started manually from the “Backups” tab on the “Services” page. When initiated:
- Ptah.sh will download the selected backup
- The backup files will be placed into the
$PTAH_BACKUP_DIR
- Your specified restore command will be executed
Best Practices
- Choose the right launch mode: Select the launch mode that best fits your worker’s purpose and resource requirements.
- Use schedules wisely: For scheduled tasks, choose intervals that balance between keeping data up-to-date and minimizing resource usage.
- Test backup and restore: Regularly test your backup and restore processes to ensure they work as expected.
- Monitor and adjust: Keep an eye on your workers’ performance and adjust launch modes or schedules as needed.
By leveraging these launch modes effectively, you can optimize your Ptah.sh services for performance, resource utilization, and data management.