Meteor(React) - Add cron job for aws meteor project - amazon-web-services

I have added cron job for my meteor app at aws by using following command:
* * * * * curl -v http://example.com/testcron
But looks like it is not working as I am not getting any results which is visible if I am trying to refresh http://example.com/testcron manually.
Also tried '/usr/bin/curl' instead of curl but no effect.
What to do?
Thanks in advance!

2 things I can think of:
Ensure that curl is installed on the instance and, in your path.
Check the logs and/or enable more verbose logging to see what’s happening with cron.

Related

What I can use place of appcfg.py download / update for google cloud?

I was generally using the code below to update my project files.
appcfg.py -A project_name -V 1 update c:\myapp\
But now I'm getting an error. That I am not authorized by cred_policy. As a result of my research, I realized that appcfg.py is no longer used. How can I update my project in the easiest way right now?
Use gcloud app deploy command instead of appcfg.py.
It would look something like this: gcloud app deploy c:\myapp\app.yaml --project= project_name
Follow the below link for more information.
https://cloud.google.com/appengine/docs/standard/java/tools/migrating-from-appcfg-to-gcloud

How do you run Drush commands via crontab on Drupal 8

I am trying to execute drush commands through a crontab for a Drupal 8 site. These commands work when I call them directly, but when run through my user's crontab I get the following error:
\Drupal::$container is not initialized yet. \Drupal::setContainer() must be
called with a real container.
Other posts suggest this is a bug within older versions of Drush, but I am on 10.3.5.
I have tried a number of things over the past few hours including reconfiguring cron, but ultimately it seems Drush is not bootstrapping Drupal correctly, but I need to be able to run the queue from cron
This is a test command I'm running which just adds to the Drupal log...
crontab (my user)
* * * * * /var/www/html/vendor/bin/drush scr /var/www/html/scripts/what.php -r /var/www/html/web
what.php
<?php
\Drupal::logger('mymod')->info("CHECKING IN FROM CRON CLI...");
Here is another command, closer to what I'm trying to accomplish...
crontab (my user)
* * * * * /var/www/html/vendor/bin/drush queue:run commerce_recurring -r /var/www/html/web >> /var/www/html/private/logs/cron_commerce_recurring.log
The error I get here is:
Command queue:run was not found. Drush was unable to query the database. As
a result, many commands are unavailable. Re-run your command with --debug
to see relevant log messages.
I get this same error when running this command with drupal console.
Any suggestions appreciated.
Thanks.
This turned out to be a database connectivity issue. The tricky part was getting to the error. I had to install an MTA, so that cron could write errors to my local user's mailbox and then add the --debug option, so that I could see the real error.
I'm working on a DDEV instance and for some reason the DDEV settings were not being loaded. An issue for another day...

Cron with elastic beanstalk and symfony - not working

I'm a newbie developer and I am messing around with Symfony and AWS. I have a Symfony app deployed via elastic beanstalk and I am trying to add a cron job every minute.
Basically I want the cron job to execute a Symfony command I created : update-pings, that is supposed to update some fields in my RDS DB.
I'm using a 02-crons.config file in my ./ebextensions directory that looks like this (greatly inspired from AWS documentation https://aws.amazon.com/fr/premiumsupport/knowledge-center/cron-job-elastic-beanstalk/ ) :
files:
"/etc/cron.d/mycron":
mode: "000644"
owner: root
group: root
content: |
* * * * * root php /var/app/current/bin/console app:update-pings
commands:
remove_old_cron:
command: "rm -f /etc/cron.d/mycron.bak"
Well, first of all, this is not working, the fields in the DB are not updating. So i connected in SSH to my EC2 instance to see what's happening.
The mycron file in /etc/cron.d/was correctly created with * * * * * root php /var/app/current/bin/console app:update-pingsinside of it.
Now, I tried replacing the content of this file by a simple * * * * * root echo test >> /tmp/cron_temp, this is working perfectly, a line with 'test' is added in my cron_temp file every minute
I tried running the initial command php /var/app/current/bin/console app:update-pingsmanually on the instance, works perfectly as ec2-user
When I switch to root user using sudo su -, the command still works. But when I try to run it with sudo, it fails, not sure if that's any relevant :
In EnvVarProcessor.php line 171:
Environment variable not found: "DATABASE_DBNAME".
I believe there is something I'm missing with linux users/rights, but I'm a total newbie with that and cannot find what's going on
Any ideas ? Thanks a lot in advance ! :)
Edit 1 : I'm know logging the sterr of the commande into a file and I get the same environment variable error as when I try to run the command manually with sudo
In EnvVarProcessor.php line 171:
Environment variable not found: "DATABASE_DBNAME".
The command works fine without sudo though

