From 94b808395cf2ba3213148a594d719162aa1a0386 Mon Sep 17 00:00:00 2001 From: Martin Geno Date: Sun, 27 Nov 2016 10:06:35 +0100 Subject: [PATCH] add warehost-ftp --- .gitignore | 2 +- warehost-ftp/defaults/main.yml | 6 +++ warehost-ftp/handlers/main.yml | 6 +++ warehost-ftp/meta/main.yml | 4 ++ warehost-ftp/tasks/main.yml | 19 +++++++ warehost-ftp/templates/config.yml | 9 ++++ warehost-ftp/templates/warehost-ftp.unit | 15 ++++++ warehost-host/defaults/main.yml | 10 ++++ warehost-host/handlers/main.yml | 6 +++ warehost-host/meta/main.yml | 4 ++ warehost-host/tasks/main.yml | 26 ++++++++++ warehost-host/templates/caddy.conf | 49 +++++++++++++++++++ warehost-host/templates/config.yml | 14 ++++++ warehost-host/templates/warehost-host.service | 16 ++++++ warehost-host/templates/warehost-host.timer | 9 ++++ warehost-web/defaults/main.yml | 2 +- 16 files changed, 195 insertions(+), 2 deletions(-) create mode 100644 warehost-ftp/defaults/main.yml create mode 100644 warehost-ftp/handlers/main.yml create mode 100644 warehost-ftp/meta/main.yml create mode 100644 warehost-ftp/tasks/main.yml create mode 100644 warehost-ftp/templates/config.yml create mode 100644 warehost-ftp/templates/warehost-ftp.unit create mode 100644 warehost-host/defaults/main.yml create mode 100644 warehost-host/handlers/main.yml create mode 100644 warehost-host/meta/main.yml create mode 100644 warehost-host/tasks/main.yml create mode 100644 warehost-host/templates/caddy.conf create mode 100644 warehost-host/templates/config.yml create mode 100644 warehost-host/templates/warehost-host.service create mode 100644 warehost-host/templates/warehost-host.timer diff --git a/.gitignore b/.gitignore index a718362..45224b7 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ mailserver/files/ warehost-api/files/ warehost-web/files/ warehost-host/files/ - +warehost-ftp/files/ diff --git a/warehost-ftp/defaults/main.yml b/warehost-ftp/defaults/main.yml new file mode 100644 index 0000000..dd98479 --- /dev/null +++ b/warehost-ftp/defaults/main.yml @@ -0,0 +1,6 @@ +--- +warehost_db_host: localhost +warehost_ftp_port: 22 +warehost_ftp_data_path: /srv/ftp +warehost_ftp_host_path: /srv/http/domain +warehost_ftp_web_path: /srv/http/web diff --git a/warehost-ftp/handlers/main.yml b/warehost-ftp/handlers/main.yml new file mode 100644 index 0000000..19e129d --- /dev/null +++ b/warehost-ftp/handlers/main.yml @@ -0,0 +1,6 @@ +--- +- name: reload daemon-reload + command: systemctl daemon-reload + +- name: restart warehost-ftp + service: name=warehost-ftp state=restarted diff --git a/warehost-ftp/meta/main.yml b/warehost-ftp/meta/main.yml new file mode 100644 index 0000000..af97e9f --- /dev/null +++ b/warehost-ftp/meta/main.yml @@ -0,0 +1,4 @@ +--- +dependencies: +- warehost-meta +- warehost-db diff --git a/warehost-ftp/tasks/main.yml b/warehost-ftp/tasks/main.yml new file mode 100644 index 0000000..05f7395 --- /dev/null +++ b/warehost-ftp/tasks/main.yml @@ -0,0 +1,19 @@ +--- +- name: Download Warehost-ftp (TODO current copy) + copy: src=warehost-ftp dest=/usr/local/bin/warehost-ftp owner=root group=root mode=0755 + +- name: Create data folder + file: path={{warehost_ftp_data_path}} state=directory owner=warehost group=http mode=0770 + +- name: Configurate warehost + template: src=config.yml dest=/etc/warehost/ftp.conf owner=warehost mode=0600 + notify: restart warehost-ftp + +- name: Install service + template: src=warehost-ftp.unit dest=/lib/systemd/system/warehost-ftp.service owner=root mode=644 + notify: + - reload daemon-reload + - restart warehost-ftp + +- name: Enable warehost + service: name=warehost-ftp state=started enabled=yes diff --git a/warehost-ftp/templates/config.yml b/warehost-ftp/templates/config.yml new file mode 100644 index 0000000..323ae9a --- /dev/null +++ b/warehost-ftp/templates/config.yml @@ -0,0 +1,9 @@ +--- +database: "host={{warehost_db_host}} user={{warehost_db_user}} dbname={{warehost_db_dbname}} password={{warehost_db_pass}} sslmode=disable" +log: + path: /var/log/warehost/ftp.log +databasedebug: false +port: {{warehost_ftp_port}} +data: {{warehost_ftp_data_path}}/%d/ +host: {{warehost_ftp_host_path}}/%s/ +web: {{warehost_ftp_web_path}}/%d/ diff --git a/warehost-ftp/templates/warehost-ftp.unit b/warehost-ftp/templates/warehost-ftp.unit new file mode 100644 index 0000000..fd525b6 --- /dev/null +++ b/warehost-ftp/templates/warehost-ftp.unit @@ -0,0 +1,15 @@ +[Unit] +Description=Warehost ftp v2 +After=syslog.target +After=network.target +After=postgresql.service + +[Service] +Type=simple +User=warehost +Group=nobody +ExecStart=/usr/local/bin/warehost-ftp -c /etc/warehost/ftp.conf +Restart=always + +[Install] +WantedBy=multi-user.target diff --git a/warehost-host/defaults/main.yml b/warehost-host/defaults/main.yml new file mode 100644 index 0000000..5cf420f --- /dev/null +++ b/warehost-host/defaults/main.yml @@ -0,0 +1,10 @@ +--- +warehost_db_host: localhost +warehost_host_web_type: caddy +warehost_host_web_path: /etc/caddy/hosts/50-gen-warehost.act +warehost_host_web_webroot: /srv/http/domain +warehost_host_db_type: mysql +warehost_host_db_host: "" +warehost_host_db_user: root +warehost_host_db_pass: "{{ lookup('password', 'credentials/mysql_root length=15') }}" +warehost_host_db_prefix: warehost_db diff --git a/warehost-host/handlers/main.yml b/warehost-host/handlers/main.yml new file mode 100644 index 0000000..e37b0a1 --- /dev/null +++ b/warehost-host/handlers/main.yml @@ -0,0 +1,6 @@ +--- +- name: reload daemon-reload + command: systemctl daemon-reload + +- name: restart warehost-host + service: name=warehost-host.timer state=restarted diff --git a/warehost-host/meta/main.yml b/warehost-host/meta/main.yml new file mode 100644 index 0000000..af97e9f --- /dev/null +++ b/warehost-host/meta/main.yml @@ -0,0 +1,4 @@ +--- +dependencies: +- warehost-meta +- warehost-db diff --git a/warehost-host/tasks/main.yml b/warehost-host/tasks/main.yml new file mode 100644 index 0000000..2b95518 --- /dev/null +++ b/warehost-host/tasks/main.yml @@ -0,0 +1,26 @@ +--- +- name: Download Warehost-host (TODO current copy) + copy: src=warehost-host dest=/usr/local/bin/warehost-host owner=root group=root mode=0755 + +- name: Configurate warehost-host + template: src=config.yml dest=/etc/warehost/host.conf owner=warehost mode=0600 + notify: restart warehost-host + +- name: Configurate host template + template: src={{warehost_host_web_type}}.conf dest=/etc/warehost/host-web.tmpl owner=warehost mode=0600 + notify: restart warehost-host + +- name: Configurate warehost-host + file: path={{warehost_host_web_path}} state=touch owner=warehost group=http mode=0660 + +- name: Install service + template: src=warehost-host.{{item}} dest=/lib/systemd/system/warehost-host.{{item}} owner=root mode=644 + with_items: + - service + - timer + notify: + - reload daemon-reload + - restart warehost-host + +- name: Enable warehost + service: name=warehost-host.timer state=started enabled=yes diff --git a/warehost-host/templates/caddy.conf b/warehost-host/templates/caddy.conf new file mode 100644 index 0000000..2661ece --- /dev/null +++ b/warehost-host/templates/caddy.conf @@ -0,0 +1,49 @@ +#jinja2:variable_start_string:'[%' , variable_end_string:'%]' +# ID: {{.ID}} - Domain: {{.Domain.ID}} - Profil: {{.Domain.Profil.ID}} +# Login: {{.Domain.Profil.Login.ID}} -> {{.Domain.Profil.Login.Username}} +# {{.Subdomain}} - {{.Domain.FQDN}} + +{{ define "domain" }}{{if .Subdomain}}{{.Subdomain}}.{{end}}{{.Domain.FQDN}}{{ end }} +{{ define "content"}} + {{if not .Redirect}} + gzip + {{if .Proxy}} + proxy / {{.Proxy}} + {{else}} + root [% warehost_host_web_webroot %]/{{template "domain" .}} + {{if .PHP}} + fastcgi / unix:/run/php-fpm/php-fpm.sock php { + env PHP_ADMIN_VALUE "open_basedir=/tmp:/usr/share/webapps/:/etc/webapps/:/usr/share/pear:/dev/urandom:[% warehost_host_web_webroot %]/{{template "domain" .}}" + } + rewrite { + to {path} {path}/ /index.php?_url={uri} + } + {{end}} + {{end}} + {{else}} + redir https://{{.Redirect}}{uri} + {{end}} +{{end}} + +{{if .SSL}} +{{if .SSLRedirect}} +http://{{template "domain".}} { + {{if not .Redirect}} + redir https://{{template "domain".}}{uri} + {{else}} + {{template "content" .}} + {{end}} +} +https://{{template "domain".}} { + {{template "content" .}} +} +{{else}} +http://{{template "domain" .}},https://{{template "domain".}} { + {{template "content" .}} +} +{{end}} +{{else}} +http://{{template "domain".}} { + {{template "content" .}} +} +{{end}} diff --git a/warehost-host/templates/config.yml b/warehost-host/templates/config.yml new file mode 100644 index 0000000..6a1ad2b --- /dev/null +++ b/warehost-host/templates/config.yml @@ -0,0 +1,14 @@ +--- +warehostdatabase: "host={{warehost_db_host}} user={{warehost_db_user}} dbname={{warehost_db_dbname}} password={{warehost_db_pass}} sslmode=disable" +log: + path: /var/log/warehost/host.log +databasedebug: false +web: + enable: true + template: /etc/warehost/host-web.tmpl + config: {{warehost_host_web_path}} +database: + enable: true + type: {{warehost_host_db_type}} + connection: "{{warehost_host_db_user}}:{{warehost_host_db_pass}}@{{warehost_host_db_host}}/mysql?interpolateParams=true" + prefix: {{warehost_host_db_prefix}} diff --git a/warehost-host/templates/warehost-host.service b/warehost-host/templates/warehost-host.service new file mode 100644 index 0000000..43a6c77 --- /dev/null +++ b/warehost-host/templates/warehost-host.service @@ -0,0 +1,16 @@ +[Unit] +Description=Warehost host to configurate the Webserver and Database +After=syslog.target +After=network.target +After=postgresql.service + +[Service] +Type=oneshot +User=warehost +Group=nobody +ExecStart=/usr/local/bin/warehost-host -c /etc/warehost/host.conf +PermissionsStartOnly=true +ExecStartPost=/usr/bin/systemctl reload {{warehost_host_web_type}} + +[Install] +WantedBy=multi-user.target diff --git a/warehost-host/templates/warehost-host.timer b/warehost-host/templates/warehost-host.timer new file mode 100644 index 0000000..7de7da2 --- /dev/null +++ b/warehost-host/templates/warehost-host.timer @@ -0,0 +1,9 @@ +[Unit] +Description=Warehost host to configurate the Webserver and Database + +[Timer] +OnBootSec=15min +OnUnitActiveSec=5min + +[Install] +WantedBy=timers.target diff --git a/warehost-web/defaults/main.yml b/warehost-web/defaults/main.yml index 55bc4ba..45ac772 100644 --- a/warehost-web/defaults/main.yml +++ b/warehost-web/defaults/main.yml @@ -2,4 +2,4 @@ warehost_db_host: localhost warehost_web_internal_ip: 127.0.0.1 warehost_web_internal_port: 60000 -warehost_web_webroot: /srv/warehost-web +warehost_web_webroot: /srv/http/web