<code>/15 * * * * /usr/bin/docker exec 439b5f929468 python3 /app/metrics.py 2>&1 | /usr/bin/timestamp.sh >> /var/log/dedl-stack/dedl_stack.log
</code>
<code>/15 * * * * /usr/bin/docker exec 439b5f929468 python3 /app/metrics.py 2>&1 | /usr/bin/timestamp.sh >> /var/log/dedl-stack/dedl_stack.log
</code>
/15 * * * * /usr/bin/docker exec 439b5f929468 python3 /app/metrics.py 2>&1 | /usr/bin/timestamp.sh >> /var/log/dedl-stack/dedl_stack.log
I have a cronjob running every 15 minutes, however sometimes one of the functions in the script gets stuck, what would be the cleanest way to implement a timeout for this job?
<code>root@noc1(INTERNAL):/etc# ps aux | grep metrics
root 1593181 0.0 0.0 12288 4 ? Sl+ Apr08 0:00 vim metrics.py
root 2506700 0.2 0.1 296684 63860 ? Ssl 11:03 0:00 python3 /app/metrics.py
root 2506842 0.3 0.1 296684 63748 ? Ssl 11:06 0:00 python3 /app/metrics.py
root 2506891 1.8 0.1 296684 63772 ? Ssl 11:09 0:00 python3 /app/metrics.py
root 2506903 0.0 0.0 7008 2208 pts/0 R+ 11:09 0:00 grep --color=auto metrics
root@noc1(INTERNAL):/etc# timeout -s 9 15s /usr/bin/docker exec 439b5f929468 python3 /app/metrics.py
2024-07-09 11:11:05,544 - INFO - Connected to central gateway.
2024-07-09 11:11:05,546 - INFO - Connected to lumi gateway.
2024-07-09 11:11:05,546 - INFO - Attempting to create new cluster for central. Attempt 1
Killed
root@noc1(INTERNAL):/etc# ps aux | grep metrics
root 1593181 0.0 0.0 12288 4 ? Sl+ Apr08 0:00 vim metrics.py
root 2506700 0.1 0.1 296684 63860 ? Ssl 11:03 0:00 python3 /app/metrics.py
root 2506842 0.2 0.1 296684 63748 ? Ssl 11:06 0:00 python3 /app/metrics.py
root 2506891 0.5 0.1 296684 63772 ? Ssl 11:09 0:00 python3 /app/metrics.py
root 2507022 4.0 0.1 296684 63692 ? Ssl 11:11 0:00 python3 /app/metrics.py
root 2507032 0.0 0.0 7008 2200 pts/0 S+ 11:11 0:00 grep --color=auto metrics
root@noc1(INTERNAL):/etc# ps aux | grep metrics
root 1593181 0.0 0.0 12288 4 ? Sl+ Apr08 0:00 vim metrics.py
root 2506700 0.0 0.1 296684 64924 ? Ssl 11:03 0:01 python3 /app/metrics.py
root 2506842 0.0 0.1 296684 64856 ? Ssl 11:06 0:00 python3 /app/metrics.py
root 2506891 0.0 0.1 296684 64880 ? Ssl 11:09 0:00 python3 /app/metrics.py
root 2507022 0.0 0.1 296684 64800 ? Ssl 11:11 0:00 python3 /app/metrics.py
root 2507977 0.0 0.0 7008 2208 pts/0 S+ 11:30 0:00 grep --color=auto metrics
root@noc1(INTERNAL):/etc# timeout -s 9 15s --foreground /usr/bin/docker exec 439b5f929468 python3 /app/metrics.py
timeout: failed to run command ‘--foreground’: No such file or directory
root@noc1(INTERNAL):/etc# timeout --foreground -s 9 15s /usr/bin/docker exec 439b5f929468 python3 /app/metrics.py
2024-07-09 11:31:23,226 - INFO - Connected to central gateway.
2024-07-09 11:31:23,227 - INFO - Connected to lumi gateway.
2024-07-09 11:31:23,227 - INFO - Attempting to create new cluster for central. Attempt 1
root@noc1(INTERNAL):/etc# ps aux | grep metrics
root 1593181 0.0 0.0 12288 4 ? Sl+ Apr08 0:00 vim metrics.py
root 2506700 0.0 0.1 296684 64924 ? Ssl 11:03 0:01 python3 /app/metrics.py
root 2506842 0.0 0.1 296684 64856 ? Ssl 11:06 0:00 python3 /app/metrics.py
root 2506891 0.0 0.1 296684 64880 ? Ssl 11:09 0:00 python3 /app/metrics.py
root 2507022 0.0 0.1 296684 64800 ? Ssl 11:11 0:00 python3 /app/metrics.py
root 2508000 3.9 0.1 296684 63764 ? Ssl 11:31 0:00 python3 /app/metrics.py
root 2508011 0.0 0.0 7008 2248 pts/0 S+ 11:31 0:00 grep --color=auto metrics
</code>
<code>root@noc1(INTERNAL):/etc# ps aux | grep metrics
root 1593181 0.0 0.0 12288 4 ? Sl+ Apr08 0:00 vim metrics.py
root 2506700 0.2 0.1 296684 63860 ? Ssl 11:03 0:00 python3 /app/metrics.py
root 2506842 0.3 0.1 296684 63748 ? Ssl 11:06 0:00 python3 /app/metrics.py
root 2506891 1.8 0.1 296684 63772 ? Ssl 11:09 0:00 python3 /app/metrics.py
root 2506903 0.0 0.0 7008 2208 pts/0 R+ 11:09 0:00 grep --color=auto metrics
root@noc1(INTERNAL):/etc# timeout -s 9 15s /usr/bin/docker exec 439b5f929468 python3 /app/metrics.py
2024-07-09 11:11:05,544 - INFO - Connected to central gateway.
2024-07-09 11:11:05,546 - INFO - Connected to lumi gateway.
2024-07-09 11:11:05,546 - INFO - Attempting to create new cluster for central. Attempt 1
Killed
root@noc1(INTERNAL):/etc# ps aux | grep metrics
root 1593181 0.0 0.0 12288 4 ? Sl+ Apr08 0:00 vim metrics.py
root 2506700 0.1 0.1 296684 63860 ? Ssl 11:03 0:00 python3 /app/metrics.py
root 2506842 0.2 0.1 296684 63748 ? Ssl 11:06 0:00 python3 /app/metrics.py
root 2506891 0.5 0.1 296684 63772 ? Ssl 11:09 0:00 python3 /app/metrics.py
root 2507022 4.0 0.1 296684 63692 ? Ssl 11:11 0:00 python3 /app/metrics.py
root 2507032 0.0 0.0 7008 2200 pts/0 S+ 11:11 0:00 grep --color=auto metrics
root@noc1(INTERNAL):/etc# ps aux | grep metrics
root 1593181 0.0 0.0 12288 4 ? Sl+ Apr08 0:00 vim metrics.py
root 2506700 0.0 0.1 296684 64924 ? Ssl 11:03 0:01 python3 /app/metrics.py
root 2506842 0.0 0.1 296684 64856 ? Ssl 11:06 0:00 python3 /app/metrics.py
root 2506891 0.0 0.1 296684 64880 ? Ssl 11:09 0:00 python3 /app/metrics.py
root 2507022 0.0 0.1 296684 64800 ? Ssl 11:11 0:00 python3 /app/metrics.py
root 2507977 0.0 0.0 7008 2208 pts/0 S+ 11:30 0:00 grep --color=auto metrics
root@noc1(INTERNAL):/etc# timeout -s 9 15s --foreground /usr/bin/docker exec 439b5f929468 python3 /app/metrics.py
timeout: failed to run command ‘--foreground’: No such file or directory
root@noc1(INTERNAL):/etc# timeout --foreground -s 9 15s /usr/bin/docker exec 439b5f929468 python3 /app/metrics.py
2024-07-09 11:31:23,226 - INFO - Connected to central gateway.
2024-07-09 11:31:23,227 - INFO - Connected to lumi gateway.
2024-07-09 11:31:23,227 - INFO - Attempting to create new cluster for central. Attempt 1
root@noc1(INTERNAL):/etc# ps aux | grep metrics
root 1593181 0.0 0.0 12288 4 ? Sl+ Apr08 0:00 vim metrics.py
root 2506700 0.0 0.1 296684 64924 ? Ssl 11:03 0:01 python3 /app/metrics.py
root 2506842 0.0 0.1 296684 64856 ? Ssl 11:06 0:00 python3 /app/metrics.py
root 2506891 0.0 0.1 296684 64880 ? Ssl 11:09 0:00 python3 /app/metrics.py
root 2507022 0.0 0.1 296684 64800 ? Ssl 11:11 0:00 python3 /app/metrics.py
root 2508000 3.9 0.1 296684 63764 ? Ssl 11:31 0:00 python3 /app/metrics.py
root 2508011 0.0 0.0 7008 2248 pts/0 S+ 11:31 0:00 grep --color=auto metrics
</code>
root@noc1(INTERNAL):/etc# ps aux | grep metrics
root 1593181 0.0 0.0 12288 4 ? Sl+ Apr08 0:00 vim metrics.py
root 2506700 0.2 0.1 296684 63860 ? Ssl 11:03 0:00 python3 /app/metrics.py
root 2506842 0.3 0.1 296684 63748 ? Ssl 11:06 0:00 python3 /app/metrics.py
root 2506891 1.8 0.1 296684 63772 ? Ssl 11:09 0:00 python3 /app/metrics.py
root 2506903 0.0 0.0 7008 2208 pts/0 R+ 11:09 0:00 grep --color=auto metrics
root@noc1(INTERNAL):/etc# timeout -s 9 15s /usr/bin/docker exec 439b5f929468 python3 /app/metrics.py
2024-07-09 11:11:05,544 - INFO - Connected to central gateway.
2024-07-09 11:11:05,546 - INFO - Connected to lumi gateway.
2024-07-09 11:11:05,546 - INFO - Attempting to create new cluster for central. Attempt 1
Killed
root@noc1(INTERNAL):/etc# ps aux | grep metrics
root 1593181 0.0 0.0 12288 4 ? Sl+ Apr08 0:00 vim metrics.py
root 2506700 0.1 0.1 296684 63860 ? Ssl 11:03 0:00 python3 /app/metrics.py
root 2506842 0.2 0.1 296684 63748 ? Ssl 11:06 0:00 python3 /app/metrics.py
root 2506891 0.5 0.1 296684 63772 ? Ssl 11:09 0:00 python3 /app/metrics.py
root 2507022 4.0 0.1 296684 63692 ? Ssl 11:11 0:00 python3 /app/metrics.py
root 2507032 0.0 0.0 7008 2200 pts/0 S+ 11:11 0:00 grep --color=auto metrics
root@noc1(INTERNAL):/etc# ps aux | grep metrics
root 1593181 0.0 0.0 12288 4 ? Sl+ Apr08 0:00 vim metrics.py
root 2506700 0.0 0.1 296684 64924 ? Ssl 11:03 0:01 python3 /app/metrics.py
root 2506842 0.0 0.1 296684 64856 ? Ssl 11:06 0:00 python3 /app/metrics.py
root 2506891 0.0 0.1 296684 64880 ? Ssl 11:09 0:00 python3 /app/metrics.py
root 2507022 0.0 0.1 296684 64800 ? Ssl 11:11 0:00 python3 /app/metrics.py
root 2507977 0.0 0.0 7008 2208 pts/0 S+ 11:30 0:00 grep --color=auto metrics
root@noc1(INTERNAL):/etc# timeout -s 9 15s --foreground /usr/bin/docker exec 439b5f929468 python3 /app/metrics.py
timeout: failed to run command ‘--foreground’: No such file or directory
root@noc1(INTERNAL):/etc# timeout --foreground -s 9 15s /usr/bin/docker exec 439b5f929468 python3 /app/metrics.py
2024-07-09 11:31:23,226 - INFO - Connected to central gateway.
2024-07-09 11:31:23,227 - INFO - Connected to lumi gateway.
2024-07-09 11:31:23,227 - INFO - Attempting to create new cluster for central. Attempt 1
root@noc1(INTERNAL):/etc# ps aux | grep metrics
root 1593181 0.0 0.0 12288 4 ? Sl+ Apr08 0:00 vim metrics.py
root 2506700 0.0 0.1 296684 64924 ? Ssl 11:03 0:01 python3 /app/metrics.py
root 2506842 0.0 0.1 296684 64856 ? Ssl 11:06 0:00 python3 /app/metrics.py
root 2506891 0.0 0.1 296684 64880 ? Ssl 11:09 0:00 python3 /app/metrics.py
root 2507022 0.0 0.1 296684 64800 ? Ssl 11:11 0:00 python3 /app/metrics.py
root 2508000 3.9 0.1 296684 63764 ? Ssl 11:31 0:00 python3 /app/metrics.py
root 2508011 0.0 0.0 7008 2248 pts/0 S+ 11:31 0:00 grep --color=auto metrics
As you can see timout didn’t work on script run through docker exec