浏览代码

:bug: fix worker service names

Jeremy Zheng 1 年之前
父节点
当前提交
a40b3e7442

+ 1 - 0
deploy/.gitignore

@@ -1,5 +1,6 @@
 /clients/
 /python/
+/shared/
 /tmp/
 /roles/mint/files/dashboard/
 *.log

+ 1 - 1
deploy/roles/mint-dashboard-v4-build/tasks/main.yml

@@ -26,7 +26,7 @@
     REACT_APP_DOCUMENTS_SERVER: "{{ app_documents_server }}"
     REACT_APP_RPC_SERVER: "{{ app_grpc_web_server }}"
     REACT_APP_ASSETS_SERVER: "{{ app_assets_server }}"
-    REACT_APP_API_SERVER: "https://{{ inventory_hostname }}"
+    REACT_APP_API_SERVER: "https://{{ app_domain }}"
     REACT_APP_ICP_CODE: "{{ app_icp_code }}"
     REACT_APP_MPS_CODE: "{{ app_mps_code }}"
     REACT_APP_QUESTIONNAIRE_LINK: "{{ app_questionnaire_link }}"

+ 16 - 0
deploy/roles/mint-v2.1/files/launch.sh

@@ -26,6 +26,22 @@ if [ "$1" == "setup" ]; then
     composer update --optimize-autoloader --no-dev
     echo "install v1 nodejs packages"
     npm install --production
+
+    echo "check file permissions"
+    cd $WORK_DIR/
+    chown -R www-data:www-data bootstrap/cache storage
+
+    cd $WORK_DIR/
+    echo "caching configuration "
+    su -c php artisan config:cache www-data
+    echo "caching events"
+    su -c php artisan event:cache www-data
+    echo "caching "
+    su -c php artisan www-data
+    echo "caching routes"
+    su -c php artisan route:cache www-data
+    echo "caching views"
+    su -c php artisan view:cache www-data
 else
     $@
 fi

+ 45 - 127
deploy/roles/mint-v2.1/tasks/laravel-v8.yml

@@ -1,5 +1,5 @@
 - name: Upload launch.sh
-  ansible.builtin.template:
+  ansible.builtin.copy:
     src: launch.sh
     dest: "{{ app_deploy_target }}/scripts/"
     mode: "0555"
@@ -12,135 +12,53 @@
       - setup
     chdir: "{{ app_deploy_target }}/"
     creates: "{{ app_deploy_target }}/api-v8/public/node_modules"
-# - name: Setup nodejs packages for v2
-#   ansible.builtin.command:
-#     argv:
-#       - "{{ app_deploy_target }}/docker/mint/run.sh"
-#       - "{{ app_mint_image_name }}"
-#       - npm
-#       - install
-#     chdir: "{{ app_deploy_target }}/api-v8"
-#     creates: "{{ app_deploy_target }}/api-v8/node_modules"
-# - name: Upload .env(v2)
-#   become: true
-#   ansible.builtin.template:
-#     src: v2/env.j2
-#     dest: "{{ app_deploy_target }}/mint/api-v8/.env"
-#     owner: www-data
-#     group: www-data
-#     mode: "0444"
-
-# - name: Upload config.php(v1)
-#   ansible.builtin.become: true
-#   ansible.builtin.template:
-#     src: v1/config.php.j2
-#     dest: "{{ app_deploy_target }}/mint/api-v8/public/app/config.php"
-#     owner: www-data
-#     group: www-data
-#     mode: "0444"
-
-# - name: Upload config.js(v1)
-#   become: true
-#   ansible.builtin.template:
-#     src: v1/config.js.j2
-#     dest: "{{ app_deploy_target }}/mint/api-v8/public/app/config.js"
-#     owner: www-data
-#     group: www-data
-#     mode: "0444"
-
-# - name: Setup bootstrap folder for {{ ansible_user }}
-#   become: true
-#   ansible.builtin.file:
-#     path: "{{ app_deploy_target }}/mint/api-v8/bootstrap/cache"
-#     state: directory
-#     owner: "{{ ansible_user }}"
-#     group: "{{ ansible_user }}"
-#     recurse: true
-
-# - name: Auto-loader optimization for v2
-#   ansible.builtin.command:
-#     argv:
-#       - /usr/bin/composer
-#       - update
-#       - --optimize-autoloader
-#       - --no-dev
-#     chdir: "{{ app_deploy_target }}/api-v8"
-
-# - name: Auto-loader optimization for v1
-#   ansible.builtin.command:
-#     argv:
-
-#     chdir: "{{ app_deploy_target }}/mint/api-v8/public"
-
-# - name: Setup storage folder for v2 for php-fpm
-#   become: true
-#   ansible.builtin.file:
-#     path: "{{ app_deploy_target }}/mint/api-v8/storage"
-#     state: directory
-#     owner: www-data
-#     group: www-data
-#     recurse: true
-
-# - name: Caching configuration
-#   become: true
-#   become_user: www-data
-#   ansible.builtin.command:
-#     argv:
-#       - /usr/bin/php
-#       - artisan
-#       - config:cache
-#     chdir: "{{ app_deploy_target}}/api-v8"
 
