Skip to content

Commit

Permalink
Fix the problem that the certificate cannot be automatically renewed …
Browse files Browse the repository at this point in the history
…when port 80 is occupied.
  • Loading branch information
loyess committed Jan 3, 2022
1 parent 970c416 commit 9b8d8a2
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
41 changes: 41 additions & 0 deletions ss-plugins.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,43 @@ install_webserver(){
esac
}

gen_random_minute(){
local _t="$(date -u "+%s")"
echo "$(($_t % 60))"
}

certificate_renew_by_acme(){
if ! check_port_occupy "80"; then
return
fi
do_stop > /dev/null
"/root/.acme.sh"/acme.sh --cron --home "/root/.acme.sh" > /dev/null
do_start > /dev/null
}

add_cron_job_for_acme(){
random_minute="$(gen_random_minute)"
(crontab -l ; echo "${random_minute} 0 * * * \"/root/.acme.sh\"/acme.sh --cron --home \"/root/.acme.sh\" > /dev/null") | sort - | uniq - | crontab -
}

remove_cron_job_for_acme(){
if [ -z "$(crontab -l | grep 'acme.sh --cron')" ]; then
return
fi
crontab -l | sed '/acme.sh --cron/d' | crontab -
}

add_cron_job(){
local random_minute

if ! check_port_occupy "80"; then
return
fi
remove_cron_job_for_acme
random_minute="$(gen_random_minute)"
(crontab -l ; echo "${random_minute} 0 * * * \"${CUR_DIR}\"/ss-plugins.sh renew > /dev/null") | sort - | uniq - | crontab -
}

install_status(){
status_init

Expand Down Expand Up @@ -1297,6 +1334,7 @@ install_step_all(){
install_completed
ldconfig
do_start
add_cron_job
do_show
}

Expand Down Expand Up @@ -1514,6 +1552,9 @@ case ${action} in
catcfg)
do_${action} "${2}"
;;
renew)
certificate_renew_by_acme
;;
help)
usage 0
;;
Expand Down
9 changes: 9 additions & 0 deletions utils/uninstall.sh
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,14 @@ log_file_remove(){
rm -f /var/log/nginx-access.log
}

remove_cron_job(){
if [ -z "$(crontab -l | grep 'ss-plugins.sh renew')" ]; then
return
fi
crontab -l | sed '/ss-plugins.sh renew/d' | crontab -
add_cron_job_for_acme
}

uninstall_services(){
shadowsocks_uninstall
v2ray_plugin_uninstall
Expand All @@ -283,6 +291,7 @@ uninstall_services(){
nginx_uninstall
ipcalc_uninstall
log_file_remove
remove_cron_job
}


Expand Down

0 comments on commit 9b8d8a2

Please sign in to comment.