Skip to content

Commit

Permalink
add systemd service auto restart for nginx, php-fpm & redis
Browse files Browse the repository at this point in the history
- for nginx, php-fpm and redis systemd services add support to auto restart their respective services if service fails, crashes or exists. Auto restart will trigger 5 seconds after service failure is detected. The following config files control the settings and if they are custom edited, ensure you do run command = systemctl daemon-reload afterwards

/etc/systemd/system/nginx.service.d/failure-restart.conf
/etc/systemd/system/php-fpm.service.d/failure-restart.conf
/etc/systemd/system/redis.service.d/failure-restart.conf
  • Loading branch information
centminmod committed Apr 19, 2022
1 parent 86d247f commit 67b07bf
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 0 deletions.
10 changes: 10 additions & 0 deletions addons/redis-server-install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,16 @@ ExecStart=/bin/sh -c "/usr/bin/echo 'never' > /sys/kernel/mm/transparent_hugepag
WantedBy=multi-user.target
EOF

cat > "/etc/systemd/system/redis.service.d/failure-restart.conf" <<TDG
[Unit]
StartLimitIntervalSec=30
StartLimitBurst=2
[Service]
Restart=on-failure
RestartSec=5s
TDG

if [ -f /etc/systemd/system/disable-thp.service ]; then
systemctl daemon-reload
systemctl start disable-thp
Expand Down
13 changes: 13 additions & 0 deletions inc/cpcheck.inc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ if [[ "$CENTOS_NINE" = '9' || "$CENTOS_EIGHT" = '8' || "$CENTOS_SEVEN" = '7' ]]
cat > "/etc/systemd/system/nginx.service.d/openfileslimit.conf" <<TDG
[Service]
LimitNOFILE=1048576
TDG
systemctl daemon-reload
fi
if [[ "$CENTOS_NINE" = '9' || "$CENTOS_EIGHT" = '8' || "$CENTOS_SEVEN" = '7' ]] && [[ ! -f /etc/systemd/system/nginx.service.d/failure-restart.conf ]]; then
echo "setup /etc/systemd/system/nginx.service.d/failure-restart.conf"
cat > "/etc/systemd/system/nginx.service.d/failure-restart.conf" <<TDG
[Unit]
StartLimitIntervalSec=30
StartLimitBurst=2

[Service]
Restart=on-failure
RestartSec=5s
TDG
systemctl daemon-reload
fi
Expand Down
13 changes: 13 additions & 0 deletions inc/nginx_install.inc
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,19 @@ if [[ "$CENTOS_EIGHT" = '8' || "$CENTOS_NINE" = '9' ]] || [[ "$SWITCH_NGINX_SYST
cat > "/etc/systemd/system/nginx.service.d/openfileslimit.conf" <<TDG
[Service]
LimitNOFILE=1048576
TDG
systemctl daemon-reload
fi
if [[ "$CENTOS_NINE" = '9' || "$CENTOS_EIGHT" = '8' || "$CENTOS_SEVEN" = '7' ]] && [[ ! -f /etc/systemd/system/nginx.service.d/failure-restart.conf ]]; then
echo "setup /etc/systemd/system/nginx.service.d/failure-restart.conf"
cat > "/etc/systemd/system/nginx.service.d/failure-restart.conf" <<TDG
[Unit]
StartLimitIntervalSec=30
StartLimitBurst=2

[Service]
Restart=on-failure
RestartSec=5s
TDG
systemctl daemon-reload
fi
Expand Down
11 changes: 11 additions & 0 deletions inc/php_upgrade.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,17 @@ sar_call

if [[ "$CENTOS_SEVEN" -eq '7' || "$CENTOS_EIGHT" -eq '8' || "$CENTOS_NINE" -eq '9' ]] && [[ "$SWITCH_PHPFPM_SYSTEMD" = [yY] && -f "/usr/local/src/centminmod/tools/php-systemd.sh" && ! -f /usr/lib/systemd/system/php-fpm.service ]]; then
/usr/local/src/centminmod/tools/php-systemd.sh fpm-systemd
if [ ! -f /etc/systemd/system/php-fpm.service.d/failure-restart.conf ]; then
cat > "/etc/systemd/system/php-fpm.service.d/failure-restart.conf" <<TDG
[Unit]
StartLimitIntervalSec=30
StartLimitBurst=2

[Service]
Restart=on-failure
RestartSec=5s
TDG
fi
fi
cmservice php-fpm restart
if [ -f /usr/bin/journalctl ]; then
Expand Down
11 changes: 11 additions & 0 deletions tools/php-systemd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@ StartLimitBurst=50
#CPUSchedulingPriority=99
EOF
fi
if [ ! -f /etc/systemd/system/php-fpm.service.d/failure-restart.conf ]; then
cat > "/etc/systemd/system/php-fpm.service.d/failure-restart.conf" <<TDG
[Unit]
StartLimitIntervalSec=30
StartLimitBurst=2
[Service]
Restart=on-failure
RestartSec=5s
TDG
fi

CHECK_FPMSYSTEMD=$(php-config --configure-options | grep -o with-fpm-systemd)

Expand Down

0 comments on commit 67b07bf

Please sign in to comment.