-# - name: Caching events
-#   become: true
-#   become_user: www-data
-#   ansible.builtin.command:
-#     argv:
-#       - /usr/bin/php
-#       - artisan
-#       - event:cache
-#     chdir: "{{ app_deploy_target }}/api-v8"
-
-# - name: Caching routes
-#   become: true
-#   become_user: www-data
-#   ansible.builtin.command:
-#     argv:
-#       - /usr/bin/php
-#       - artisan
-#       - route:cache
-#     chdir: "{{ app_deploy_target }}/api-v8"
-
-# - name: Caching views
-#   become: true
-#   become_user: www-data
-#   ansible.builtin.shell:
-#     argv:
-#       - /usr/bin/php
-#       - artisan
-#       - view:cache
-#     chdir: "{{ app_deploy_target }}/api-v8"
-
-# - name: Setup sqlite3 db for v1
-#   become: true
-#   ansible.builtin.file:
-#     src: /var/www/shared/appdata
-#     dest: "{{ app_deploy_target }}/mint/api-v8/storage/app/data"
-#     state: link
-
-# # https://laravel.com/docs/10.x/scheduling#running-the-scheduler
-# - name: Upload scheduler service
-#   become: true
-#   ansible.builtin.template:
-#     src: v2/scheduler.service.j2
-#     dest: /usr/lib/systemd/system/{{ inventory_hostname }}-scheduler.service
-#     owner: root
-#     group: root
-#     mode: "0644"
+- name: Upload .env(v2)
+  ansible.builtin.template:
+    src: v2/env.j2
+    dest: "{{ app_deploy_target }}/api-v8/.env"
+    mode: "0444"
 
-# - name: Setup laravel queue workers
-#   ansible.builtin.import_tasks: queue-workers.yml
+- name: Upload config.php(v1)
+  ansible.builtin.template:
+    src: v1/config.php.j2
+    dest: "{{ app_deploy_target }}/api-v8/public/app/config.php"
+    mode: "0444"
 
+- name: Upload config.js(v1)
+  ansible.builtin.template:
+    src: v1/config.js.j2
+    dest: "{{ app_deploy_target }}/api-v8/public/app/config.js"
+    mode: "0444"
+
+- name: Setup sqlite3 db for v1
+  ansible.builtin.file:
+    src: /mnt/{{ app_domain }}/shared/appdata
+    dest: "{{ app_deploy_target }}/api-v8/storage/app/data"
+    state: link
+
+# https://laravel.com/docs/10.x/scheduling#running-the-scheduler
+- name: Upload scheduler service
+  become: true
+  ansible.builtin.template:
+    src: v2/scheduler.service.j2
+    dest: /usr/lib/systemd/system/scheduler.{{ app_domain }}.service
+    owner: root
+    group: root
+    mode: "0644"
+
+# https://wiki.archlinux.org/title/Systemd/Timers
+- name: Upload scheduler timer
+  become: true
+  ansible.builtin.template:
+    src: v2/scheduler.timer.j2
+    dest: /usr/lib/systemd/system/scheduler.{{ app_domain }}.timer
+    owner: root
+    group: root
+    mode: "0644"
+
+- name: Setup laravel queue workers
+  ansible.builtin.import_tasks: queue-workers.yml
 # - name: Setup morus service
 #   ansible.builtin.import_tasks: morus.yml
 

+ 3 - 5
deploy/roles/mint-v2.0/tasks/lily.yml → deploy/roles/mint-v2.1/tasks/lily.yml

@@ -8,18 +8,16 @@
   become: true
   template:
     src: v2/lily/services/server.service.j2
-    dest: /usr/lib/systemd/system/mint-{{ app_deploy_env }}-lily.service
+    dest: /usr/lib/systemd/system/rpc.lily.{{ app_domain }}.service
     owner: root
     group: root
     mode: "0644"
 
