Prechádzať zdrojové kódy

Cronjob via packages (#1820)

* Final version
Laurence Jones 2 rokov pred
rodič
commit
24b540ecde

+ 4 - 0
config/crowdsec.cron.daily

@@ -0,0 +1,4 @@
+#!/bin/sh
+cscli --error hub update && cscli --error hub upgrade
+systemctl reload crowdsec
+exit 0

+ 1 - 0
debian/crowdsec.cron.daily

@@ -0,0 +1 @@
+../config/crowdsec.cron.daily

+ 0 - 1
debian/postinst

@@ -82,7 +82,6 @@ if [ "$1" = configure ]; then
         set -e
     fi
 
-    install_cronjob
 
     if [[ -f /var/lib/crowdsec/data/crowdsec.db.backup ]]; then
         cp /var/lib/crowdsec/data/crowdsec.db.backup /var/lib/crowdsec/data/crowdsec.db

+ 2 - 2
debian/postrm

@@ -1,7 +1,7 @@
 if [ "$1" = "purge" ]; then
    find /etc/crowdsec -maxdepth 1 -mindepth 1 | grep -v "bouncer" | xargs rm -rf || echo ""
    rm -rf /var/lib/crowdsec
-   if [ -d "/etc/cron.daily/" ] && [ -f "/etc/cron.daily/crowdsec-hub" ]; then
-      rm /etc/cron.daily/crowdsec-hub
+   if [ -f "/etc/cron.daily/crowdsec" ]; then
+      rm /etc/cron.daily/crowdsec
    fi
 fi

+ 6 - 4
rpm/SPECS/crowdsec.spec

@@ -14,8 +14,8 @@ BuildRoot:      %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
 
 BuildRequires:  git
 BuildRequires:  make
-BuildRequires:  jq
 BuildRequires:  systemd
+Requires: crontabs
 %{?fc33:BuildRequires: systemd-rpm-macros}
 %{?fc34:BuildRequires: systemd-rpm-macros}
 %{?fc35:BuildRequires: systemd-rpm-macros}
@@ -52,6 +52,7 @@ mkdir -p %{buildroot}%{_sharedstatedir}/%{name}/plugins
 mkdir -p %{buildroot}%{_sysconfdir}/crowdsec/notifications/
 mkdir -p %{buildroot}%{_libdir}/%{name}/plugins/
 
+
 install -m 755 -D cmd/crowdsec/crowdsec %{buildroot}%{_bindir}/%{name}
 install -m 755 -D cmd/crowdsec-cli/cscli %{buildroot}%{_bindir}/cscli
 install -m 755 -D wizard.sh %{buildroot}/usr/share/crowdsec/wizard.sh
@@ -61,6 +62,7 @@ install -m 600 -D config/config.yaml %{buildroot}%{_sysconfdir}/crowdsec
 install -m 644 -D config/simulation.yaml %{buildroot}%{_sysconfdir}/crowdsec
 install -m 644 -D config/profiles.yaml %{buildroot}%{_sysconfdir}/crowdsec
 install -m 644 -D config/console.yaml %{buildroot}%{_sysconfdir}/crowdsec
+install -m 750 -D config/%{name}.cron.daily %{buildroot}%{_sysconfdir}/cron.daily/%{name}
 install -m 644 -D %{SOURCE1} %{buildroot}%{_presetdir}
 
 install -m 551 plugins/notifications/slack/notification-slack %{buildroot}%{_libdir}/%{name}/plugins/
@@ -118,6 +120,7 @@ rm -rf %{buildroot}
 %config(noreplace) %{_sysconfdir}/%{name}/notifications/slack.yaml
 %config(noreplace) %{_sysconfdir}/%{name}/notifications/splunk.yaml
 %config(noreplace) %{_sysconfdir}/%{name}/notifications/email.yaml
+%config(noreplace) %{_sysconfdir}/cron.daily/%{name}
 
 %{_unitdir}/%{name}.service
 
@@ -175,7 +178,6 @@ if [ $1 == 1 ]; then
     fi
 
     cscli hub update
-    install_cronjob
     CSCLI_BIN_INSTALLED="/usr/bin/cscli" SILENT=true install_collection
 
 #upgrade
@@ -228,8 +230,8 @@ if [ $1 == 0 ]; then
     rm -rf /etc/crowdsec/hub
 fi
 
-if [ -d "/etc/cron.daily/" ] && [ -f "/etc/cron.daily/crowdsec-hub" ]; then
-    rm /etc/cron.daily/crowdsec-hub
+if [ -f "/etc/cron.daily/crowdsec-hub" ]; then
+    rm /etc/cron.daily/crowdsec
 fi
 
 #systemctl stop crowdsec || echo "crowdsec was not started"

+ 0 - 21
wizard.sh

@@ -68,7 +68,6 @@ telnet
 smb
 '
 
-CRON_NAME=/etc/cron.daily/crowdsec-hub
 
 HTTP_PLUGIN_BINARY="./plugins/notifications/http/notification-http"
 SLACK_PLUGIN_BINARY="./plugins/notifications/slack/notification-slack"
@@ -553,22 +552,6 @@ uninstall_crowdsec() {
     log_info "crowdsec successfully uninstalled"
 }
 
-install_cronjob() {
-    log_info "Installing Hub Cronjob"
-    if [[ -d /etc/cron.daily/ ]] && [[ ! -f $CRON_NAME ]]; then
-        echo "/usr/bin/cscli hub update" >> $CRON_NAME
-        echo "/usr/bin/cscli hub upgrade" >> $CRON_NAME
-        chmod 755 $CRON_NAME
-    fi
-}
-
-uninstall_cronjob() {
-    if [[ -d /etc/cron.daily/ ]] && [[ -f $CRON_NAME ]]; then
-        log_info "Uninstall Hub Cronjob"
-        rm $CRON_NAME
-    fi
-}
-
 
 function show_link {
     echo ""
@@ -635,7 +618,6 @@ main() {
         ${CSCLI_BIN_INSTALLED} hub update
         install_collection
         genacquisition
-        install_cronjob
         if ! skip_tmp_acquis; then
             mv "${TMP_ACQUIS_FILE}" "${ACQUIS_TARGET}"
         fi
@@ -656,7 +638,6 @@ main() {
         fi
         check_running_bouncers
         uninstall_crowdsec
-        uninstall_cronjob
         return
     fi
 
@@ -711,8 +692,6 @@ main() {
         mkdir -p "${PATTERNS_PATH}"
         cp "./${PATTERNS_FOLDER}/"* "${PATTERNS_PATH}/"
 
-        # install hub cronjob
-        install_cronjob
         # api register
         ${CSCLI_BIN_INSTALLED} machines add --force "$(cat /etc/machine-id)" -a -f "${CROWDSEC_CONFIG_PATH}/${CLIENT_SECRETS}" || log_fatal "unable to add machine to the local API"
         log_dbg "Crowdsec LAPI registered"