diff --git a/README.md b/README.md index 2d70f5a4bd4dc0e2165350ebcec17692f01f015a..943850c03284d0e56a8db25a4b55587aa5aaa3a0 100644 --- a/README.md +++ b/README.md @@ -21,12 +21,13 @@ vagrant up ``` Wait for the provisioning to finish (~5mins), and go to your browser: https://indiehosters.dev +If the process fails, for instance due to network problems, you can retry by running `vagrant provision`. ### If you want to add another nginx instance apart from indiehosters.dev: ```bash vagrant ssh -sh /data/indiehosters/scripts/activate-user.sh example.dev nginx +sudo sh /data/indiehosters/scripts/activate-user.sh example.dev nginx https://github.com/indiehosters/website-static.git ``` Check https://example.dev in your bowser! diff --git a/importers/nginx-updater.sh b/importers/nginx-updater.sh new file mode 100755 index 0000000000000000000000000000000000000000..034a40230396eca6cbdc19d9194c219b7a5603b8 --- /dev/null +++ b/importers/nginx-updater.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +cd /data/per-user/$USER/nginx/data/www-content && git pull diff --git a/importers/nginx.sh b/importers/nginx.sh index ac46b0e74c762d1f29c5610e440aebd556e0c3a7..06c79537f2c8d378e9f5448ec35481b1086e6cba 100755 --- a/importers/nginx.sh +++ b/importers/nginx.sh @@ -1,6 +1,10 @@ #!/bin/bash -if [ ! -d "/data/per-user/$USER/nginx/data" ]; then - mkdir -p /data/per-user/$USER/nginx/data/www-content - echo Hello $USER > /data/per-user/$USER/nginx/data/www-content/index.html +if [ ! -e "/data/per-user/$USER/nginx/data/www-content/index.html" ]; then + if [ -e "/data/per-user/$USER/nginx/data/git-url.txt" ]; then + git clone `cat /data/per-user/$USER/nginx/data/git-url.txt` /data/per-user/$USER/nginx/data/www-content + else + mkdir -p /data/per-user/$USER/nginx/data/www-content + echo Hello $USER > /data/per-user/$USER/nginx/data/www-content/index.html + fi fi diff --git a/scripts/activate-user.sh b/scripts/activate-user.sh index 4ee58a206652db0835f23cead450de339c6ca39b..87a99d8c378520fbf88229397d53f8d1270e31b3 100755 --- a/scripts/activate-user.sh +++ b/scripts/activate-user.sh @@ -1,12 +1,18 @@ #!/bin/bash -eux -# mkdir -p /data/per-user/$1/nginx/data -# if [ -e /data/per-user/$1/nginx/data/www-content ]; then -# cd /data/per-user/$1/nginx/data/www-content; git pull --rebase -# else -# git clone $3 /data/per-user/$1/nginx/data/www-content -# fi +if [ $# -ge 2 ]; then + DOMAIN=$1 + IMAGE=$2 +else + echo "Usage: sh /data/indiehosters/scripts/activate-user domain image [gitrepo]" + exit 1 +fi +mkdir -p /data/per-user/$DOMAIN/nginx/data +if [ $# -ge 3 ]; then + GITREPO=$3 + echo $GITREPO > /data/per-user/$DOMAIN/nginx/data/git-url.txt +fi -# Start service for new site (and create the user) -systemctl enable $2@$1.service -systemctl start $2@$1.service +# Start service for new site (and create the user). This will also enable the git puller. +systemctl enable $IMAGE@$DOMAIN.service +systemctl start $IMAGE@$DOMAIN.service diff --git a/unit-files/nginx-gitpuller@.path b/unit-files/nginx-gitpuller@.path new file mode 100644 index 0000000000000000000000000000000000000000..564b2bc13b1e4c1c77fb7d373d86b24071e7f227 --- /dev/null +++ b/unit-files/nginx-gitpuller@.path @@ -0,0 +1,2 @@ +[Path] +PathExists=/data/per-user/%i/nginx/data/git-url.txt diff --git a/unit-files/nginx-gitpuller@.service b/unit-files/nginx-gitpuller@.service new file mode 100644 index 0000000000000000000000000000000000000000..a05ab8384717b9c78357487ae9e3b18a0ca4b894 --- /dev/null +++ b/unit-files/nginx-gitpuller@.service @@ -0,0 +1,12 @@ +[Unit] +Description=nginx git puller + +# Dependency ordering +Before=nginx@%i.service + +[Service] +Environment=USER=%i +ExecStart=/data/indiehosters/importers/nginx-updater.sh + +[Install] +WantedBy=nginx@%i.service diff --git a/unit-files/nginx-gitpuller@.timer b/unit-files/nginx-gitpuller@.timer new file mode 100644 index 0000000000000000000000000000000000000000..78faa1e6b7c53e4b35d8a39962efd22cb93273eb --- /dev/null +++ b/unit-files/nginx-gitpuller@.timer @@ -0,0 +1,8 @@ +[Unit] +Description=Run git puller every 10 minutes + +[Timer] +OnUnitActiveSec=10min + +[Install] +WantedBy=timers.target