Skip to content

Commit 252fc44

Browse files
committed
Improve ./ynh-dev dev (renamed to api) to run and auto-restart the APIs when code changes
1 parent fbf4b2d commit 252fc44

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

ynh-dev

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ function show_usage() {
2424
test [PKG] Deploy, update and run tests for some packages
2525
Tests for single modules and functions can ran with
2626
e.g. ./ynh-dev test yunohost/appurl:urlavailable
27-
dev Watch python files and restart yunohost-api and yunohost-portal-api when changes occur
27+
api Start yunohost-api and yunohost-portal-api in debug mode in the current terminal, and auto-restart them when code changes
2828
catalog
2929
build Rebuild the custom catalog
3030
add Add the custom catalog in Yunohost catalog list
@@ -53,8 +53,8 @@ function main()
5353

5454
ip|--ip) show_vm_ip "${ARGUMENTS[@]}" ;;
5555
use-git|--use-git) use_git "${ARGUMENTS[@]}" ;;
56-
dev|--dev) dev "${ARGUMENTS[@]}" ;;
57-
lint|--lint) run_linters "${ARGUMENTS[@]}" ;;
56+
api|--api) api "${ARGUMENTS[@]}" ;;
57+
lint|--lint) run_linters "${ARGUMENTS[@]}" ;;
5858
test|--test) run_tests "${ARGUMENTS[@]}" ;;
5959

6060
catalog|--catalog) catalog "${ARGUMENTS[@]}" ;;
@@ -448,23 +448,34 @@ $IP $MAIN_DOMAIN"
448448
done
449449
}
450450

451-
function dev()
451+
function api()
452452
{
453453
assert_inside_vm
454454

455455
command -v inotifywait &>/dev/null || critical "You should first run: apt install inotify-tools"
456456

457-
info "Now monitoring for changes in python files, restarting yunohost-api and yunohost-portal-api when changes occur!"
457+
function kill_and_restart_api()
458+
{
459+
systemctl --quiet is-active yunohost-api && systemctl stop yunohost-api || true
460+
systemctl --quiet is-active yunohost-portal-api && systemctl stop yunohost-portal-api || true
461+
for PID in $(pgrep -f yunohost-api) $(pgrep -f yunohost-portal-api); do kill $PID; done
462+
yunohost-api --debug &
463+
yunohost-portal-api --debug &
464+
}
458465

459-
journalctl --no-pager --no-hostname -u yunohost-api -u yunohost-portal-api -n 0 -f &
460-
JOURNALCTL_PID=$!
466+
info "Now monitoring for changes in python files, restarting yunohost-api and yunohost-portal-api when changes occur!"
461467

462-
trap 'kill $JOURNALCTL_PID; exit' SIGINT
468+
kill_and_restart_api
469+
trap 'for PID in $(pgrep -f yunohost-api) $(pgrep -f yunohost-portal-api); do kill $PID; done; exit' SIGINT
463470

464-
while ! inotifywait -q -e modify /usr/lib/python3/dist-packages/{moulinette,yunohost}/{*.py,*/*.py}
471+
while { inotifywait --quiet -r -e modify /ynh-dev/yunohost/share /ynh-dev/yunohost/locales/ /ynh-dev/yunohost/src /ynh-dev/moulinette/moulinette --exclude "(test_|\.pyc)" || true; }
465472
do
473+
echo ""
474+
echo "=========================="
466475
info "Restarting services"
467-
systemctl restart yunohost-api yunohost-portal-api
476+
echo "=========================="
477+
echo ""
478+
kill_and_restart_api
468479
done
469480

470481
}

0 commit comments

Comments
 (0)