-- name: upload lily rpc worker({{ queue }}) service
+- name: upload lily rpc worker service
   become: true
   template:
     src: v2/lily/services/worker.service.j2
-    dest: /usr/lib/systemd/system/mint-{{ app_deploy_env }}-worker-{{ queue }}.service
+    dest: /usr/lib/systemd/system/worker.lily.{{ app_domain }}.service
     owner: root
     group: root
     mode: "0644"
-  vars:
-    queue: "palm.lily.tex-to-pdf"

+ 5 - 0
deploy/roles/mint-v2.1/tasks/main.yml

@@ -13,6 +13,11 @@
     remote_src: true
     creates: "{{ app_deploy_target }}"
 
+# - name: Upload shared
+#   ansible.posix.synchronize:
+#     src: "{{ playbook_dir }}/shared"
+#     dest: "/mnt/{{ app_domain }}/shared"
+
 - name: Upload dashboard-v4 dist
   ansible.posix.synchronize:
     src: "{{ playbook_dir }}/tmp/mint/dashboard-v4/dashboard/dist-{{ mint_version }}/"

+ 2 - 2
deploy/roles/mint-v2.0/tasks/morus.yml → deploy/roles/mint-v2.1/tasks/morus.yml

@@ -5,13 +5,13 @@
       - install
       - --optimize-autoloader
       - --no-dev
-    chdir: "{{ app_deploy_target }}/mint/dashboard-v4/rpc/morus/morus"
+    chdir: "{{ app_deploy_target }}/dashboard-v4/rpc/morus/morus"
 
 - name: Upload morus rpc service
   become: true
   ansible.builtin.template:
     src: v2/morus.service.j2
-    dest: /usr/lib/systemd/system/{{ inventory_hostname }}-morus.service
+    dest: /usr/lib/systemd/system/morus.{{ app_domain }}.service
     owner: root
     group: root
     mode: "0644"

+ 6 - 6
deploy/roles/mint-v2.1/tasks/queue-workers.yml

@@ -2,7 +2,7 @@
   become: true
   template:
     src: v2/queue-worker.service.j2
-    dest: /usr/lib/systemd/system/{{ inventory_hostname }}-{{ action }}-worker.service
+    dest: /usr/lib/systemd/system/{{ action }}.worker.{{ app_domain }}.service
     owner: root
     group: root
     mode: "0644"
@@ -13,7 +13,7 @@
   become: true
   template:
     src: v2/queue-worker.service.j2
-    dest: /usr/lib/systemd/system/{{ inventory_hostname }}-{{ action }}-worker.service
+    dest: /usr/lib/systemd/system/{{ action }}.worker.{{ app_domain }}.service
     owner: root
     group: root
     mode: "0644"
@@ -24,7 +24,7 @@
   become: true
   template:
     src: v2/queue-worker.service.j2
-    dest: /usr/lib/systemd/system/{{ inventory_hostname }}-{{ action }}-worker.service
+    dest: /usr/lib/systemd/system/{{ action }}.worker.{{ app_domain }}.service
     owner: root
     group: root
     mode: "0644"
@@ -35,7 +35,7 @@
   become: true
   template:
     src: v2/queue-worker.service.j2
-    dest: /usr/lib/systemd/system/{{ inventory_hostname }}-{{ action }}-worker.service
+    dest: /usr/lib/systemd/system/{{ action }}.worker.{{ app_domain }}.service
     owner: root
     group: root
     mode: "0644"
@@ -46,7 +46,7 @@
   become: true
   template:
     src: v2/queue-worker.service.j2
-    dest: /usr/lib/systemd/system/{{ inventory_hostname }}-{{ action }}-worker.service
+    dest: /usr/lib/systemd/system/{{ action }}.worker.{{ app_domain }}.service
     owner: root
     group: root
     mode: "0644"
@@ -57,7 +57,7 @@
   become: true
   template:
     src: v2/queue-worker.service.j2
-    dest: /usr/lib/systemd/system/{{ inventory_hostname }}-{{ action }}-worker.service
+    dest: /usr/lib/systemd/system/{{ action }}.worker.{{ app_domain }}.service
     owner: root
     group: root
     mode: "0644"

+ 5 - 12
deploy/roles/mint-v2.0/tasks/tulip.yml → deploy/roles/mint-v2.1/tasks/tulip.yml

@@ -5,24 +5,24 @@
       - update
       - --optimize-autoloader
       - --no-dev
