Ubuntu监控目录
409 words
One minute
注意
1
| sudo apt-get install inotify-tools nginx -y
|
- 将docker项目保存nginx配置的目录挂载到主机,主机目录需要777权限
相关文件,根目录为 root
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
|
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
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
| # 包含CLOSE_WRITE字样的事件,表示文件写入已完成,比如ftp上传文件后,完成上传操作,再进行其他操作,可以用到
inotifywait -m /home/vsftpd/dywily/ -e create -e close_write |
while read path action file; do
if [[ "$action" == "CREATE" ]]; then
echo "File '$file' was created."
elif [[ "$action" == *"CLOSE_WRITE"* ]]; then
echo "File '$file' has been written and closed."
fi
done
# 所有事件
inotifywait -m /home/vsftpd/dywily/ -e access -e modify -e attrib -e close_write -e close_nowrite -e open -e moved_from -e moved_to -e create -e delete -e delete_self -e move_self |
while read path action file; do
echo "Event: $action on file: $file in directory: $path"
done
|
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
|