Ver Fonte

:wrench: add auto restart support

Jeremy Zheng há 1 ano atrás
pai
commit
02edb0c57c

+ 6 - 0
deploy/mint.yml

@@ -55,3 +55,9 @@
     - web
   roles:
     - mint-nginx
+
+- name: Setup single-node worker
+  hosts:
+    - fort
+  roles:
+    - mint-fort

+ 9 - 9
deploy/roles/mint-fort/tasks/main.yml

@@ -1,7 +1,7 @@
 - name: Upload script for schedule-run
-  ansible.builtin.copy:
-    src: schedule-run.sh
-    dest: "{{ app_deploy_target }}/scripts/worker-{{ zone_name }}-{{ worker_name }}.sh"
+  ansible.builtin.template:
+    src: schedule-run.sh.j2
+    dest: "{{ app_deploy_target }}/scripts/worker-schedule-run.sh"
     mode: "0555"
 
 - name: Stop schedule-run
@@ -18,10 +18,10 @@
       - "{{ app_deploy_target }}:{{ app_deploy_target }}:z"
     workdir: "{{ app_deploy_target }}"
     # auto_remove: true
-    generate_systemd:
-      path: "{{ app_deploy_target | dirname }}/systemd"
-      container_prefix: mint
-      names: true
-      restart_policy: always
-      stop_timeout: 120
+    # generate_systemd:
+    #   path: "{{ app_deploy_target | dirname }}/systemd"
+    #   container_prefix: mint
+    #   names: true
+    #   restart_policy: always
+    #   stop_timeout: 120
 # TODO timer

+ 5 - 1
deploy/roles/mint-fort/templates/schedule-run.j2 → deploy/roles/mint-fort/templates/schedule-run.sh.j2

@@ -9,4 +9,8 @@ source "$NVM_DIR/nvm.sh"
 
 cd $WORK_DIR/api-v8/
 
-php artisan schedule:run
+while true
+do
+    php -d memory_limit={{ app_php_memory_limit }} artisan schedule:run || true
+    sleep 60
+done

+ 2 - 0
deploy/roles/mint-nginx/templates/nginx.conf.j2

@@ -44,6 +44,8 @@ server {
     location ~ \.php$ {
         fastcgi_pass php_fpm_{{ app_php_fpm_port }};
         fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
+        # for nginx v1.18
+        # fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
         include fastcgi_params;
         fastcgi_hide_header X-Powered-By;
     }

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

@@ -1,3 +1,11 @@
+- name: Create www folder
+  become: true
+  ansible.builtin.file:
+    path: "{{ app_deploy_target | dirname }}"
+    state: directory
+    owner: "{{ ansible_user }}"
+    mode: "0755"
+
 - name: Download source code
   ansible.builtin.unarchive:
     src: https://github.com/iapt-platform/mint/archive/{{ mint_version }}.zip

+ 9 - 1
deploy/roles/mint-workers/templates/worker.sh.j2

@@ -9,4 +9,12 @@ source "$NVM_DIR/nvm.sh"
 
 cd $WORK_DIR/api-v8/
 
-php -d memory_limit={{ app_php_memory_limit }} artisan {{ zone_name }}:{{ worker_name }}
+# php -d memory_limit={{ app_php_memory_limit }} artisan {{ zone_name }}:{{ worker_name }}
+
+while true
+do
+    php -d memory_limit={{ app_php_memory_limit }} artisan {{ zone_name }}:{{ worker_name }} || true
+    sleep 10
+done
+
+exit 0