COMPETED CHAINETV ROLE
This commit is contained in:
parent
e8649a2b2f
commit
33b7061716
@ -1,2 +1,12 @@
|
||||
---
|
||||
# defaults file for chainetv
|
||||
|
||||
|
||||
name: chainetv
|
||||
source_location: /srv/chainetv/
|
||||
venv_location: /opt/venv/
|
||||
venv_name: "{{name}}"
|
||||
backendfolder: backend
|
||||
exec_user: root
|
||||
exec_group: root
|
||||
repo: gitea@pi2:vincent/chainetv_web.git
|
||||
|
@ -1,2 +1,21 @@
|
||||
---
|
||||
# handlers file for chainetv
|
||||
|
||||
|
||||
- name: Reload systemd
|
||||
systemd:
|
||||
daemon_reload: yes
|
||||
become: yes
|
||||
|
||||
- name: ensure socket is start
|
||||
systemd:
|
||||
name: "gunicorn-{{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 service
|
||||
systemd:
|
||||
name: "gunicorn-{{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.
|
||||
become: yes
|
@ -55,6 +55,7 @@ galaxy_info:
|
||||
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
|
||||
# Maximum 20 tags per role.
|
||||
|
||||
dependencies: []
|
||||
dependencies:
|
||||
- nginx
|
||||
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
|
||||
# if you add dependencies to this list.
|
@ -1,12 +1,75 @@
|
||||
---
|
||||
# tasks file for chainetv
|
||||
- name: ensure that gunicorn is install
|
||||
pacman:
|
||||
state: present # not required. choices: absent;latest;present. Desired state of the package.
|
||||
upgrade: false # not required. Whether or not to upgrade whole system.
|
||||
force: false # not required. When removing package - force remove package, without any checks. When update_cache - force redownload repo databases.
|
||||
name: gunicorn # not required. Name or list of names of the packages to install, upgrade, or remove.
|
||||
update_cache: false # not required. Whether or not to refresh the master package lists. This can be run as part of a package installation or as a separate step.
|
||||
recurse: false # not required. When removing a package, also remove its dependencies, provided that they are not required by other packages and were not explicitly installed by a user.
|
||||
- name: stat location folder
|
||||
stat:
|
||||
path: "{{source_location}}/dist" # 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: "/tmp/{{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: "{{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
|
||||
when: location_stat.stat.exists == false
|
||||
|
||||
- name: compile client source
|
||||
shell: "/tmp/{{name}}/deploy_client.sh"
|
||||
when: location_stat.stat.exists == false
|
||||
|
||||
- name: copy source
|
||||
synchronize:
|
||||
dest: "{{source_location}}" # required. Remote absolute path where the file should be copied to. If I(src) is a directory, this must be a directory too. If I(dest) is a nonexistent path and if either I(dest) ends with "/" or I(src) is a directory, I(dest) is created. If I(src) and I(dest) are files, the parent directory of I(dest) isn't created: the task fails if it doesn't already exist.
|
||||
src: "/tmp/{{name}}/{{backendfolder}}/" # not required. Local path to a file to copy to the remote server; can be absolute or relative. If path is a directory, it is copied recursively. In this case, if path ends with "/", only inside contents of that directory are copied to destination. Otherwise, if it does not end with "/", the directory itself with all contents is copied. This behavior is similar to Rsync.
|
||||
when: location_stat.stat.exists == false
|
||||
delegate_to: "{{ inventory_hostname }}"
|
||||
become: yes
|
||||
|
||||
- name:
|
||||
file:
|
||||
path: "/tmp/{{name}}"
|
||||
state: absent
|
||||
when: location_stat.stat.exists == false
|
||||
|
||||
- name: ensure venv folder exist
|
||||
file:
|
||||
name: "{{venv_location}}"
|
||||
state: directory
|
||||
mode: 0777
|
||||
become: yes
|
||||
|
||||
- name: create venv
|
||||
pip:
|
||||
requirements: "{{source_location}}/requirements.txt"
|
||||
virtualenv: "{{venv_location}}{{venv_name}}"
|
||||
virtualenv_command: /usr/bin/python -m venv
|
||||
|
||||
|
||||
- name: install gunicorn
|
||||
pip:
|
||||
virtualenv: "{{venv_location}}{{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 nginx template
|
||||
template:
|
||||
dest: "/etc/nginx/conf.d/{{name}}.default" # required. Location to render the template to on the remote machine.
|
||||
src: "nginx/{{name}}.default.j2" # required. Path of a Jinja2 formatted template on the Ansible controller. This can be a relative or absolute path.
|
||||
become: yes
|
||||
notify: restart nginx
|
||||
|
||||
- name: apply systemd socket template
|
||||
template:
|
||||
dest: "/etc/systemd/system/gunicorn-{{name}}.socket" # required. Location to render the template to on the remote machine.
|
||||
src: "systemd/gunicorn.socket.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
|
||||
- ensure socket is start
|
||||
|
||||
- name: apply systemd service template
|
||||
template:
|
||||
dest: "/etc/systemd/system/gunicorn-{{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
|
||||
|
@ -1,10 +1,11 @@
|
||||
location /chainetv {
|
||||
alias /srv/chainetv_web/dist;
|
||||
location /{{name}}/static {
|
||||
alias {{source_location}}dist/static;
|
||||
}
|
||||
location /chainetv/api {
|
||||
proxy_pass http://unix:/run/gunicorn/socket;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Scheme $scheme;
|
||||
proxy_set_header X-Script-Name /chainetv;
|
||||
location /{{name}} {
|
||||
proxy_pass http://unix:/run/gunicorn-{{name}}/socket:/;
|
||||
#proxy_set_header Host $host;
|
||||
#proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
#proxy_set_header X-Scheme $scheme;
|
||||
#proxy_set_header X-Script-Name /{{name}}
|
||||
}
|
||||
|
||||
|
@ -1,22 +1,17 @@
|
||||
[Unit]
|
||||
Description=gunicorn daemon
|
||||
Requires=gunicorn.socket
|
||||
Description=gunicorn daemon for {{name}}
|
||||
Requires=gunicorn-{{name}}.socket
|
||||
After=network.target
|
||||
|
||||
[Service]
|
||||
PIDFile=/run/gunicorn/pid
|
||||
User=root
|
||||
Group=root
|
||||
PIDFile=/run/gunicorn-{{name}}/pid
|
||||
User={{exec_user}}
|
||||
Group={{exec_group}}
|
||||
RuntimeDirectory=gunicorn
|
||||
WorkingDirectory=/srv/chainetv_web/backend
|
||||
ExecStart=/usr/bin/gunicorn --pid /run/gunicorn/pid \
|
||||
--bind unix:/run/gunicorn/socket run:app
|
||||
WorkingDirectory={{source_location}}
|
||||
ExecStart={{venv_location}}{{venv_name}}/bin/gunicorn --pid /run/gunicorn-{{name}}/pid \
|
||||
--bind unix:/run/gunicorn-{{name}}/socket run:app
|
||||
ExecReload=/bin/kill -s HUP $MAINPID
|
||||
ExecStop=/bin/kill -s TERM $MAINPID
|
||||
PrivateTmp=true
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
[Unit]
|
||||
Description=gunicorn socket
|
||||
|
||||
|
@ -0,0 +1,10 @@
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
||||
[Unit]
|
||||
Description=gunicorn socket
|
||||
|
||||
[Socket]
|
||||
ListenStream=/run/gunicorn-{{name}}/socket
|
||||
|
||||
[Install]
|
||||
WantedBy=sockets.target
|
@ -1 +0,0 @@
|
||||
d /run/gunicorn 0755 root roor -
|
Loading…
Reference in New Issue
Block a user