Skip to content

Commit

Permalink
repos
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfiex committed Jan 9, 2024
1 parent 0257846 commit 92f575f
Show file tree
Hide file tree
Showing 40 changed files with 1,826 additions and 7,590 deletions.
Binary file modified .DS_Store
Binary file not shown.
Binary file modified docs/.DS_Store
Binary file not shown.
Binary file not shown.
File renamed without changes.
32 changes: 32 additions & 0 deletions docs/Server_Config/FASTAPI.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# FastAPI (Gunicorn)

--bind 0.0.0.0:8000 essentially tells Gunicorn to listen on all available network interfaces on port 8000. This is a common configuration when you want your Gunicorn server to be accessible from external sources, such as when deploying a web application.

For example, if you deploy a Flask, Django or FastAPI application with Gunicorn using this bind option, your application will be accessible over HTTP at http://your_server_ip:8000.



## Gunicorn YAML Config

```yaml

workers = 3 # number of workers Gunicorn will spawn

bind = '127.0.0.1:8000' # this is where you declare on which address your


# gunicorn app is running.
# Basically where Nginx will forward the request to

pidfile = '/var/run/gunicorn/mysite.pid' # create a simple pid file for gunicorn.

user = 'user' # the user gunicorn will run on

daemon = True # this is only to tell gunicorn to deamonize the server process

errorlog = '/var/log/gunicorn/error-mysite.log' # error log

accesslog = '/var/log/gunicorn/access-mysite.log' # access log

proc_name = 'gunicorn-mysite' # the gunicorn process name
```
File renamed without changes.
123 changes: 123 additions & 0 deletions docs/Server_Config/nginx.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# Nginx

[Nginx](https://nginx.org/) is a powerful and widely-used open-source web server, reverse proxy server, and load balancer. Known for its efficiency and low resource usage, Nginx excels in handling concurrent connections and serving static content, making it a popular choice for high-traffic websites.

## Installation

```bash
sudo apt update
sudo apt install nginx
```


## Configuration

Nginx's main configuration file is typically located at `/etc/nginx/nginx.conf`. Additional configurations for specific sites or applications are placed in the `/etc/nginx/sites-available/` directory.

### Basic Configuration

1. **Start Nginx:**

```bash
sudo systemctl start nginx
```

2. **Enable Nginx to start on boot:**

```bash
sudo systemctl enable nginx
```

#### Server Block (Virtual Host)

To configure a server block for a specific domain or application, create a new configuration file within the `sites-available` directory and create a symbolic link to `sites-enabled`:

```bash
sudo nano /etc/nginx/sites-available/example.com
```

Example configuration:

```nginx
server {
listen 80;
server_name example.com www.example.com;
location / {
root /var/www/html;
index index.html;
}
}
```

Create a symbolic link:

```bash
sudo ln -s /etc/nginx/sites-available/example.com /etc/nginx/sites-enabled/
```

Restart Nginx to apply changes:

```bash
sudo systemctl restart nginx
```

This basic example serves files from `/var/www/html` for the specified domain.

#### More advanced configurations
[Nginx documentation](https://nginx.org/en/docs/).

! tip "Remember to test your configuration before restarting Nginx"

```bash
sudo nginx -t
```


## Restricting files using Nginx.
Lets restrict files in two locations: (`/admin`, `/private`).


1. **Create Password Files:**
Use the `htpasswd` tool to create password files for each location:

```bash
sudo htpasswd -c /etc/nginx/.htpasswd_admin admin_user

sudo htpasswd -c /etc/nginx/.htpasswd_private private_user
```
! warn "You will be prompted to enter and confirm passwords for each user."

2. **Configure Nginx:**
Update your Nginx configuration:

```nginx
server {
listen 80;
server_name example.com;
location /admin {
auth_basic "Admin Area";
auth_basic_user_file /etc/nginx/.htpasswd_admin;
# Your configuration for the admin area goes here
}
location /private {
auth_basic "Private Area";
auth_basic_user_file /etc/nginx/.htpasswd_private;
# Your configuration for the private area goes here
}
...
}
```


3. **Test and Reload Nginx:**
Test the Nginx configuration and reload:

```bash
sudo nginx -t
sudo systemctl reload nginx
```
8 changes: 7 additions & 1 deletion docs/Server Config/ports.md → docs/Server_Config/ports.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ If UFW is not working, we can enable it with:

Syntax to open specific TCP port:

```sudo ufw allow (port)/tcp```
```bash
sudo ufw allow <port>
sudo ufw reload
```




__Example__:

Expand Down
File renamed without changes.
67 changes: 67 additions & 0 deletions docs/scripts/update_repos.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# CRON update github repositories.

We have a number of repositories on our VM that we would wish to keep up to date.

To ensure this is the case we run a timed job (CRON) which checks and updates a list of repositories.

The basic code required to accomplish this can be found:

```bash
#!/bin/bash

# Define the list of repositories
repositories=(
"$HOME/repo1-location"
"$HOME/repos/repo2-location"
...
)

# Specify the branch to check for updates
branch="main"

# Specify the log file with date
log_file="$HOME/.logs/repo_update_$(date +\%Y\%m\%d).log"

# Specify the backup folder
backup_folder="$HOME/backup"

# Create the backup folder if it doesn't exist
mkdir -p "$backup_folder"

# Loop through each repository and update if changes are found
for repo in "${repositories[@]}"; do
echo "------------------------------"
echo "Checking for updates in $repo"

# Navigate to the repository
cd "$repo" || exit 1

# Fetch remote changes
git fetch origin "$branch"

# Check if there are any changes on the specified branch
if [[ $(git rev-list HEAD..origin/"$branch" --count) -gt 0 ]]; then
echo "Updating $repo"

# Create a backup with date timestamp
backup_file="$backup_folder/$(basename "$repo")_backup_$(date +\%Y\%m\%d_\%H\%M\%S).tar.gz"
tar -czf "$backup_file" . >> "$log_file" 2>&1

# Pull changes and force overwrite conflicts
git pull origin "$branch" --force >> "$log_file" 2>&1

# Log the status of the update with the date
echo "$(date): Update status for $repo: Success" >> "$log_file"
echo "$(date): Repository backed up to $backup_file" >> "$log_file"
else
echo "No updates found in $repo"

# Log the status of the update with the date
echo "$(date): Update status for $repo: No updates found" >> "$log_file"
fi

# Return to the script's directory
cd - || exit 1
done

```
Binary file removed docs/untitled folder/.DS_Store
Binary file not shown.
86 changes: 0 additions & 86 deletions docs/untitled folder/99_Acknowlegements.md

This file was deleted.

28 changes: 0 additions & 28 deletions docs/untitled folder/CMIP6Plus/index.md

This file was deleted.

13 changes: 0 additions & 13 deletions docs/untitled folder/MIP_Tables/index.md

This file was deleted.

Binary file removed docs/untitled folder/Submit_Data/.DS_Store
Binary file not shown.
19 changes: 0 additions & 19 deletions docs/untitled folder/Submit_Data/01_Background.md

This file was deleted.

Loading

0 comments on commit 92f575f

Please sign in to comment.