Crontab failing to restart systemctl process - cron

Hi im trying to setup a cron job to restart a game server daily but its failing to work
i have used crontab -e to install a job
* 3 * * * systemctl --user restart <servicename>
this failed to restart my process at 3 am as expected.
i also tried moving the command to a bash file and running the bash file through cron (as i have seen alot of people use .sh files to run commands)
additionally i have tried installing to job as root with zero success
this had similar results
my syslog did show a command execute as expected yesterday though the service didnt restart, since then cron isnt showing any new attempts.
i found some info on troubleshooting and following the guidance shows that my cron is working, i managed write the date/time to a file every minute and the service is clearly running and this showed in the logs.
is there a problem with cron running systemctl commands or is there further steps i can use to see why its failing?
Edit:
i tried running my command as root also and nothing happened
Jan 31 09:00:01 ns509515 CRON[108307]: (root) CMD (<user> systemctl --user restart EcoServer)
Jan 31 09:01:01 ns509515 CRON[108330]: (root) CMD (<user> systemctl --user restart EcoServer)
Jan 31 09:02:01 ns509515 CRON[108356]: (root) CMD (<user> systemctl --user restart EcoServer)

Related

How to disable cron service delay on startup

I'm trying to add the execution of a shell script on server startup. I do it using cron, so I configured it with 'crontab -e' command. It looks so:
#reboot /home/user/run.sh
Then I enabled service with
sudo systemctl enable cron.service
But when I reboot my server, jobs are not started. I check service status with:
sudo systemctl status cron.service
screenshot with an example
And there is a message that it's 2h 55min left to start executing all jobs. So, as I understood service is running but with 3 hours delay. It's happening after every server startup.
Using sudo systemctl restart cron.service command helps to make service working, but the server skips #reboot jobs because "it's not system startup".

Ubuntu 16.04 Cron to run Docker container

I have a virtual machine running Ubuntu 16.04 that I want to run cron-scheduled Docker containers on. I have configured the Docker host and my image repository such that they are accessible by the VM, and images run fine on the machine.
My issue is that when I create a cron-schedule using crontab -e in /var/spool/cron, the containers do not show up. I should be able to view any stopped containers using $ docker ps -a, but it does not show them. Running sudo grep CRON -i /var/log/syslog shows the output:
Mar 20 16:22:01 SpacyVM CRON[121879]: (bdsadmin) CMD (docker run -d
bdsdev.azurecr.io/crawler-public)
Mar 20 16:22:05 SpacyVM CRON[121878]: (CRON) info (No MTA installed,
discarding output)
Mar 20 16:24:01 SpacyVM CRON[124254]: (bdsadmin) CMD (docker run -d
bdsdev.azurecr.io/crawler-public)
Mar 20 16:24:02 SpacyVM CRON[124253]: (CRON) info (No MTA installed,
discarding output)
Now, this does run every 2 minutes, per the schedule for debugging purposes, but docker ps -a shows nothing, even though the containers should have exited and thus should be idle until I use docker rm $(docker ps -aq). Has anyone seen this problem before?
Here is my job configured in crontab:
*/2 * * * * docker run -d bdsdev.azurecr.io/crawler-public
Note: I have not created a mailing setup for the cronjobs to output to, hence the No MTA... error, and I am running this in an Ubuntu VM, not on an Ubuntu docker base image.
Found my problem. When I was originally troubleshooting using grep, my search was omitting a fairly important piece of the log stream. So by using vim to view /var/log/syslog:
Mar 20 06:34:01 SpacyVM dockerd[1469]: time="2018-03-20T06:34:01.634861659Z" level=info msg="Attempting next endpoint for pull after error: manifest unknown: manifest unknown"
I had made a spelling error in my crontab file, so the image is not able to be located by the docker daemon, causing this problem.
Chalk it up to amateur hour

Node Script auto start not working - RPI

I have a node script inside /home/pi/Blynk/script.js I've followed various posts online relating using cron and etc/init.d However none seem to be working. The script must be run via sudo, I've checked the log and it shows the command being run, but its not running the script.
Here is what I added to cron
(This cron below runs the Blynk server and works)
#reboot java -jar /home/pi/server-0.27.1.jar -dataFolder /home/pi/Blynk &
(This cron runs the script with user root and node yet doesn't work)
#reboot /usr/bin/sudo -u root -H /usr/bin/node /home/pi/Blynk/script.js
Could someone please show me where I've gone wrong?

ubuntu - unable to set pm2 as service on boot

I'm launching an application and am able to use PM2 to run it however I'm looking at making sure PM2 launches on reboot of the server.
I have two users, root and a user for running the application. The user has sudo privileges.
Currently I am typing this command:
sudo env PATH=$PATH:/usr/local/bin /usr/local/lib/node_modules/pm2/bin/pm2 startup systemd -u USER --hp /home/USER
and the result:
[ERROR] Exit code : 1
[PM2][ERROR] systemctl start pm2-paul failed, see error above.
When I check jorunalctl for details, I see this:
pm2-user.service: PID file /home/user/.pm2/pm2.pid not readable (yet?) after
start: No such file or directory
Failed to start PM2 process manager.
Any help would be greatly appreciated, I've been struggling for a few hours now with this.

Start crond.service on Ubuntu 16.04

I am programming some schedule task in my Ubuntu 16.04.
But when I try to start the crond.service by
sudo service crond start
I receive the message
crond.service
Loaded: not-found (Reason: No such file or directory)
Active: inactive (dead)
What's the problem? The tasks was added to the schedule by crontab command and look fine (the command works in the terminal, have the correct tree folder, I just added the day-hours parameters).
It's because the service name on 16.04 is cron, not crond. So your command should be:
sudo service cron start
You can verify on your server by looking in the /etc/init.d folder. All the services are there.
ls -l /etc/init.d

Resources