diff --git a/ss-plugins.sh b/ss-plugins.sh index 6eed0a4..d1f3698 100644 --- a/ss-plugins.sh +++ b/ss-plugins.sh @@ -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 @@ -1297,6 +1334,7 @@ install_step_all(){ install_completed ldconfig do_start + add_cron_job do_show } @@ -1514,6 +1552,9 @@ case ${action} in catcfg) do_${action} "${2}" ;; + renew) + certificate_renew_by_acme + ;; help) usage 0 ;; diff --git a/utils/uninstall.sh b/utils/uninstall.sh index fb060be..801c5ca 100644 --- a/utils/uninstall.sh +++ b/utils/uninstall.sh @@ -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 @@ -283,6 +291,7 @@ uninstall_services(){ nginx_uninstall ipcalc_uninstall log_file_remove + remove_cron_job }