-    chdir: "{{ app_deploy_target }}/mint/dashboard-v4/rpc/tulip/tulip"
+    chdir: "{{ app_deploy_target }}/dashboard-v4/rpc/tulip/tulip"
 
 - name: upload tulip db/.env
   template:
     src: v2/tulip/db/env.j2
-    dest: "{{ app_deploy_target }}/mint/dashboard-v4/rpc/tulip/tulip/db/.env"
+    dest: "{{ app_deploy_target }}/dashboard-v4/rpc/tulip/tulip/db/.env"
     mode: "0644"
 
 - name: upload tulip config.php
   template:
     src: v2/tulip/config.php.j2
-    dest: "{{ app_deploy_target }}/mint/dashboard-v4/rpc/tulip/tulip/config.php"
+    dest: "{{ app_deploy_target }}/dashboard-v4/rpc/tulip/tulip/config.php"
     mode: "0644"
 
 - name: Setup tmp folder
   become: true
   ansible.builtin.file:
-    path: "{{ app_deploy_root }}/mint/dashboard-v4/rpc/tulip/tulip/tmp"
+    path: "{{ app_deploy_root }}/dashboard-v4/rpc/tulip/tulip/tmp"
     state: directory
     owner: "www-data"
     group: "www-data"
@@ -31,14 +31,7 @@
   become: true
   template:
     src: v2/tulip/service.conf.j2
-    dest: /usr/lib/systemd/system/{{ inventory_hostname }}-tulip.service
+    dest: /usr/lib/systemd/system/tulip.{{ app_domain }}.service
     owner: root
     group: root
     mode: "0644"
-
-- name: Run tulip db migrate
-  ansible.builtin.command:
-    argv:
-      - /usr/bin/dbmate
-      - up
-    chdir: "{{ app_deploy_target }}/mint/dashboard-v4/rpc/tulip/tulip/db"

+ 2 - 2
deploy/roles/mint-v2.1/templates/v1/config.php.j2

@@ -5,7 +5,7 @@ define("GRPC_WEB_SERVER","{{ app_grpc_web_server}}");
 define("ASSETS_SERVER","{{ app_assets_server }}");
 define("DOCUMENTS_SERVER","{{ app_documents_server }}");
 define('APP_KEY','{{ app_secret_key }}');
-define('APP_ENV','{{ app_deploy_env }}');
+define('APP_ENV','{{ app_env }}');
 define('CORS_ALLOWED_ORIGINS', '{{ app_cors_allowed_origins }}');
 define('DASHBOARD_BASE_PATH', "{{ app_dashboard_base_path }}");
 
@@ -44,7 +44,7 @@ define("Redis",[
         "host" => "{{ app_redis_host }}",
         "port" => {{ app_redis_port }},
         "password" => "",
-        "prefix"=>"{{ app_deploy_env }}://www"
+        "prefix"=>"{{ app_domain }}://v1/"
 ]);
 
 

+ 5 - 5
deploy/roles/mint-v2.1/templates/v2/env.j2

@@ -1,12 +1,12 @@
-BASE_DIR="{{ app_deploy_target }}/mint/.env.global"
+BASE_DIR="{{ app_deploy_target }}/.env.global"
 CACHE_DIR="${BASE_DIR}/cache"
 TMP_DIR="${BASE_DIR}/tmp"
 
 APP_NAME="wikipali"
-APP_ENV={{ app_deploy_env }}
+APP_ENV={{ app_env }}
 APP_KEY={{ app_secret_key }}
 APP_DEBUG=false
-APP_URL="https://{{ inventory_hostname }}"
+APP_URL="https://{{ app_domain }}"
 
 LOG_CHANNEL=syslog
 LOG_DEPRECATIONS_CHANNEL=null
@@ -37,13 +37,13 @@ REDIS_HOST={{ app_redis_host }}
 REDIS_PORT={{ app_redis_port }}
 REDIS_PASSWORD=
 REDIS_DB=0
-REDIS_PREFIX="${APP_NAME}://{{ inventory_hostname }}/"
+REDIS_PREFIX="${app_domain}://v2/"
 
 REDIS_CACHE_HOST={{ app_redis_cache_host }}
 REDIS_CACHE_PORT={{ app_redis_cache_port }}
 REDIS_CACHE_PASSWORD=
 REDIS_CACHE_DB={{ app_redis_cache_db }}
-REDIS_CACHE_PREFIX="{{ inventory_hostname }}://"
+REDIS_CACHE_PREFIX="{{ app_domain }}://v2/"
 
 
 MAIL_MAILER=smtp

