Cron Management and supervisorctl - jordy33/turbogears_tutorial GitHub Wiki

Cron is used to schedule tasks to run periodically at fixed times. Cron is the name of the Daemon that runs within the Unix-like operative systems. Cron is driven by a crontab (cron table) file, a configuration file that specifies shell commands to run periodically on a given schedule. The crontab files are stored where the lists of jobs and other instructions to the cron daemon are kept. Users can have their own individual crontab files and often there is a system-wide crontab file.

To enter the table in edit mode as follows:

crontab -e

Every user has its own cron table. If you want to run like root the program within you must edit cron table (crontab) entering previously like root user.

If the program doesn't need special permissions you can use an ordinary user. When you issue the command crontab -e , the first time will ask you what editor you may use every time. It could be nano, vim, etc.

Each line of a crontab file represents a job, and looks like this:

# ┌───────────── minute (0 - 59)
# │ ┌───────────── hour (0 - 23)
# │ │ ┌───────────── day of month (1 - 31)
# │ │ │ ┌───────────── month (1 - 12)
# │ │ │ │ ┌───────────── day of week (0 - 6) (Sunday to Saturday;
# │ │ │ │ │                                   7 is also Sunday on some systems)
# │ │ │ │ │
# │ │ │ │ │
# * * * * * command to execute

Real Example:

* * * * * /usr/bin/supervisorctl restart readEmail

This example will run every minute the command. In this case will restart the supervisorctl restart from the task reademail. Every 5 minutes will look like this:

5 * * * * /usr/bin/supervisorctl restart readEmail

I easy to program running task using supervisorctl To load a task store the following script in: /etc/supervisor/conf.d/reademail.conf

[supervisord]
logfile=reademail.log
loglevel=debug
nodaemon=true

[inet_http_server]
port = 9001
username = dwim # Basic auth username
password = GPSc0ntr0l1 # Basic auth password

[program:readEmail]
command=/home/wsgi/public_wsgi/.virtualenvs/tg2env/bin/python3 readEmail.py
directory= /home/wsgi/public_wsgi/python.mercury.ms
autostart=false
autorestart=false
startretries=0
environment=MERCURY_HOST=mercury.dudewhereismy.com.mx, MERCURY_PORT=8086, MERCURY_SECURE=True, MERCURY_DIR=/home/wsgi/public_wsgi/python.mercury.ms

Once is stored you must activate it:

supervisorctl reload

To run the program

supervisorctl start

To stop

supervisorctl stop

In this case this routine will exit after running the program if you issue:

supervisorctl

you will see that the program exited If you run a loop program like a web server you will see the running instead of exited.