I have a deploy script which i have to execute every time i change my config files. Which is a bummer.
I tried to add the deploy script to my crontab, but from the logs i see that this command is failing in crontab because you are tehnically not in a git repo
exec('git log -1 --format="%H"')
This fella should deliver a revision number so the code can use it, but it dous not execute when you run the script from crontab.
Anyone has any idea how to make it work?
Related
I have in my docker file :
RUN apt-get -y install cron
RUN cron
COPY symfony.cron /var/spool/cron/crontabs/www-data
RUN chown www-data:crontab /var/spool/cron/crontabs/www-data
CMD ["start.sh"]
And in my start.sh :
echo "+ start cron service"
service cron start
All good, the problem is that crons are not running, and is strange because when I go to the docker container and I do service cron status I get [ ok ] cron is running.
so all good. And when I try to execute one command, is executed well. And when I do crontab -u www-data -l I get the liste with all the crons. So all is good at this point. But the crons are not executed anymore, so I don't understand the problem, maybe some permissions or I don't know. Please help me !!! Thx in advance and sorry for my english.
Any ideas please
You should broadly assume commands like service start don’t work in Docker. Just run the program you’re trying to run directly. Make sure it starts as a foreground process.
CMD ["crond", "-f"]
(If your main container script runs a service start command, and that command exits, and the main container script exits, then the container will exit, which isn’t what you want. If service is backed by systemd or another init system, your container won’t be running that.)
I have a Laravel Artisan command that works great and has some interactive-type questions. It works great when run from the command line.
However, when invoked from a Git hook (a Bash script), it doesn't display the interactive questions like "confirm" or "ask", etc. I just need to know in which context the Artisan command is being run and whether I will be able to display my "confirm" or other interactive questions. Is it possible?
My code below:
#!/bin/bash
php artisan some:command
Git executes the hook scripts in a non-interactive shell, so the script's stdin isn't connected to the terminal. We can redirect the terminal to the hook script's process so we can interact with the commands:
#!/bin/sh
# This is a git hook.
# Connect terminal to STDIN...
exec < /dev/tty
# Run any interactive commands...
php artisan some:command
# Close STDIN...
exec <&-
We use exec in this context to control the file descriptors available to the script. See this question or the POSIX spec for more information about exec.
This technique should work fine from the command-line. We may encounter issues if we use other tools that wrap or interact with git.
I have a cronjob with name changeflag. I can use following terminal command to execute this cronjob in local.
php artisan changeflag
In hosting server, I can easily set the execution of console command with cron job.
Is it possible to run above command periodically in local system in Linux automatically as in server ?
or
We have to execute above command through terminal for every test ?
I am using LAMP.
Any help is appreciated.
if you want to add your project's cron jobs in crontab, just add them in crontab file:
change editor to nano (optional)
setenv EDITOR nano
open crontab file
crontab -e
add this line
* * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1
replace path-to-your-project with the real path and the cron will be executed automatically.
If this doesn't work, replace php with full php path. To find the whole path just type in command line which php.
For more info read the docs
Im using php-apache image to create an owncloud installation. I want to use a system cronjob to execute cron.php, therefore I run:
RUN echo "*/3 * * * * php -f /var/www/html/cron.php >> /oc_data/cron.log" > /cron.conf \
&& crontab -u www-data /cron.conf
The entrypoint script starts cron with:
cron -f
It gets executed but the owncloud.log shows following message:
"app":"cron","message":"Failed to connect to the database: An exception occured in driver: could not find driver"
Fun thing is, if I enter the docker container and execute the command I use for the cronjob, it works. And php --ini shows all php conf.d extensions including mysql.so and pdo_mysql.so.
I also tried to add the cron.conf file as user root with the same result.
Any ideas, what is happening here?
Please use the correct folder to keep your cron files: "/etc/cron.d/", use COPY to copy the cron file to inside container and "cron -f" in CMD parameter instead ENTRYPOINT.
OK, ALWAYS use absolute paths!!
path of the php command using the bash in the docker container was different to the one cron used.
use which php to get the correct path and add it to the cronjob.
I'm trying to setup phing to work with travis-ci, but I can't get it to run a setup script to get all the dependencies installed.
My .travis.yml file is:
language: php
php:
- 5.2
script: ./.travis-phing.sh
In travis, I get the error:
/home/travis/build.sh: line 105: ./.travis-phing.sh: Permission denied
What is causing that?
Solved
The script to be set to execute. I used:
chmod a+x .travis-phing.sh
Then simply commit, and push back to github.
Run the script using bash
Another option would be to run the script using bash, this would omit the need to modify the files' permissions.
bash path/to/file.sh
Alternatively:
sh path/to/file.sh
Note that
In this case you're not executing the script itself, you're executing bash or sh which then runs the script. Therefore the script does not need to be executable.
Make sense?
I've found this solution incredibly useful myself. I'm mainly running node & npm projects on travis-ci, those builds make use of the npm test command which you can configure to be anything.
I'm order to modify file permission I need to use sudo chmod ... on my local machine. But you can't always use sudo on travis-ci.
sh file.sh allows me to run my tests both locally and on travis-ci without having to manually update permissions.