Cron job with aws eb and laravel task scheduling

I would like to know how create a cron with AWS elastic beanstalk and laravel task scheduling.
Currently AWS elastic beanstalk propose to create a cron.yaml file but this file take in paramters only the url. However laravel need to execute a command. I don't know how to do it.
Can you help me please ?
Having done lots of googling, I don't think AWS EB supports executing the schedule:run command directly from app. Instead, the command will have to be triggered from an endpoint just as explained in the docs here.
I found a package here which helped me setup the endpoint easily
Hope it helps...
Getting Laravel Scheduled tasks working is a lot simpler if you just do this:
sudo vi /etc/crontab
and add the line to the bottom of the file:
* * * * * webapp cd /var/www/html/<yourAppFolder>/ && php artisan schedule:run >> /dev/null 2>&1
Done!

Elastic Beanstalk and Cron tasks not sure if its working with Yii

I am having a problem with getting a simple cron task set up on Elastic Beanstalk. I have found some of the other questions on here useful, but i still can't seem to get the cron to execute. I am unsure if it is an AWS issue, or if the script itself is not executing. The script is set up inside YII as a Console Command. I am not finding any PHP errors, and the ec2 instance is loaded without errors. Here is what i have done so far:
I have created a folder on the root of my application called .ebextensions.
Within that folder i have created a configuration file with the contents
# Installing dos2unix in case files are edited on windows PC
packages:
yum:
dos2unix: []
container_commands:
01-command:
command: dos2unix -k cron_setup.sh
02-command:
command: chmod 700 cron_setup.sh
03-command:
command: "cat .ebextensions/cron_task.txt > /etc/cron.d/cron_task && chmod 644 /etc/cron.d/cron_task"
# leader_only prevents problems when EB auto-scales
leader_only: true
the file cron_task.txt exists inside the .ebextensions folder with the contents
# The newline at the end of this file is extremely important. Cron won't run without it.
* * * * * /bin/php /var/www/html/crons.php test > /dev/null
Crons.php is a file at the root of the application that includes the Yii framework
defined('YII_DEBUG') or define('YII_DEBUG',true);
// including Yii
require_once(dirname(__FILE__).$yii.'/yii.php');
// we'll use a separate config file
$configFile=dirname(__FILE__).'/protected/config/cron.php';
// creating and running console application
Yii::createConsoleApplication($configFile)->run();
the config/cron.php file is a setup file for the framework, includes database connection and model inclusions, etc
and the cron script being referenced in the cron_task.txt file is a console command that looks like this
class TestCommand extends CConsoleCommand {
public function run($args) {
$message = new Crontasks();
$message->timestamp = date("Y-m-d H:i:s");
$message->message = "test";
$message->insert();
}
}
here i am just trying to get a record into the database to prove the cron was executed successfully. And i can't seem to get a record added.
The problem is, i don't know where this is failing. I am not getting any instance errors. And i took a snapshot log and cant seem to find any relevant errors in there either. Should php errors be logged here? OR do i have to set it up myself to log errors? The problem, i am also having trouble getting into ec2 via SSH. I am getting a permission denied (public key) error!! Even though i have set up the security group/key pair and using the correct public DNS for the instance!
If anyone can see anything obvious is what im doing wrong here, please let me know! Otherwise could you give any advice on where to look for any errors that might be preventing this cron task to execute? Many thanks!!