2023-12-07 20:07:33 +00:00
|
|
|
version = node.metadata.get('paperless/version')
|
|
|
|
workers = ('consumer', 'scheduler', 'taskqueue', 'webserver')
|
|
|
|
|
|
|
|
users['paperless'] = {
|
|
|
|
'home': '/opt/paperless',
|
2021-05-23 15:41:19 +00:00
|
|
|
}
|
|
|
|
|
2023-12-07 20:07:33 +00:00
|
|
|
directories['/opt/paperless'] = {}
|
|
|
|
|
|
|
|
directories['/opt/paperless/static'] = {
|
|
|
|
'owner': 'paperless',
|
2021-05-23 15:41:19 +00:00
|
|
|
}
|
|
|
|
|
2023-12-07 20:07:33 +00:00
|
|
|
|
|
|
|
files['/opt/paperless/paperless.conf'] = {
|
|
|
|
'content_type': 'mako',
|
|
|
|
'triggers': {
|
|
|
|
f'svc_systemd:paperless-{worker}:restart'
|
|
|
|
for worker in workers
|
2021-05-23 15:41:19 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-12-07 20:07:33 +00:00
|
|
|
actions['paperless_create_virtualenv'] = {
|
|
|
|
'command': '/usr/bin/python3 -m virtualenv -p python3 /opt/paperless/venv/',
|
|
|
|
'unless': 'test -d /opt/paperless/venv/',
|
|
|
|
'needs': {
|
|
|
|
'directory:/opt/paperless',
|
|
|
|
'pkg_apt:python3',
|
|
|
|
'pkg_apt:python3-pip',
|
|
|
|
'pkg_apt:python3-virtualenv',
|
2021-05-23 15:41:19 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2023-12-07 20:07:33 +00:00
|
|
|
actions['paperless_install'] = {
|
|
|
|
'command': ' && '.join([
|
|
|
|
f'wget -qO /opt/paperless/{version}.tar.xz https://github.com/paperless-ngx/paperless-ngx/releases/download/{version}/paperless-ngx-{version}.tar.xz',
|
|
|
|
'rm -rf /opt/paperless/src/',
|
|
|
|
'mkdir -p /opt/paperless/src/',
|
|
|
|
f'tar -C /opt/paperless/src -xf /opt/paperless/{version}.tar.xz',
|
|
|
|
f'rm /opt/paperless/{version}.tar.xz',
|
|
|
|
'cd /opt/paperless/src/paperless-ngx',
|
|
|
|
'/opt/paperless/venv/bin/pip install --upgrade pip',
|
|
|
|
'/opt/paperless/venv/bin/pip install --upgrade -r requirements.txt',
|
|
|
|
f'echo "{version}" > /opt/paperless/version',
|
|
|
|
]),
|
|
|
|
'unless': f'''bash -c '[[ "$(cat /opt/paperless/version)" == "{version}" ]]' ''',
|
|
|
|
'after': {
|
|
|
|
'pkg_apt:',
|
2021-05-23 15:41:19 +00:00
|
|
|
},
|
2023-12-07 20:07:33 +00:00
|
|
|
'needs': {
|
|
|
|
'action:paperless_create_virtualenv',
|
2021-05-23 15:41:19 +00:00
|
|
|
},
|
2023-12-07 20:07:33 +00:00
|
|
|
'triggers': {
|
|
|
|
'action:paperless_migrate_database',
|
2021-05-23 15:41:19 +00:00
|
|
|
},
|
2023-12-07 20:07:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
actions['paperless_migrate_database'] = {
|
|
|
|
'command': ' && '.join([
|
|
|
|
'cd /opt/paperless/src/paperless-ngx/src',
|
|
|
|
'sudo -Hu paperless PAPERLESS_CONFIGURATION_PATH=/opt/paperless/paperless.conf /opt/paperless/venv/bin/python manage.py migrate',
|
|
|
|
]),
|
|
|
|
'triggered': True,
|
|
|
|
'needs': {
|
|
|
|
# /mnt/paperless is NOT created by this bundle.
|
|
|
|
'action:paperless_install',
|
|
|
|
'directory:/mnt/paperless',
|
|
|
|
'directory:/opt/paperless/static',
|
|
|
|
'file:/opt/paperless/paperless.conf',
|
|
|
|
'user:paperless',
|
|
|
|
'postgres_db:paperless',
|
2021-05-24 13:02:04 +00:00
|
|
|
},
|
2021-05-23 15:41:19 +00:00
|
|
|
}
|
|
|
|
|
2023-12-07 20:07:33 +00:00
|
|
|
for worker in workers:
|
|
|
|
files[f'/etc/systemd/system/paperless-{worker}.service'] = {
|
|
|
|
'delete': True,
|
|
|
|
'triggers': {
|
|
|
|
'action:systemd-reload',
|
2021-05-23 15:41:19 +00:00
|
|
|
},
|
2023-12-07 20:07:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
files[f'/usr/local/lib/systemd/system/paperless-{worker}.service'] = {
|
|
|
|
'triggers': {
|
|
|
|
'action:systemd-reload',
|
|
|
|
f'svc_systemd:paperless-{worker}:restart',
|
2021-05-23 15:41:19 +00:00
|
|
|
},
|
2023-12-07 20:07:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
svc_systemd[f'paperless-{worker}'] = {
|
2021-05-23 15:41:19 +00:00
|
|
|
'needs': {
|
2023-12-07 20:07:33 +00:00
|
|
|
'action:paperless_install',
|
2021-05-23 15:41:19 +00:00
|
|
|
'action:paperless_migrate_database',
|
2023-12-07 20:07:33 +00:00
|
|
|
f'file:/usr/local/lib/systemd/system/paperless-{worker}.service',
|
2021-05-23 15:41:19 +00:00
|
|
|
},
|
2023-12-07 20:07:33 +00:00
|
|
|
}
|