init
This commit is contained in:
parent
92236209d1
commit
e56bea4b0f
4 changed files with 102 additions and 0 deletions
39
cleanup.d/delete_devices
Executable file
39
cleanup.d/delete_devices
Executable file
|
@ -0,0 +1,39 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
token_path="$1"
|
||||||
|
base_url="$2"
|
||||||
|
verbose="true"
|
||||||
|
|
||||||
|
warn() {
|
||||||
|
echo "WARN: $@" >&2
|
||||||
|
}
|
||||||
|
log() {
|
||||||
|
if [[ "$verbose" == "true" ]]; then
|
||||||
|
echo "LOG: $@" >&2
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
invoke_req() {
|
||||||
|
log "invoke curl $@"
|
||||||
|
curl -s --header "@${token_path}" --max-time 600 --connect-timeout 600 $@
|
||||||
|
return $?
|
||||||
|
}
|
||||||
|
|
||||||
|
ec=0
|
||||||
|
|
||||||
|
log "starting device cleanup - api url: ${base_url}"
|
||||||
|
|
||||||
|
for user_id in `invoke_req -X GET "${base_url}v2/users" | jq -r '.users[]|.name'`; do
|
||||||
|
log "processing user ${user_id}"
|
||||||
|
for device in `invoke_req -X GET "${base_url}v2/users/${user_id}/devices" | jq -r '.devices|sort_by(.last_seen_ts)[0:-5][]|.device_id'`; do
|
||||||
|
warn "deleting device ${user_id}/${device}"
|
||||||
|
#resp=$(invoke_req -X DELETE "${base_url}v2/users/${user_id}/devices/${device}")
|
||||||
|
#rc=$?
|
||||||
|
#if [[ "$resp" != "{}" ]]; then
|
||||||
|
# ec=$rc
|
||||||
|
# echo "Deletion of device '${user_id}/devices/${device}' failed:" >&2
|
||||||
|
# echo "$resp" | jq '.' >&2
|
||||||
|
#fi
|
||||||
|
done
|
||||||
|
done
|
||||||
|
|
||||||
|
exit $ec
|
32
cleanup.d/purge_media_cache
Executable file
32
cleanup.d/purge_media_cache
Executable file
|
@ -0,0 +1,32 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
token_path="$1"
|
||||||
|
base_url="$2"
|
||||||
|
verbose="true"
|
||||||
|
|
||||||
|
warn() {
|
||||||
|
echo "WARN: $@" >&2
|
||||||
|
}
|
||||||
|
log() {
|
||||||
|
if [[ "$verbose" == "true" ]]; then
|
||||||
|
echo "LOG: $@" >&2
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
invoke_req() {
|
||||||
|
log "invoke curl $@"
|
||||||
|
curl -s --header "@${token_path}" --max-time 600 --connect-timeout 600 $@
|
||||||
|
return $?
|
||||||
|
}
|
||||||
|
|
||||||
|
log "starting media purge - api url: ${base_url}"
|
||||||
|
|
||||||
|
cutoff_ts="$(date -d '-9 months' '+%s')000"
|
||||||
|
|
||||||
|
response="$(invoke_req -X POST --data-raw '{}' "${base_url}v1/purge_media_cache?before_ts=${cutoff_ts}")"
|
||||||
|
rc=$?
|
||||||
|
|
||||||
|
if [[ "$(echo "$response" | jq -r '.deleted')" == "null" ]]; then
|
||||||
|
warn "purge failed: $response"
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit $rc
|
8
install.sh
Executable file
8
install.sh
Executable file
|
@ -0,0 +1,8 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
BASEDIR=$(dirname $0)
|
||||||
|
|
||||||
|
install --owner=0 --group=0 --mode=444 $BASEDIR/matrix-synapse-maintenance.service /etc/systemd/system/
|
||||||
|
|
||||||
|
mkdir -p /etc/matrix-synapse/cleanup.d
|
||||||
|
install --owner=0 --group=0 --mode=555 $BASEDIR/cleanup.d/* /etc/matrix-synapse/cleanup.d/
|
23
matrix-synapse-maintenance.service
Normal file
23
matrix-synapse-maintenance.service
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
[Unit]
|
||||||
|
Description=cleanup tasks for the matrix synapse service
|
||||||
|
|
||||||
|
After=matrix-synapse.service
|
||||||
|
BindsTo=matrix-synapse.service
|
||||||
|
Requisite=matrix-synapse.service
|
||||||
|
|
||||||
|
# Please create a token file
|
||||||
|
ConditionPathExists=/etc/matrix-synapse/cleanup.token
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
Type=simple
|
||||||
|
LoadCredential=token_header:/etc/matrix-synapse/cleanup.token
|
||||||
|
|
||||||
|
ExecStart=/usr/bin/run-parts --verbose --arg=%d/token_header --arg=http://127.0.0.1:8008/_synapse/admin/ -- /etc/matrix-synapse/cleanup.d
|
||||||
|
|
||||||
|
# Matrix user isn't needed for the current scripts
|
||||||
|
# User=matrix-synapse
|
||||||
|
# Group=matrix-synapse
|
||||||
|
DynamicUser=yes
|
||||||
|
|
||||||
|
ProtectSystem=strict
|
||||||
|
ConfigurationDirectory=matrix-synapse/cleanup.d
|
Loading…
Reference in a new issue