From 2d9ed43ca5bde476851d6e7503d9e7e8e6e0c30d Mon Sep 17 00:00:00 2001 From: vincent Date: Sun, 14 Nov 2021 11:32:06 +0100 Subject: [PATCH] update launcher to supysonic-server --- defaults/main.yml | 4 +-- handlers/main.yml | 12 ++++---- tasks/main.yml | 28 ++++++------------- templates/systemd/supysonic-daemon.service.j2 | 2 +- ...service.j2 => supysonic-server.service.j2} | 7 ++--- tests/inventory | 0 tests/test.yml | 7 +++++ 7 files changed, 25 insertions(+), 35 deletions(-) rename templates/systemd/{gunicorn.service.j2 => supysonic-server.service.j2} (53%) create mode 100644 tests/inventory create mode 100644 tests/test.yml diff --git a/defaults/main.yml b/defaults/main.yml index 6de5dc1..5ab0216 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -1,9 +1,7 @@ --- # defaults file for supysonic - supysonic_name: supysonic -source_location: /srv/ venv_location: /opt/venv/ supysonic_venv_name: "{{supysonic_name}}" exec_user: root @@ -19,4 +17,4 @@ supysonic_db_password: supysonic supysonic_db_name: supysonic supysonic_log_level: INFO -gitea_SQl_target_file: [] \ No newline at end of file +gitea_SQl_target_file: [] diff --git a/handlers/main.yml b/handlers/main.yml index 90d65fe..c00adb6 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -1,23 +1,21 @@ --- # handlers file for chainetv - - name: Reload systemd systemd: daemon_reload: yes become: yes - -- name: restart supysonic service +- name: restart supysonic service systemd: - name: "gunicorn-{{supysonic_name}}.service" # not required. Name of the service. When using in a chroot environment you always need to specify the full name i.e. (crond.service). + name: "supysonic-server.service" # not required. Name of the service. When using in a chroot environment you always need to specify the full name i.e. (crond.service). state: restarted # not required. choices: reloaded;restarted;started;stopped. C(started)/C(stopped) are idempotent actions that will not run commands unless necessary. C(restarted) will always bounce the service. C(reloaded) will always reload. enabled: true - become: yes + become: yes -- name: restart daemon service +- name: restart daemon service systemd: name: "{{supysonic_name}}-daemon.service" # not required. Name of the service. When using in a chroot environment you always need to specify the full name i.e. (crond.service). state: restarted # not required. choices: reloaded;restarted;started;stopped. C(started)/C(stopped) are idempotent actions that will not run commands unless necessary. C(restarted) will always bounce the service. C(reloaded) will always reload. enabled: true - become: yes \ No newline at end of file + become: yes diff --git a/tasks/main.yml b/tasks/main.yml index 350f9de..ab3a995 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -4,22 +4,6 @@ - name: select specific Database tasks include_tasks: "database_{{supysonic_DB_type}}.yml" -- name: stat location folder - stat: - path: "{{source_location}}/{{supysonic_name}}" # required. The full path of the file/object to get the facts of. - register: location_stat - -- name: install source file if not exist - git: - dest: "{{source_location}}/{{supysonic_name}}" # required. The path of where the repository should be checked out. This parameter is required, unless C(clone) is set to C(no). - repo: "{{supysonic_repo}}" # required. git, SSH, or HTTP(S) protocol address of the git repository. - clone: yes # not required. If C(no), do not clone the repository if it does not exist locally - version: "{{supysonic_repo_branch}}" - become: yes - when: location_stat.stat.exists == false or supysonic_force_site_update == true - notify: - - restart supysonic service - - name: create folder in var file: path: "/var/{{supysonic_name}}" # required. Path to the file being managed. @@ -32,12 +16,15 @@ state: directory mode: 0777 become: yes + notify: + - restart supysonic service - name: create venv pip: - name: "file://{{source_location}}/{{supysonic_name}}" + name: "git+{{supysonic_repo}}" virtualenv: "{{venv_location}}{{supysonic_venv_name}}" virtualenv_command: /usr/bin/python -m venv + state: "{{'forcereinstall' if supysonic_force_site_update ==true else 'present'}}" become: yes - name: install sql client @@ -47,6 +34,7 @@ - pymysql - psycopg2 become: yes + - name: apply config template template: dest: "/etc/supysonic" # required. Location to render the template to on the remote machine. @@ -64,8 +52,8 @@ - name: apply systemd service template template: - dest: "/etc/systemd/system/gunicorn-{{supysonic_name}}.service" # required. Location to render the template to on the remote machine. - src: "systemd/gunicorn.service.j2" # required. Path of a Jinja2 formatted template on the Ansible controller. This can be a relative or absolute path. + dest: "/etc/systemd/system/supysonic-server.service" # required. Location to render the template to on the remote machine. + src: "systemd/supysonic-server.service.j2" # required. Path of a Jinja2 formatted template on the Ansible controller. This can be a relative or absolute path. become: yes notify: - Reload systemd @@ -89,7 +77,7 @@ - name: enable supysonic service systemd: - name: "gunicorn-{{supysonic_name}}.service" # not required. Name of the service. When using in a chroot environment you always need to specify the full name i.e. (crond.service). + name: "supysonic-server.service" # not required. Name of the service. When using in a chroot environment you always need to specify the full name i.e. (crond.service). enabled: true state: started become: yes diff --git a/templates/systemd/supysonic-daemon.service.j2 b/templates/systemd/supysonic-daemon.service.j2 index 132e05c..281953c 100644 --- a/templates/systemd/supysonic-daemon.service.j2 +++ b/templates/systemd/supysonic-daemon.service.j2 @@ -7,7 +7,7 @@ User=root Restart=always RestartSec=2s Group=root -WorkingDirectory={{source_location}}/{{supysonic_name}} +WorkingDirectory=/var/{{supysonic_name}} ExecStart={{venv_location}}{{supysonic_venv_name}}/bin/python -m supysonic.daemon diff --git a/templates/systemd/gunicorn.service.j2 b/templates/systemd/supysonic-server.service.j2 similarity index 53% rename from templates/systemd/gunicorn.service.j2 rename to templates/systemd/supysonic-server.service.j2 index 0ce995a..e6a3d99 100644 --- a/templates/systemd/gunicorn.service.j2 +++ b/templates/systemd/supysonic-server.service.j2 @@ -3,12 +3,11 @@ Description=gunicorn daemon for {{supysonic_name}} After=network.target {{ 'postgresql.service' if supysonic_DB_type == 'postgres' else mysqld.service }} [Service] -PIDFile=/run/gunicorn-{{supysonic_name}}/pid +PIDFile=/run/{{supysonic_name}}.pid User={{exec_user}} Group={{exec_group}} -RuntimeDirectory=gunicorn-{{supysonic_name}} -WorkingDirectory={{source_location}}/{{supysonic_name}}/cgi-bin -ExecStart={{venv_location}}{{supysonic_venv_name}}/bin/gunicorn -b 0.0.0.0:8001 --workers=4 --pid /run/gunicorn-{{supysonic_name}}/pid server:app +WorkingDirectory=/var/{{supysonic_name}} +ExecStart={{venv_location}}{{supysonic_venv_name}}/bin/supysonic-server -p 8001 --threads 4 ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s TERM $MAINPID PrivateTmp=true diff --git a/tests/inventory b/tests/inventory new file mode 100644 index 0000000..e69de29 diff --git a/tests/test.yml b/tests/test.yml new file mode 100644 index 0000000..fe7d07d --- /dev/null +++ b/tests/test.yml @@ -0,0 +1,7 @@ +--- +- hosts: all + vars: + supysonic_force_site_update: True + become: True + roles: + - supysonic