Cronjob and scheduled tasks

Hi,

i have installed sharetribe and it works like a charm, thank you!

But i have problems with the cronjobs and scheduled tasks. Doesnt matter how i add them to crontab, they dont work. Can someone give me the right config or example? Ubuntu 18.04

Thanks!!!

This script dont work:

#!/bin/bash
cd /home/administrator/sharetribe
RAILS_ENV=production bundle exec rake ts:start
screen -dmS worker bash -c 'RAILS_ENV=production bundle exec rake jobs:work'
screen -dmS server bash -c 'bundle exec rails server -e production'

Same with scheduled tasks.

Why are you running server/jobs from crontab?

btw my cron jobs file looks like

cd /home/user_name/sharetribe/
source ~/.profile
RAILS_ENV=production bundle exec rails runner ActiveSessionsHelper.cleanup
RAILS_ENV=production bundle exec rake sharetribe:delete_expired_auth_tokens
RAILS_ENV=production bundle exec rake sharetribe:community_updates:deliver

Hi kaleem,

thanks for answer. Crontab because i want to run as user.
You copy your script to /etc/cron.daily? Will the cron be executed as root?

Do you also have a script for starting up the server?

I place the cronjobs file inside the root of the sharetribe repo (/home/user_name/sharetribe/)
and my crontab file has this line to execute the cronjobs file every day at 12:00 am

  0 0 * * * /home/user_name/sharetribe/cron_jobs.sh

You’re starting the Sphinx server, Delayed Jobs and the App server all from a cronjob file, but those things are supposed to start only once,

The cronjob file should contain tasks that are supposed to execute regularly in a specified interval.

I don’t have a single script to start/stop Sphinx server, Delayed Jobs and the App server,
I start them manually

For the delayed jobs and sphinx server

~/sharetribe$ script/delayed_job 
~/sharetribe$ RAILS_ENV=production bundle exec rake ts:start

for app server, I’m using unicorn 5.4.1 and a systemd service to start/stop/restart the server
the service file is

~/sharetribe$ sudo cat /etc/systemd/system/sharetribe-server.service

[Service]
WorkingDirectory=/home/user_name/sharetribe
ExecStart=/bin/bash -lc 'unicorn_rails -c config/unicorn.rb -E production'
Restart=always
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=st_server
User=user_name
Group=user_name

[Install]
WantedBy=multi-user.target
1 Like

It doesnt work for me. Have tried following:

#!/bin/bash
cd /home/username/sharetribe/
source /home/username/.profile
RAILS_ENV=production bundle exec rails runner ActiveSessionsHelper.cleanup >> /home/username/sharetribe/log/cleanupsession.log 2>&1

cleanupsession.log

/home/username/scheduledtasks.sh: line 5: bundle: command not found