Contents

Ubuntu监控目录

注意

  • 业务是监控目录,生成nginx配置

  • 主机需要安装 inotify-tools ,nginx

1
sudo apt-get install inotify-tools nginx -y
  • 将docker项目保存nginx配置的目录挂载到主机,主机目录需要777权限

相关文件,根目录为 root

  • build-web.sh
1
2
3
4
5
6
7
8
9
#!/bin/bash

dir=$1

dir2=$2

sleep 1
cp "$dir/$dir2/default.conf" "/etc/nginx/sites-enabled/$dir2-my-laravel-project.com"
service nginx restart
  • web-dir-monitor.sh
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
#!/bin/sh

# 监视的文件或目录
filename=$1

# 监视发现有增、删、改时执行的脚本
script=$2

inotifywait -mq --format '%f' -e create  $filename | while read line
  do
      bash $script $filename $line
  done
  • nginx配置示例
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
server {
  listen 10001;
  # server_name  ~^(?<subdomain>.+)\.test_domain\.com$;
  # root   "/$subdomain";
  root   "/home/laravel-project/storage/app/websites/1";
  index index.html index.htm;
  location / {
    try_files $uri $uri/ =404;
  }
}
  • 执行命令
1
bash web-dir-monitor.sh /home/laravel-project/storage/app/websites build-web.sh
  • 当然也可以和supervisor一起食用
coffee