mirror of
https://github.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker.git
synced 2025-09-03 11:10:47 +00:00
fix service command for cron jobs
the cron environment usually does not contain $PATH. This fixes cases where users do not use full paths in their crontabs. fixes https://github.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/issues/120#issuecomment-364028147
This commit is contained in:
parent
0ebdfec103
commit
c3624d2d89
1 changed files with 15 additions and 7 deletions
|
@ -140,15 +140,24 @@ update_paths() {
|
||||||
|
|
||||||
service_cmd() {
|
service_cmd() {
|
||||||
# arch linux does not have a 'service' command
|
# arch linux does not have a 'service' command
|
||||||
local svc= svc_list="service systemctl rc-service"
|
local x= svc= svc_list="service systemctl rc-service"
|
||||||
|
|
||||||
for svc in $svc_list; do
|
for x in $svc_list; do
|
||||||
svc=$(which $svc 2>/dev/null)
|
svc=$(which $svc 2>/dev/null)
|
||||||
if [ -n "$svc" ]; then
|
if [ -n "$svc" ]; then
|
||||||
echo $svc
|
case "$x" in
|
||||||
exit 0
|
service) svc="$svc nginx reload";;
|
||||||
|
systemctl) svc="$svc reload nginx.service";;
|
||||||
|
rc-service) svc="$svc nginx reload";;
|
||||||
|
esac
|
||||||
|
break
|
||||||
|
else
|
||||||
|
# centos does not have 'which' by default
|
||||||
|
svc="/usr/sbin/service nginx reload"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
echo $svc
|
||||||
}
|
}
|
||||||
|
|
||||||
sanitize_path() {
|
sanitize_path() {
|
||||||
|
@ -259,8 +268,7 @@ get_options() {
|
||||||
main() {
|
main() {
|
||||||
local REPO=https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master
|
local REPO=https://raw.githubusercontent.com/mitchellkrogza/nginx-ultimate-bad-bot-blocker/master
|
||||||
local file=globalblacklist.conf remote_dir=conf.d url= output= update= status= tmp= retval=
|
local file=globalblacklist.conf remote_dir=conf.d url= output= update= status= tmp= retval=
|
||||||
# default to service (centos does not have 'which' by default)
|
local reload_service=$(service_cmd)
|
||||||
local service=${service_cmd:-"service"}
|
|
||||||
|
|
||||||
# require root
|
# require root
|
||||||
if [ "$(id -u)" != "0" ]; then
|
if [ "$(id -u)" != "0" ]; then
|
||||||
|
@ -307,7 +315,7 @@ main() {
|
||||||
# re-read nginx configuration
|
# re-read nginx configuration
|
||||||
if [ $retval = 0 ]; then
|
if [ $retval = 0 ]; then
|
||||||
|
|
||||||
$service nginx reload 2>&1 >/dev/null
|
$reload_service 2>&1 >/dev/null
|
||||||
if [ $? = 0 ]; then
|
if [ $? = 0 ]; then
|
||||||
status="${BOLDGREEN}[OK]${RESET}"
|
status="${BOLDGREEN}[OK]${RESET}"
|
||||||
print_message "\nReloading NGINX configuration...$status\n"
|
print_message "\nReloading NGINX configuration...$status\n"
|
||||||
|
|
Loading…
Add table
Reference in a new issue