| return | return | ||||
| } | } | ||||
| if forceHttpDownload(r) { | |||||
| w.Header().Set("Content-Disposition", "attachment; filename="+ul.Upload.FileName) | |||||
| } | |||||
| //check local file first | //check local file first | ||||
| path := ul.filePath() | path := ul.filePath() | ||||
| if fileExists(path) { | if fileExists(path) { |
| { | |||||
| "Host":"0.0.0.0", | |||||
| "Port":"8080", | |||||
| "DSN": "sp:sp@/syd_credit?parseTime=true&loc=Australia%2FSydney", | |||||
| "TlsCert": "/home/c5016/ssl.combined", | |||||
| "TlsKey": "/home/c5016/ssl.key", | |||||
| "Debug": false, | |||||
| "UploadsDir": { | |||||
| "FileDir": "/var/sfmapi/uploads/file", | |||||
| "FileDefault": "./assets/no_preview.jpg", | |||||
| "JpgDir": "/var/sfmapi/uploads/jpg", | |||||
| "JpgDefault": "./assets/no_preview.jpg", | |||||
| "ThumbDir": "/var/sfmapi/uploads/thumb", | |||||
| "ThumbDefault": "./assets/thumb_file_icon.webp", | |||||
| "PdfDir": "/var/sfmapi/uploads/pdf", | |||||
| "PdfDefault": "./assets/no_preview.pdf" | |||||
| }, | |||||
| "TempDir": "/var/sfmapi/tmp/", | |||||
| "Static": [ | |||||
| { | |||||
| "Dir": "./html/", | |||||
| "StaticUrl": "/", | |||||
| "StripPrefix" : "/" | |||||
| }, | |||||
| { | |||||
| "Dir": "./html/test/", | |||||
| "StaticUrl": "/spa1/", | |||||
| "StripPrefix" : "/spa1/" | |||||
| }, | |||||
| { | |||||
| "Dir": "./html/test/", | |||||
| "StaticUrl": "/spa2/", | |||||
| "StripPrefix" : "/spa2/" | |||||
| } | |||||
| ], | |||||
| "Session" : { | |||||
| "Guest": true, | |||||
| "Year": 10, | |||||
| "Month": 1, | |||||
| "Day": 1 | |||||
| } | |||||
| } |
| #!/bin/bash | |||||
| chmod +x /usr/local/lib/sfmapi/local_update.sh | |||||
| ls -l /usr/local/lib/sfmapi/local_update.sh | |||||
| echo "for pdf to text poppler-utils" | |||||
| apt install poppler-utils | |||||
| echo "for converting xls libreoffice" | |||||
| apt install libreoffice | |||||
| echo "for tree structure" | |||||
| apt install tree | |||||
| echo "ensure service is available" | |||||
| rm -f /etc/systemd/system/sfmapi.service | |||||
| ln -s /usr/local/lib/sfmapi/sfmapi.service /etc/systemd/system/sfmapi.service | |||||
| ls -l /etc/systemd/system/sfmapi.service | |||||
| echo "reload systemd deamon" | |||||
| systemctl daemon-reload | |||||
| echo "enable sfmapi service" | |||||
| systemctl enable sfmapi | |||||
| echo "make dir /var/sfmapi/tmp/dist/" | |||||
| mkdir -p /var/sfmapi/tmp/dist | |||||
| #!/bin/bash | |||||
| cd /home/sp/go/src/SFM_Loan_RestApi/ | |||||
| go build | |||||
| rm -rf /tmp/sfm_loan_rest_api_dist | |||||
| mkdir -p /tmp/sfm_loan_rest_api_dist/local-lib | |||||
| mkdir -p /tmp/sfm_loan_rest_api_dist/var-sfmapi | |||||
| mkdir -p /tmp/sfm_loan_rest_api_dist/var-sfmapi/log | |||||
| mkdir -p /tmp/sfm_loan_rest_api_dist/var-sfmapi/tmp | |||||
| # for /usr/local/lib/sfmapi | |||||
| cp apiv1 /tmp/sfm_loan_rest_api_dist/local-lib/ | |||||
| cp deploy/config.prod.json /tmp/sfm_loan_rest_api_dist/local-lib/config.json | |||||
| cp -a html /tmp/sfm_loan_rest_api_dist/local-lib/ | |||||
| cp -a assets /tmp/sfm_loan_rest_api_dist/local-lib/ | |||||
| # for /var/sfmapi | |||||
| cp -a uploads /tmp/sfm_loan_rest_api_dist/var-sfmapi/ | |||||
| cp -a tmp /tmp/sfm_loan_rest_api_dist/var-sfmapi/ | |||||
| # make sure remote service are all available | |||||
| ssh root@c5016.biukop.com.au 'mkdir -p /usr/local/lib/sfmapi/ && mkdir -p /var/sfmapi/tmp/dist' | |||||
| scp deploy/dependency.sh root@c5016.biukop.com.au:/usr/local/lib/sfmapi/ | |||||
| scp deploy/local_update.sh root@c5016.biukop.com.au:/usr/local/lib/sfmapi/ | |||||
| scp deploy/sfmapi.service root@c5016.biukop.com.au:/usr/local/lib/sfmapi/sfmapi.service | |||||
| ssh root@c5016.biukop.com.au 'chmod +x /usr/local/lib/sfmapi/dependency.sh && /usr/local/lib/sfmapi/dependency.sh' | |||||
| #dump mysql database | |||||
| echo "dump datebase with stored procedures" | |||||
| mysqldump -u root -psp --routines syd_credit > /tmp/sfm_loan_rest_api_dist/syd_credit.sql | |||||
| gzip -f /tmp/sfm_loan_rest_api_dist/syd_credit.sql | |||||
| echo "copy it to remote server" | |||||
| scp /tmp/sfm_loan_rest_api_dist/syd_credit.sql.gz root@c5016.biukop.com.au:/var/sfmapi/tmp/dist/ | |||||
| echo "sync files to remote server" | |||||
| rsync -avh /tmp/sfm_loan_rest_api_dist/ root@c5016.biukop.com.au:/var/sfmapi/tmp/dist/ | |||||
| # remote update | |||||
| ssh root@c5016.biukop.com.au '/usr/local/lib/sfmapi/local_update.sh' |
| #!/bin/bash | |||||
| # stop server | |||||
| echo "stopping remote server ..." | |||||
| service sfmapi stop | |||||
| # restore database | |||||
| gunzip -f /var/sfmapi/tmp/dist/syd_credit.sql.gz | |||||
| mysql -usp -psp syd_credit < /var/sfmapi/tmp/dist/syd_credit.sql | |||||
| # update api program | |||||
| rsync -avh /var/sfmapi/tmp/dist/local-lib/ /usr/local/lib/sfmapi/ | |||||
| rm -f /usr/local/lib/sfmapi/sfm | |||||
| mv /usr/local/lib/sfmapi/apiv1 /usr/local/lib/sfmapi/sfm | |||||
| chmod +x /usr/local/lib/sfmapi/sfm | |||||
| # sync uploads on disk | |||||
| mkdir -p /var/sfmapi/uploads/ | |||||
| mkdir -p /var/sfmapi/log/ | |||||
| rsync -avh /var/sfmapi/tmp/dist/var-sfmapi/uploads/ /var/sfmapi/uploads/ | |||||
| # start server | |||||
| echo "starting remote server ..." | |||||
| service sfmapi start | |||||
| echo "wait for remote server to startup" | |||||
| sleep 2 | |||||
| echo "check remote server status" | |||||
| service sfmapi status | |||||
| ls -l /usr/local/lib/sfmapi/ | |||||
| ls -l /var/sfmapi | |||||
| tree /usr/local/lib/sfmapi/ | |||||
| tree /var/sfmapi |
| [Unit] | |||||
| Description=SFM API | |||||
| After=network.target | |||||
| [Service] | |||||
| Type=simple | |||||
| ExecStart=/usr/local/lib/sfmapi/sfm | |||||
| Restart=on-failure | |||||
| PIDFile=/run/sfmapi.pid | |||||
| WorkingDirectory=/usr/local/lib/sfmapi/ | |||||
| KillMode=process | |||||
| [Install] | |||||
| WantedBy=multi-user.target |