Skip to content

Commit

Permalink
Cronjob via packages (#1820)
Browse files Browse the repository at this point in the history
* Final version
  • Loading branch information
LaurenceJJones authored Oct 18, 2022
1 parent 487bf4e commit 24b540e
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 28 deletions.
4 changes: 4 additions & 0 deletions config/crowdsec.cron.daily
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
cscli --error hub update && cscli --error hub upgrade
systemctl reload crowdsec
exit 0
1 change: 1 addition & 0 deletions debian/crowdsec.cron.daily
1 change: 0 additions & 1 deletion debian/postinst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions debian/postrm
Original file line number Diff line number Diff line change
@@ -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
10 changes: 6 additions & 4 deletions rpm/SPECS/crowdsec.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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
Expand All @@ -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/
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
21 changes: 0 additions & 21 deletions wizard.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 ""
Expand Down Expand Up @@ -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
Expand All @@ -656,7 +638,6 @@ main() {
fi
check_running_bouncers
uninstall_crowdsec
uninstall_cronjob
return
fi

Expand Down Expand Up @@ -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"
Expand Down

0 comments on commit 24b540e

Please sign in to comment.