+ 2 - 2
deploy/roles/mint-v2.1/templates/v2/lily/services/server.service.j2

@@ -1,11 +1,11 @@
 [Unit]
-Description=Mint lily rpc service for {{ inventory_hostname }}
+Description=Mint lily rpc service for {{ app_domain }}
 After=network.target
 
 [Service]
 Type=simple
 ExecStart=/bin/bash lily.sh -d -c config.toml
-WorkingDirectory={{ app_deploy_target }}/mint/dashboard-v4/rpc/lily
+WorkingDirectory={{ app_deploy_target }}/dashboard-v4/rpc/lily
 User=www-data
 Group=www-data
 Restart=always

+ 2 - 2
deploy/roles/mint-v2.1/templates/v2/lily/services/worker.service.j2

@@ -1,11 +1,11 @@
 [Unit]
-Description=Mint lily worker service for {{ inventory_hostname }}
+Description=Mint lily worker service for {{ app_domain }}
 After=network.target
 
 [Service]
 Type=simple
 ExecStart=/bin/bash lily.sh -d -c config.toml --worker {{ queue }}
-WorkingDirectory={{ app_deploy_target }}/mint/dashboard-v4/rpc/lily
+WorkingDirectory={{ app_deploy_target }}/dashboard-v4/rpc/lily
 User=www-data
 Group=www-data
 Restart=always

+ 2 - 2
deploy/roles/mint-v2.1/templates/v2/morus.service.j2

@@ -1,11 +1,11 @@
 [Unit]
-Description=Mint morus rpc service for {{ inventory_hostname }}
+Description=Mint morus rpc service for {{ app_domain }}
 After=network.target
 
 [Service]
 Type=simple
 ExecStart=/usr/bin/php server.php -p {{ app_morus_listen_port }}
-WorkingDirectory={{ app_deploy_target }}/mint/dashboard-v4/rpc/morus/morus
+WorkingDirectory={{ app_deploy_target }}/dashboard-v4/rpc/morus/morus
 User=www-data
 Group=www-data
 Restart=always

+ 2 - 2
deploy/roles/mint-v2.1/templates/v2/queue-worker.service.j2

@@ -1,11 +1,11 @@
 [Unit]
-Description=Mint {{ action }} worker for {{ inventory_hostname }}
+Description=Mint {{ action }} worker for {{ app_domain }}
 After=network.target
 
 [Service]
 Type=simple
 ExecStart=/usr/bin/php artisan mq:{{ action }}
-WorkingDirectory={{ app_deploy_target }}/mint
+WorkingDirectory={{ app_deploy_target }}
 User=www-data
 Group=www-data
 Restart=always

+ 2 - 2
deploy/roles/mint-v2.1/templates/v2/scheduler.service.j2

@@ -1,9 +1,9 @@
 [Unit]
-Description=Mint scheduler for {{ inventory_hostname }}
+Description=Mint scheduler for {{ app_domain }}
 
 [Service]
 Type=simple
 ExecStart=/usr/bin/php artisan schedule:run
-WorkingDirectory={{ app_deploy_target }}/mint
+WorkingDirectory={{ app_deploy_target }}
 User=www-data
 Group=www-data

+ 2 - 2
deploy/roles/mint-v2.1/templates/v2/scheduler.timer.j2

@@ -1,10 +1,10 @@
 [Unit]
-Description=Runs Mint {{ inventory_hostname }} scheduler every minute
+Description=Runs Mint {{ app_domain }} scheduler every minute
 
 [Timer]
 OnBootSec=15minutes
 OnUnitActiveSec=1minute
-Unit={{ inventory_hostname }}-scheduler.service
+Unit=scheduler.{{ app_domain }}.service
 
 [Install]
 WantedBy=timers.target

+ 2 - 2
deploy/roles/mint-v2.1/templates/v2/tulip/service.conf.j2

@@ -1,11 +1,11 @@
 [Unit]
-Description=Mint tulip rpc service for {{ inventory_hostname }}
+Description=Mint tulip rpc service for {{ app_domain }}
 After=network.target
 
 [Service]
 Type=simple
 ExecStart=/usr/bin/php server.php
-WorkingDirectory={{ app_deploy_target }}/mint/dashboard-v4/rpc/tulip/tulip
+WorkingDirectory={{ app_deploy_target }}/dashboard-v4/rpc/tulip/tulip
 User=www-data
 Group=www-data
 Restart=always