From 7fa9bf43c02a0f976f7405caf7bae030a0f3f3c6 Mon Sep 17 00:00:00 2001 From: vincent Date: Sun, 17 Nov 2019 17:12:24 +0100 Subject: [PATCH] add supysonic daemon --- defaults/main.yml | 3 +- handlers/main.yml | 9 +++++- tasks/main.yml | 30 ++++++++++++++----- templates/supysonic.j2 | 5 ++-- templates/systemd/supysonic-daemon.service.j2 | 13 ++++++++ 5 files changed, 49 insertions(+), 11 deletions(-) create mode 100644 templates/systemd/supysonic-daemon.service.j2 diff --git a/defaults/main.yml b/defaults/main.yml index c0a923a..5d8ba4b 100644 --- a/defaults/main.yml +++ b/defaults/main.yml @@ -15,4 +15,5 @@ supysonic_db_user: supysonic # Database password, please change when using the role supysonic_db_password: supysonic # Database name -supysonic_db_name: supysonic \ No newline at end of file +supysonic_db_name: supysonic +supysonic_log_level: INFO \ No newline at end of file diff --git a/handlers/main.yml b/handlers/main.yml index 7b867cc..90d65fe 100644 --- a/handlers/main.yml +++ b/handlers/main.yml @@ -13,4 +13,11 @@ 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). 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 + +- 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 diff --git a/tasks/main.yml b/tasks/main.yml index 9757a15..1bf070b 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -34,7 +34,7 @@ become: yes when: location_stat.stat.exists == false or supysonic_force_site_update == true notify: - - restart supysonic service + - restart supysonic service - name: create folder in var file: @@ -62,18 +62,19 @@ virtualenv: "{{venv_location}}{{supysonic_venv_name}}" # not required. An optional path to a I(virtualenv) directory to install into. It cannot be specified together with the 'executable' parameter (added in 2.1). If the virtualenv does not exist, it will be created before installing packages. The optional virtualenv_site_packages, virtualenv_command, and virtualenv_python options affect the creation of the virtualenv. name: pymysql -- name: apply systemd service template +- name: apply config template template: dest: "/etc/supysonic" # required. Location to render the template to on the remote machine. src: "supysonic.j2" # required. Path of a Jinja2 formatted template on the Ansible controller. This can be a relative or absolute path. become: yes notify: - - restart supysonic service + - restart supysonic service + - restart daemon service - name: install gunicorn pip: - virtualenv: "{{venv_location}}{{supysonic_venv_name}}" # not required. An optional path to a I(virtualenv) directory to install into. It cannot be specified together with the 'executable' parameter (added in 2.1). If the virtualenv does not exist, it will be created before installing packages. The optional virtualenv_site_packages, virtualenv_command, and virtualenv_python options affect the creation of the virtualenv. - name: gunicorn # not required. The name of a Python library to install or the url(bzr+,hg+,git+,svn+) of the remote package.,This can be a list (since 2.2) and contain version specifiers (since 2.7). + virtualenv: "{{venv_location}}{{supysonic_venv_name}}" # not required. An optional path to a I(virtualenv) directory to install into. It cannot be specified together with the 'executable' parameter (added in 2.1). If the virtualenv does not exist, it will be created before installing packages. The optional virtualenv_site_packages, virtualenv_command, and virtualenv_python options affect the creation of the virtualenv. + name: gunicorn # not required. The name of a Python library to install or the url(bzr+,hg+,git+,svn+) of the remote package.,This can be a list (since 2.2) and contain version specifiers (since 2.7). - name: apply systemd service template @@ -82,8 +83,23 @@ src: "systemd/gunicorn.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 - - restart supysonic service + - Reload systemd + - restart supysonic service + +- name: apply systemd daemon template + template: + dest: "/etc/systemd/system/{{supysonic_name}}-daemon.service" # required. Location to render the template to on the remote machine. + src: "systemd/supysonic-daemon.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 + - restart daemon service + +- name: enable daemon 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). + enabled: true + become: yes - name: enable supysonic service systemd: diff --git a/templates/supysonic.j2 b/templates/supysonic.j2 index 746d43e..adeaa6a 100644 --- a/templates/supysonic.j2 +++ b/templates/supysonic.j2 @@ -22,7 +22,7 @@ transcode_cache_size = 1024 log_file = /var/supysonic/supysonic.log ; Log level. Possible values: DEBUG, INFO, WARNING, ERROR, CRITICAL. Default: WARNING -log_level = WARNING +log_level = {{supysonic_log_level}} ; Enable the Subsonic REST API. You'll most likely want to keep this on, here for testing purposes. Default: on ;mount_api = on @@ -35,10 +35,11 @@ log_level = WARNING ; This prevents running too many scans when multiple changes are detected for a ; single file over a short time span. Default: 5 wait_delay = 5 +socket = /var/run/supysonic.sock ; Optional rotating log file for the scanner daemon. Logs to stderr if empty log_file = /var/supysonic/supysonic-daemon.log -log_level = INFO +log_level = {{supysonic_log_level}} [lastfm] ; API and secret key to enable scrobbling. http://www.last.fm/api/accounts diff --git a/templates/systemd/supysonic-daemon.service.j2 b/templates/systemd/supysonic-daemon.service.j2 new file mode 100644 index 0000000..1509ac0 --- /dev/null +++ b/templates/systemd/supysonic-daemon.service.j2 @@ -0,0 +1,13 @@ +[Unit] +Description=Supysonic Daemon + +[Service] +User=root +Group=root +WorkingDirectory={{source_location}}/{{supysonic_name}} +ExecStart={{venv_location}}{{supysonic_venv_name}}/bin/python -m supysonic.daemon +ExecReload=/bin/kill -s HUP $MAINPID +ExecStop=/bin/kill -s TERM $MAINPID + +[Install] +WantedBy=multi-user.target