Skip to content

Commit

Permalink
feat: always install libretime in a python venv
Browse files Browse the repository at this point in the history
  • Loading branch information
jooola committed May 12, 2023
1 parent d74692a commit 52e7c70
Show file tree
Hide file tree
Showing 14 changed files with 50 additions and 37 deletions.
4 changes: 1 addition & 3 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ libretime_log_dir: /var/log/libretime
libretime_config_dir: /etc/libretime
libretime_config_filepath: "{{ libretime_config_dir }}/config.yml"
libretime_storage_dir: /srv/libretime

# Experimental !
# libretime_venv:
libretime_venv_dir: /opt/libretime

# > Analyzer
########################################################################################
Expand Down
1 change: 0 additions & 1 deletion molecule/default/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ provisioner:
instance2:
libretime_public_url: http://localhost:{{ libretime_listen_port }}/
libretime_listen_port: 9002
libretime_venv: /opt/libretime

verifier:
name: testinfra
11 changes: 10 additions & 1 deletion tasks/analyzer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,19 @@
libretime-analyzer[{{ libretime_analyzer_pip_extras | join(',') }}]
@ file://{{ libretime_checkout_dest }}/analyzer
state: latest # noqa package-latest
virtualenv: "{{ libretime_venv | default(omit) }}"
virtualenv: "{{ libretime_venv_dir }}"
notify: Restart libretime
when: libretime_checkout is changed

- name: Create analyzer entrypoint symlinks
ansible.builtin.file:
src: "{{ libretime_venv_dir }}/bin/libretime-analyzer"
dest: /usr/local/bin/libretime-analyzer
owner: root
group: root
state: link
force: true

- name: Create analyzer home directory
ansible.builtin.file:
path: "{{ libretime_home }}/analyzer"
Expand Down
11 changes: 10 additions & 1 deletion tasks/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,19 @@
libretime-api[{{ (['prod'] + libretime_api_pip_extras) | join(',') }}]
@ file://{{ libretime_checkout_dest }}/api
state: latest # noqa package-latest
virtualenv: "{{ libretime_venv | default(omit) }}"
virtualenv: "{{ libretime_venv_dir }}"
notify: Restart libretime
when: libretime_checkout is changed

- name: Create api entrypoint symlinks
ansible.builtin.file:
src: "{{ libretime_venv_dir }}/bin/libretime-api"
dest: /usr/local/bin/libretime-api
owner: root
group: root
state: link
force: true

- name: Setup api systemd socket
ansible.builtin.import_tasks: _systemd.yml
vars:
Expand Down
2 changes: 1 addition & 1 deletion tasks/api_client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
libretime-api-client
@ file://{{ libretime_checkout_dest }}/api-client
state: latest # noqa package-latest
virtualenv: "{{ libretime_venv | default(omit) }}"
virtualenv: "{{ libretime_venv_dir }}"
notify: Restart libretime
when: libretime_checkout is changed
4 changes: 2 additions & 2 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
ansible.builtin.pip:
name: [pip, setuptools, wheel]
state: latest # noqa package-latest
virtualenv: "{{ libretime_venv | default(omit) }}"
virtualenv: "{{ libretime_venv_dir }}"
virtualenv_command: python3 -m venv
virtualenv_site_packages: true

Expand Down Expand Up @@ -155,7 +155,7 @@
- name: Run database migration
become: true
become_user: "{{ libretime_user }}"
ansible.builtin.command: "{{ libretime_venv | default('/usr/local') }}/bin/libretime-api migrate"
ansible.builtin.command: "{{ libretime_venv_dir }}/bin/libretime-api migrate"
register: migration
changed_when: >
"No migrations to apply." not in migration.stdout
Expand Down
15 changes: 14 additions & 1 deletion tasks/playout.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,23 @@
libretime-playout[{{ libretime_playout_pip_extras | join(',') }}]
@ file://{{ libretime_checkout_dest }}/playout
state: latest # noqa package-latest
virtualenv: "{{ libretime_venv | default(omit) }}"
virtualenv: "{{ libretime_venv_dir }}"
notify: Restart libretime
when: libretime_checkout is changed

- name: Create playout entrypoint symlinks
ansible.builtin.file:
src: "{{ libretime_venv_dir }}/bin/{{ item }}"
dest: /usr/local/bin/{{ item }}
owner: root
group: root
state: link
force: true
with_items:
- libretime-liquidsoap
- libretime-playout
- libretime-playout-notify

- name: Create playout home directory
ansible.builtin.file:
path: "{{ libretime_home }}/playout"
Expand Down
2 changes: 1 addition & 1 deletion tasks/shared.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
libretime-shared
@ file://{{ libretime_checkout_dest }}/shared
state: latest # noqa package-latest
virtualenv: "{{ libretime_venv | default(omit) }}"
virtualenv: "{{ libretime_venv_dir }}"
notify: Restart libretime
when: libretime_checkout is changed
2 changes: 1 addition & 1 deletion tasks/worker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
libretime-worker[{{ libretime_worker_pip_extras | join(',') }}]
@ file://{{ libretime_checkout_dest }}/worker
state: latest # noqa package-latest
virtualenv: "{{ libretime_venv | default(omit) }}"
virtualenv: "{{ libretime_venv_dir }}"
notify: Restart libretime
when: libretime_checkout is changed

