Since we have upgraded our laravel project from laravel 8 to laravel 9. we are facing issue that all the commands and jobs mentioned in kernel.php are running twice because of which the system is creating duplicate entries in DB. we didn't make any changes to the code.
We also upgraded the ubuntu version from 16 to 20.
I checked the cron file by this command crontab -e but there is a written command only once. maybe on the server from somewhere else ubuntu running one more command as well.
Kernel.php
protected function schedule(Schedule $schedule)
{
//POD STATS update job
$schedule->job(new PodStatsJob)->everyTenMinutes();
//Consignment table backup job
#Pickup Email Reminder
$pickup_reminder_time = substr(getSingleOrganisationSetting("pickup_reminder_time"), 0, 5) ?? '07:00';
// $schedule->command('conveyor:indexing')->dailyAt($conveyor_consignment_indexing);
}
when I check with this command ps aux | grep "artisan schedule:run"
I get this
root 1331614 0.0 0.0 2616 528 ? Ss 15:00 0:00 /bin/sh -c cd /var/www/html/coldxlogistics && php artisan schedule:run >> /dev/null 2>&1
root 1331616 0.0 0.9 216924 77220 ? S 15:00 0:03 php artisan schedule:run
root 1345894 0.0 0.0 2616 592 ? Ss 17:39 0:00 /bin/sh -c cd /var/www/html/coldxlogistics && php artisan schedule:run >> /dev/null 2>&1
ubuntu 1345895 0.0 0.0 2616 600 ? Ss 17:39 0:00 /bin/sh -c cd /var/www/html/coldxlogistics && php artisan schedule:run >> /dev/null 2>&1
root 1345896 27.0 0.9 216924 79020 ? S 17:39 0:00 php artisan schedule:run
ubuntu 1345897 28.0 0.9 216924 78944 ? S 17:39 0:00 php artisan schedule:run
ubuntu 1345911 0.0 0.0 8484 2428 pts/0 S+ 17:39 0:00 grep --color=auto artisan schedule:run
It seems that two users root and ubuntu are running the same command php artisan schedule:run:
root 1345896 27.0 0.9 216924 79020 ? S 17:39 0:00 php artisan schedule:run
ubuntu 1345897 28.0 0.9 216924 78944 ? S 17:39 0:00 php artisan schedule:run
You maybe need to run the service on only one user.
Related
IN a laravel I have a SnapShot method to copy data to a statistics model.
When I run
/var/www/laravel/artisan schedule:run
data are added to the Statistics-table.
Now I have added the following line to /etc/crontab
* * * * * php /var/www/laravel/artisan schedule:run >> dev/null 2>&1
In my /var/log/syslog I read:
Jul 16 08:53:01 cluego CRON[24524]: (root) CMD (cd /usr/bin/php7.4 && php artisan schedule:run /dev/null 2>&1)
Jul 16 08:53:01 cluego CRON[24523]: (CRON) info (No MTA installed, discarding output)
Jul 16 08:54:01 cluego CRON[24599]: (root) CMD (php /var/www/laravel/artisan schedule:run /dev/null 2>&1)
Jul 16 08:54:01 cluego CRON[24598]: (CRON) info (No MTA installed, discarding output)
The laravel.log shows:
[2021-07-16 09:25:01] production.ERROR: No arguments expected for "schedule:run" command, got "/dev/null". {"exception":"[object] (Symfony\\Component\\Console\\Exception\\$
[stacktrace]
when I run manually I get the following result:
root#xxxx:/var/www/laravel# php artisan schedule:run
Running scheduled command: '/usr/bin/php7.4' 'artisan' statistics:snap > '/dev/null' 2>&1
and a data point is added to Statistics-table, just as it is supposed to.
Can anyone see why the cronjob is not running the statistics:snap command, just like the manual schedule:run does?
The problem is that your coron job is wrongly formatted. From the documentation it should look like this:
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
So in your case it should look like:
* * * * * cd /var/www/laravel && php artisan schedule:run >> /dev/null 2>&1
I guess you could also try running your version but with the full path to php instead of only php or using /dev/null instead of dev/null
* * * * * php /var/www/laravel/artisan schedule:run >> /dev/null 2>&1
* * * * * /path/to/php /var/www/laravel/artisan schedule:run >> /dev/null 2>&1
Hello I have enabling the cron feature for Laravel on Ubuntu 18.10 on Vultr VPS server.
I have added the cron task to the cron jobs list using the command
crontab -e
Then I have added the command listed in the laravel documentation
* * * * * cd /var/www/html/hva && php artisan schedule:run >> /dev/null 2>&1
I have made sure that cron is running and I can see that the task is running if I run
sudo grep -i cron /var/log/syslog|tail -3
Which returns
May 20 20:56:01 HiRe-Pro-Web CRON[1819]: (root) CMD (cd /var/www/html/hva && php artisan schedule:run >> /dev/null 2>&1)
May 20 20:57:01 HiRe-Pro-Web CRON[1862]: (root) CMD (cd /var/www/html/hva && php artisan schedule:run >> /dev/null 2>&1)
May 20 20:58:01 HiRe-Pro-Web CRON[1898]: (root) CMD (cd /var/www/html/hva && php artisan schedule:run >> /dev/null 2>&1)
Does anyone have any suggestions where I'm going wrong here.
I'm writing a code which :
put all xsessions name in a file.
while not EOF , assign a line to a
variable, then pass it to pgrep, line by line.
Output pgrep in terminal.
There is several way to print the desktop environnement,session/window manager.
But i couldn't find one wich work for all xsession(/usr/share/xsessions).
After many try , it still doesn't work.
There is a problem with the loop.
ls /usr/share/xsessions/>all_xsessions;while [ "$var" != "" ]; do let x=x+1; var=$(sed "${x}q;d" all_xsessions); pgrep -lu $(whoami) $var; done
Unfortunately, there is no real standart way or universal environmental variable for that.
Most of information can be get from printenv but variable names differ a lot.
For example, in arch-linux with xfce, where sessions are run directly from windows-manager, you can get PID from $SESSION_MANAGER variable.
But in ubuntu, that is the most popular desktop distro now, your x-session is in fact upstart-session, that starts everything needed. And the variable is $UPSTART_SESSION.
And in xubuntu you have BOTH $SESSION_MANAGER and $UPSTART_SESSION variables.
There is also $DESKTOP_SESSION, it exists almost everywhere and contains some pretty name for desktop-environment, like xfce, ubuntu of xubuntu.
So, that can differ from distro to distro, but in most cases that script will work for you.
#!/bin/bash
[[ -n $SESSION_MANAGER ]] && pid="${SESSION_MANAGER##*/}"
[[ -n $UPSTART_SESSION ]] && pid="${UPSTART_SESSION##*/}"
process_name=$(cat /proc/$pid/cmdline)
pretty_name=$DESKTOP_SESSION
echo "$process_name : $pid : $pretty_name"
And output will be like that:
# Arch with xfce
xfce4-session : 3021 : xfce
# Ubuntu
/sbin/upstart--user : 3153 : ubuntu
# Xubuntu
init--user : 2343 : xubuntu
EDIT: Your method can work in some cases, but most of the time it will fail. Just because right now on ubuntu I have:
$ ls -1 /usr/share/xsessions/
openbox.desktop
ubuntu.desktop
And x-session starting process in Unity looks like that:
root 964 0.0 0.0 276680 6032 ? SLsl 00:16 0:00 /usr/sbin/lightdm
root 997 3.8 0.9 255676 74708 tty7 Ss+ 00:16 0:15 \_ /usr/lib/xorg/Xorg -core :0 -seat seat0 -auth /var/run/lightdm/root/:0 -nolisten tcp vt7 -novtswitch
root 1196 0.0 0.0 230304 6420 ? Sl 00:16 0:00 \_ lightdm --session-child 12 19
user 1442 0.0 0.0 53756 4924 ? Ss 00:16 0:00 \_ /sbin/upstart --user
user 1734 0.0 0.0 39992 280 ? S 00:16 0:00 \_ upstart-udev-bridge --daemon --user
user 1737 0.2 0.0 43932 4332 ? Ss 00:16 0:00 \_ dbus-daemon --fork --session --address=unix:abstract=/tmp/dbus-wkfpguwfxw
user 1749 0.0 0.1 93416 8756 ? Ss 00:16 0:00 \_ /usr/lib/x86_64-linux-gnu/hud/window-stack-bridge
So there is no correlation between name of session in /usr/share/xsessions/ and real process cmdline. So pgrep won't find anything in that cases.
I have a simple script that checks for files to download.
The problem is after some time I can see him multiple times running, started in different times, even though I started him only once:
ps aux | grep _db
root 2804 0.0 0.0 11288 1756 ? S 00:26 0:06 /bin/bash /script/downloader/downloader_db.sh
root 8606 0.0 0.0 11284 872 ? S 12:18 0:00 /bin/bash /script/downloader/downloader_db.sh
root 8649 0.0 0.0 11168 680 pts/0 S 12:18 0:00 /bin/bash /script/downloader/downloader_db.sh
root 11552 0.0 0.0 11272 860 ? S 11:25 0:00 /bin/bash /script/downloader/downloader_db.sh
root 11562 0.0 0.0 11152 672 pts/0 S 11:25 0:00 /bin/bash /script/downloader/downloader_db.sh
root 39150 0.0 0.0 11172 1644 pts/0 S 10:51 0:01 /bin/bash /script/downloader/downloader_db.sh
I started the script with nohup from rc.local:
nohup /script/downloader/downloader_db.sh &> /dev/null &
the script:
#!/bin/bash
while true; do
while IFS=$'\t' read -a line; do
...
sleep 2
done < <(mysql --batch -u${user} -p${password} ${database} -e "${query}" -h ${host})
sleep 10
done
Is anything in the while loop running in the background? It is conceivable that it has the same name as the parent process.
You can check whether some of the processes are subprocesses by running ps wafux and looking at the process tree.
If they are not "related" to each other, you have very likely simply run the script more than once, and the other processes are not finished yet.
I have a program that is running as root. This app calls another program (processA) to run. When processA is running, it is owned by root but I want owner of it to be the current user logged on. How to do it?
Well it's a little bit tricky... Depends if it's a daemon (service) or you run this command/app.
For the 2nd case you can use "su" command.
Here's a short example.
1. I create o simple script with following content (it will sleep in background for 100 seconds and will output the process list coresponding to this script):
#!/bin/bash
sleep 100 &
ps faux | grep test.sh
2. I run the "su" command like this (I'm currently logged in as "root" and I want to run this script as "sandbox" user):
su - sandbox -c ./test.sh
sandbox = the username that will run this command.
-c ./test.sh = means it will execute this command
3. Output (first column = the user that owns this process):
root#i6:/web-storage/sandbox# su - sandbox -c ./test.sh
sandbox 18149 0.0 0.0 31284 1196 pts/0 S+ 20:13 0:00 \_ su - sandbox -c ./test.sh
sandbox 18150 0.0 0.0 8944 1160 pts/0 S+ 20:13 0:00 \_ /bin/bash ./test.sh
sandbox 18155 0.0 0.0 3956 644 pts/0 S+ 20:13 0:00 \_ grep test.sh
root#i6:/web-storage/sandbox#
I hope it will help,
Stefan