Score:0

Ubuntu 20.04 @reboot cronjob doens't run script

at flag

I have a vultr server in a ubuntu so 20.04, i'm creating a bash script in the following dir

/startupscripts/apilibro

Inside of the script i need to start my directus server running yarn directus start

!#/bin/bash
cd /var/www/vhosts/librocambio.cl/core.librocambio.cl/apilibro
/usr/bin/yarn directus start

I give chmod 755 to read, write and execute the script, finally i run crontab -e and add the following code to execute when server is restarted

@reboot /startupscripts/apilibro

My problem is that the yarn directus start command doesn't run, when i run locally the command works, but on ubuntu reboot doesn't work, finally i test the bash script adding a line as touch index.js and it works but yarn directus start command doesn't run.

Any idea how to solve this problem?

Artur Meinild avatar
vn flag
Remember that cron runs its own environment. Does yarn require anything in `$PATH` or other environment variables? If yes, then those should be set in the script as well before the command runs.
Score:0
ao flag

1st way,

i think you can use the command to check out log of crond

tail -f /var/log/cron.log

the output here might be give you some info.

if there is no cron.log, use this command and restart the rsyslog service

sed -i '/#cron.*/s/^#//g' /etc/rsyslog.d/50-default.conf

systemctl restart rsyslog.service

2nd

perhaps the env of yarn does not match your use who run the crond?

Score:0
at flag

Problem solved, this is what i did to solve my problem.

  1. I ran the script manually using bash apilibro, so i notice that yarn wasn't present in my environment variables, i just added as @Artur Medim say.
  2. I notice that my nodejs version was 10.x.x by default, when i changed it using nvm it works, but when i rebooted the system or close my ssh terminal, the nodejs version change to the default, so updated correctly my versión to 16.x.x to make sure that this is not happening.

After that i could run the script manually and on cronjob, thank to all for your answers.

I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.