From 6010d2aa4f2e8c11503d6b8b88274ffc001aff30 Mon Sep 17 00:00:00 2001 From: vincent Date: Mon, 13 May 2019 19:00:10 +0200 Subject: [PATCH] create supysonic role --- defaults/main.yml | 18 ++++++ handlers/main.yml | 22 +++++++ meta/main.yml | 61 +++++++++++++++++++ tasks/main.yml | 84 +++++++++++++++++++++++++++ templates/supysonic.j2 | 63 ++++++++++++++++++++ templates/systemd/gunicorn.service.j2 | 15 +++++ vars/main.yml | 2 + 7 files changed, 265 insertions(+) create mode 100644 defaults/main.yml create mode 100644 handlers/main.yml create mode 100644 meta/main.yml create mode 100644 tasks/main.yml create mode 100644 templates/supysonic.j2 create mode 100644 templates/systemd/gunicorn.service.j2 create mode 100644 vars/main.yml diff --git a/defaults/main.yml b/defaults/main.yml new file mode 100644 index 0000000..c0a923a --- /dev/null +++ b/defaults/main.yml @@ -0,0 +1,18 @@ +--- +# defaults file for supysonic + + +supysonic_name: supysonic +source_location: /srv/ +venv_location: /opt/venv/ +supysonic_venv_name: "{{supysonic_name}}" +exec_user: root +exec_group: root +supysonic_repo: https://github.com/spl0k/supysonic.git +supysonic_force_site_update: false +supysonic_repo_branch: master +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 diff --git a/handlers/main.yml b/handlers/main.yml new file mode 100644 index 0000000..044cf5c --- /dev/null +++ b/handlers/main.yml @@ -0,0 +1,22 @@ +--- +# handlers file for chainetv + + +- name: Reload systemd + systemd: + daemon_reload: yes + become: yes + +- name: ensure socket is start + systemd: + name: "gunicorn-{{supysonic_name}}.socket" # 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 # not required. Whether the service should start on boot. B(At least one of state and enabled are required.) + 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. + become: yes + +- 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). + 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/meta/main.yml b/meta/main.yml new file mode 100644 index 0000000..dae7197 --- /dev/null +++ b/meta/main.yml @@ -0,0 +1,61 @@ +galaxy_info: + author: your name + description: your description + company: your company (optional) + + # If the issue tracker for your role is not on github, uncomment the + # next line and provide a value + # issue_tracker_url: http://example.com/issue/tracker + + # Some suggested licenses: + # - BSD (default) + # - MIT + # - GPLv2 + # - GPLv3 + # - Apache + # - CC-BY + license: license (GPLv2, CC-BY, etc) + + min_ansible_version: 2.4 + + # If this a Container Enabled role, provide the minimum Ansible Container version. + # min_ansible_container_version: + + # Optionally specify the branch Galaxy will use when accessing the GitHub + # repo for this role. During role install, if no tags are available, + # Galaxy will use this branch. During import Galaxy will access files on + # this branch. If Travis integration is configured, only notifications for this + # branch will be accepted. Otherwise, in all cases, the repo's default branch + # (usually master) will be used. + #github_branch: + + # + # Provide a list of supported platforms, and for each platform a list of versions. + # If you don't wish to enumerate all versions for a particular platform, use 'all'. + # To view available platforms and versions (or releases), visit: + # https://galaxy.ansible.com/api/v1/platforms/ + # + # platforms: + # - name: Fedora + # versions: + # - all + # - 25 + # - name: SomePlatform + # versions: + # - all + # - 1.0 + # - 7 + # - 99.99 + + galaxy_tags: [] + # List tags for your role here, one per line. A tag is a keyword that describes + # and categorizes the role. Users find roles by searching for tags. Be sure to + # remove the '[]' above, if you add tags to this list. + # + # NOTE: A tag is limited to a single word comprised of alphanumeric characters. + # Maximum 20 tags per role. + +dependencies: + - {role: mariadb, become: yes } + # List your role dependencies here, one per line. Be sure to remove the '[]' above, + # if you add dependencies to this list. \ No newline at end of file diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..5dc5510 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,84 @@ +--- +# tasks file for chainetv + +- name: "Ensure database is present" + become: yes + mysql_db: + name: "{{ supysonic_db_name }}" + collation: utf8_general_ci + encoding: utf8 + state: present + register: ttrss_database_creation + + +- name: "Ensure db user is present" + become: yes + mysql_user: + name: "{{ supysonic_db_user }}" + host: localhost + password: "{{ supysonic_db_password }}" + priv: "{{ supysonic_db_name }}.*:ALL" + state: present + +- 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 + +- name: create folder in var + file: + path: "/var/{{supysonic_name}}" # required. Path to the file being managed. + state: directory # not required. choices: absent;directory;file;hard;link;touch. If C(directory), all intermediate subdirectories will be created if they do not exist. Since Ansible 1.7 they will be created with the supplied permissions. If C(file), the file will NOT be created if it does not exist; see the C(touch) value or the M(copy) or M(template) module if you want that behavior. If C(link), the symbolic link will be created or changed. Use C(hard) for hardlinks. If C(absent), directories will be recursively deleted, and files or symlinks will be unlinked. Note that C(absent) will not cause C(file) to fail if the C(path) does not exist as the state did not change. If C(touch) (new in 1.4), an empty file will be created if the C(path) does not exist, while an existing file or directory will receive updated file access and modification times (similar to the way `touch` works from the command line). + become: yes + + +- name: ensure venv folder exist + file: + name: "{{venv_location}}" + state: directory + mode: 0777 + become: yes + + +- name: create venv + pip: + name: "file://{{source_location}}/{{supysonic_name}}" + virtualenv: "{{venv_location}}{{supysonic_venv_name}}" + virtualenv_command: /usr/bin/python -m venv + +- name: install sql client + 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: pymysql + +- name: apply systemd service 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 + +- 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). + + +- 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. + become: yes + notify: + - Reload systemd + - restart supysonic service \ No newline at end of file diff --git a/templates/supysonic.j2 b/templates/supysonic.j2 new file mode 100644 index 0000000..746d43e --- /dev/null +++ b/templates/supysonic.j2 @@ -0,0 +1,63 @@ +[base] +; A database URI. See the 'schema' folder for schema creation scripts +; Default: sqlite:////tmp/supysonic/supysonic.db +;database_uri = sqlite:////var/supysonic/supysonic.db +database_uri = mysql://{{supysonic_db_user}}:{{supysonic_db_password}}@localhost/{{supysonic_db_name}} +;database_uri = postgres://supysonic:supysonic@localhost/supysonic + +; Optional, restrict scanner to these extensions. Default: none +;scanner_extensions = mp3 ogg + +[webapp] +; Optional cache directory. Default: /tmp/supysonic +cache_dir = /var/supysonic/cache + +; Main cache max size in MB. Default: 512 +cache_size = 512 + +; Transcode cache max size in MB. Default: 1024 (1GB) +transcode_cache_size = 1024 + +; Optional rotating log file. Default: none +log_file = /var/supysonic/supysonic.log + +; Log level. Possible values: DEBUG, INFO, WARNING, ERROR, CRITICAL. Default: WARNING +log_level = WARNING + +; Enable the Subsonic REST API. You'll most likely want to keep this on, here for testing purposes. Default: on +;mount_api = on + +; Enable the administrative web interface. Default: on +;mount_webui = on + +[daemon] +; Delay before triggering scanning operation after a change have been detected +; 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 + +; Optional rotating log file for the scanner daemon. Logs to stderr if empty +log_file = /var/supysonic/supysonic-daemon.log +log_level = INFO + +[lastfm] +; API and secret key to enable scrobbling. http://www.last.fm/api/accounts +; Defaults: none +;api_key = +;secret = + +[transcoding] +; Programs used to convert from one format/bitrate to another. Defaults: none +transcoder_mp3_mp3 = lame --quiet --mp3input -b %outrate %srcpath - +transcoder = ffmpeg -i %srcpath -ab %outratek -v 0 -f %outfmt - +decoder_mp3 = mpg123 --quiet -w - %srcpath +decoder_ogg = oggdec -o %srcpath +decoder_flac = flac -d -c -s %srcpath +encoder_mp3 = lame --quiet -b %outrate - - +encoder_ogg = oggenc2 -q -M %outrate - + +[mimetypes] +; Extension to mimetype mappings in case your system has some trouble guessing +; Default: none +;mp3 = audio/mpeg +;ogg = audio/vorbis diff --git a/templates/systemd/gunicorn.service.j2 b/templates/systemd/gunicorn.service.j2 new file mode 100644 index 0000000..da977a7 --- /dev/null +++ b/templates/systemd/gunicorn.service.j2 @@ -0,0 +1,15 @@ +[Unit] +Description=gunicorn daemon for {{supysonic_name}} +After=network.target + +[Service] +PIDFile=/run/gunicorn-{{supysonic_name}}/pid +User={{exec_user}} +Group={{exec_group}} +RuntimeDirectory=gunicorn +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 +ExecReload=/bin/kill -s HUP $MAINPID +ExecStop=/bin/kill -s TERM $MAINPID +PrivateTmp=true + diff --git a/vars/main.yml b/vars/main.yml new file mode 100644 index 0000000..056f891 --- /dev/null +++ b/vars/main.yml @@ -0,0 +1,2 @@ +--- +# vars file for chainetv \ No newline at end of file