diff options
| author | Jan Tuomi <jan@jantuomi.fi> | 2025-10-06 15:36:41 +0300 |
|---|---|---|
| committer | Jan Tuomi <jan@jantuomi.fi> | 2025-10-06 15:36:41 +0300 |
| commit | 25f62c996b560df12c2a8f1c7506aba28c02b154 (patch) | |
| tree | 43b9f991aab015a3d6affcb47d55ef270ec5d20f /templates | |
| parent | 29eb2e6cc469d9534c2586e98b782f1879bd8c76 (diff) | |
Run diddle
Diffstat (limited to 'templates')
| -rw-r--r-- | templates/diddle/root_clone.sh | 14 | ||||
| -rw-r--r-- | templates/diddle/root_diddle_env.j2 | 9 | ||||
| -rw-r--r-- | templates/diddle/usr_local_bin_diddle | 17 | ||||
| -rw-r--r-- | templates/diddle/usr_local_etc_rc.d_diddle | 43 |
4 files changed, 83 insertions, 0 deletions
diff --git a/templates/diddle/root_clone.sh b/templates/diddle/root_clone.sh new file mode 100644 index 0000000..a3dbdac --- /dev/null +++ b/templates/diddle/root_clone.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +# Exits with 100 if the directory was changed + +if [ ! -f /root/diddle ]; then + git clone https://github.com/jantuomi/diddle.git /root/diddle && exit 100 +fi + +cd /root/diddle +before=$(git rev-parse HEAD) +git fetch && git pull --ff-only --quiet +after=$(git rev-parse HEAD) + +if [ "$before" != "$after" ]; then exit 100; fi diff --git a/templates/diddle/root_diddle_env.j2 b/templates/diddle/root_diddle_env.j2 new file mode 100644 index 0000000..ca7db78 --- /dev/null +++ b/templates/diddle/root_diddle_env.j2 @@ -0,0 +1,9 @@ +PYTHONUNBUFFERED="1" +BASE_URL="https://diddle.jan.systems" +DB_PATH="db.sqlite3" +EMAIL_HOST="smtp.postmarkapp.com" +EMAIL_PORT="587" +EMAIL_HOST_USER="{{ diddle_email_host_user }}" +EMAIL_HOST_PASSWORD="{{ diddle_email_host_password }}" +EMAIL_USE_TLS="true" +EMAIL_MESSAGE_FROM="diddle@jan.systems" diff --git a/templates/diddle/usr_local_bin_diddle b/templates/diddle/usr_local_bin_diddle new file mode 100644 index 0000000..d07cd5e --- /dev/null +++ b/templates/diddle/usr_local_bin_diddle @@ -0,0 +1,17 @@ +#!/bin/sh + +set -eux + +PATH=$PATH:/usr/local/bin + +cd /root/diddle + +if [ ! -f venv ]; then + python3.11 -m venv venv +fi + +PATH=$PATH:/root/diddle/venv/bin + +pip install -r requirements.txt +python apply_migrations.py +gunicorn --bind "0.0.0.0:80" -w 4 app:app diff --git a/templates/diddle/usr_local_etc_rc.d_diddle b/templates/diddle/usr_local_etc_rc.d_diddle new file mode 100644 index 0000000..01deaad --- /dev/null +++ b/templates/diddle/usr_local_etc_rc.d_diddle @@ -0,0 +1,43 @@ +#!/bin/sh +# +# PROVIDE: diddle +# REQUIRE: NETWORKING +# KEYWORD: shutdown +# +# Enable in /etc/rc.conf: +# diddle_enable="YES" +# +. /etc/rc.subr + +name="diddle" +rcvar=diddle_enable + +load_rc_config $name + +: ${diddle_command:=/usr/local/bin/diddle} +: ${diddle_log:=/var/log/${name}.log} + +start_cmd="${name}_start" +stop_cmd="${name}_stop" +status_cmd="${name}_status" + +extra_commands="status" + +diddle_start() { + /usr/local/bin/logto ${diddle_log} ${diddle_command} & +} + +diddle_status() { + if ps aux | grep diddle | grep -v grep | grep -v rc.d/diddle; then + echo "diddle is running" + else + echo "diddle is not running" + exit 1 + fi +} + +diddle_stop() { + ps aux | grep diddle | grep -v grep | grep -v rc.d/diddle | awk '{print $2}' | xargs kill -TERM +} + +run_rc_command "$1" |