Expand Down
7 changes: 2 additions & 5 deletions templates/systemd/libretime-analyzer.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@ ProtectKernelTunables=true
ProtectProc=invisible
ProtectSystem=full

{% if libretime_venv is defined %}
Environment=PATH={{ libretime_venv }}/bin:/usr/local/bin:/usr/bin:/bin
{% endif %}

Environment=PATH={{ libretime_venv_dir }}/bin:/usr/local/bin:/usr/bin:/bin
Environment=LIBRETIME_CONFIG_FILEPATH={{ libretime_config_filepath }}
Environment=LIBRETIME_LOG_FILEPATH={{ libretime_log_dir }}/analyzer.log
WorkingDirectory={{ libretime_home }}/analyzer

ExecStart={{ libretime_venv | default('/usr/local') }}/bin/libretime-analyzer
ExecStart={{ libretime_venv_dir }}/bin/libretime-analyzer
Restart=always

User={{ libretime_user }}
Expand Down
7 changes: 2 additions & 5 deletions templates/systemd/libretime-api.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,13 @@ ProtectKernelTunables=true
ProtectProc=invisible
ProtectSystem=full

{% if libretime_venv is defined %}
Environment=PATH={{ libretime_venv }}/bin:/usr/local/bin:/usr/bin:/bin
{% endif %}

Environment=PATH={{ libretime_venv_dir }}/bin:/usr/local/bin:/usr/bin:/bin
Environment=LIBRETIME_CONFIG_FILEPATH={{ libretime_config_filepath }}
Environment=LIBRETIME_LOG_FILEPATH={{ libretime_log_dir }}/api.log

Type=notify
KillMode=mixed
ExecStart={{ libretime_venv | default('/usr') }}/bin/python3 -m gunicorn \
ExecStart={{ libretime_venv_dir }}/bin/python3 -m gunicorn \
--workers 4 \
--worker-class uvicorn.workers.UvicornWorker \
--log-file - \
Expand Down
7 changes: 2 additions & 5 deletions templates/systemd/libretime-liquidsoap.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@ ProtectKernelTunables=true
ProtectProc=invisible
ProtectSystem=full

{% if libretime_venv is defined %}
Environment=PATH={{ libretime_venv }}/bin:/usr/local/bin:/usr/bin:/bin
{% endif %}

Environment=PATH={{ libretime_venv_dir }}/bin:/usr/local/bin:/usr/bin:/bin
Environment=LIBRETIME_CONFIG_FILEPATH={{ libretime_config_filepath }}
Environment=LIBRETIME_LOG_FILEPATH={{ libretime_log_dir }}/liquidsoap.log
WorkingDirectory={{ libretime_home }}/playout

ExecStart={{ libretime_venv | default('/usr/local') }}/bin/libretime-liquidsoap
ExecStart={{ libretime_venv_dir }}/bin/libretime-liquidsoap
Restart=always

User={{ libretime_user }}
Expand Down
7 changes: 2 additions & 5 deletions templates/systemd/libretime-playout.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,12 @@ ProtectKernelTunables=true
ProtectProc=invisible
ProtectSystem=full

{% if libretime_venv is defined %}
Environment=PATH={{ libretime_venv }}/bin:/usr/local/bin:/usr/bin:/bin
{% endif %}

Environment=PATH={{ libretime_venv_dir }}/bin:/usr/local/bin:/usr/bin:/bin
Environment=LIBRETIME_CONFIG_FILEPATH={{ libretime_config_filepath }}
Environment=LIBRETIME_LOG_FILEPATH={{ libretime_log_dir }}/playout.log
WorkingDirectory={{ libretime_home }}/playout

ExecStart={{ libretime_venv | default('/usr/local') }}/bin/libretime-playout
ExecStart={{ libretime_venv_dir }}/bin/libretime-playout
Restart=always

User={{ libretime_user }}
Expand Down
7 changes: 2 additions & 5 deletions templates/systemd/libretime-worker.service.j2
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,12 @@ ProtectKernelTunables=true
ProtectProc=invisible
ProtectSystem=full

{% if libretime_venv is defined %}
Environment=PATH={{ libretime_venv }}/bin:/usr/local/bin:/usr/bin:/bin
{% endif %}

Environment=PATH={{ libretime_venv_dir }}/bin:/usr/local/bin:/usr/bin:/bin
Environment=LIBRETIME_CONFIG_FILEPATH={{ libretime_config_filepath }}
Environment=LIBRETIME_LOG_FILEPATH={{ libretime_log_dir }}/worker.log
WorkingDirectory={{ libretime_home }}/worker

ExecStart=/usr/bin/sh -c '{{ libretime_venv | default('/usr/local') }}/bin/celery worker \
ExecStart=/usr/bin/sh -c '{{ libretime_venv_dir }}/bin/celery worker \
--app=libretime_worker.tasks:worker \
--config=libretime_worker.config \
--time-limit=1800 \
Expand Down

0 comments on commit 52e7c70

Please sign in to comment.