N
N
Nightmarr132021-12-19 03:16:00
PostgreSQL
Nightmarr13, 2021-12-19 03:16:00

Postgresql startup script in cron sends SIGTERM after start. Everything is ok in the terminal. What is the problem?

I use a small bash script to check Postgresql status and if for some reason the status is failed, a command is issued to start the service:

#!/bin/bash
if [ "$(systemctl is-active [email protected])" = "failed" ]; then
     service [email protected] start
fi


When checking in the console, everything is OK - I stop postgresql, I execute the script file - everything starts up fine.

But when the script is launched via cron (I use the system one for it), the server starts, but then immediately receives a shutdown signal.
In the logs it looks like this:
2021-12-18 08:10:04.070 MSK [18362] LOG: listening on IPv4 address "0.0.0.0", port
5432 listening on IPv6 address "::", port 5432
2021-12-18 08:10:04.071 MSK [18362] LOG: listening on Unix socket "/var/run/postgresql/.s.PGSQL.5432"
2021-12- 18 08:10:04.171 MSK [18371] LOG: database system was shut down at 2021-12-18 08:05:04 MSK
2021-12-18 08:10:04.201 MSK [18362] LOG: database system is ready to accept connections
2021-12-18 08:10:04.275 MSK [18362] LOG: received smart shutdown
request 1
2021-12-18 08:10:04.288 MSK [18373] LOG: shutting down
2021-12-18 08:10:04.302 MSK [18362] LOG: database system is shut

down conflicts and SIGNAL arrives from somewhere to stop work, so I ran the killsnoop-bpfcc utility, this is what it showed:

61be78f04602d613480119.jpeg
I didn’t really understand what the picture was in the end, but I checked where the processes with these PIDs are located - in the folder with the script mentioned above. Other cron scripts have been disabled at this time.

Obviously, the problem is not in the script itself (which runs perfectly from the console), but in the work of cron, but I can’t understand what exactly, Google did not help.
I will be glad to advice.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Valdemar Smorman, 2021-12-19
@smorman

As a rule, and most often, errors in Cron work are associated with incorrect registration of the path to the script in the scheduler.
You need to write the full path !

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question