How to change TimeoutStartSec on Debian

Post Reply
User avatar
isscbta
Team Member
Posts: 133
Joined: Mon Jul 19, 2021 1:41 am
Has thanked: 17 times
Been thanked: 3 times

In some situations, usually due to poor server hardware, server may take too much time to restart certain processes. If this happens, server may give up and remain shut down, causing downtime for your website or web application. It's important to ensure that your server hardware is adequate to support your resource requirements, and to configure your server settings appropriately to prevent long restart times and minimize the risk of downtime.

However, if adding more hardware is not an option, you can adjust the amount of time server waits for a process to restart before giving up. This can be achieved by modifying the appropriate settings in the server configuration file. By extending the timeout period, you may be able to prevent Apache from giving up too quickly and experiencing downtime as a result. However, it's important to note that extending the timeout period may increase server load and affect performance, so it should be done with caution and with consideration for the potential impact on overall system stability.

In this situation, we are going to change TimeoutStartSec for Apache web server service:

Code: Select all

sed -i "s|Restart=on-abort|Restart=on-abort\nTimeoutStartSec=900|g" /lib/systemd/system/apache2.service
systemctl daemon-reload
In order to determine if the change has been made successfully, run:

Code: Select all

cat /lib/systemd/system/apache2.service
Explanation:
This command uses the stream editor "sed" to edit the contents of the file located at "/lib/systemd/system/apache2.service". The "-i" flag tells "sed" to modify the file in place, meaning the changes will be made to the original file rather than being outputted to the console.

The command performs a search-and-replace operation on the file, replacing any occurrence of "Restart=on-abort" with "Restart=on-abort\nTimeoutStartSec=900". The "|" character is used as a delimiter instead of the typical "/" delimiter to avoid conflicts with the forward slashes in the search and replace strings.

The new string being inserted includes a line break character "\n" followed by "TimeoutStartSec=900". This adds a new line to the file with a timeout value of 900 seconds (15 minutes) for the Apache web server to start. The "g" at the end of the command means that the search-and-replace operation will be performed globally, meaning all occurrences of the search string will be replaced in the file.

Tags:
Post Reply