Fix to safely kill only targeted scripts

This commit is contained in:
Ilia Ross
2025-10-04 00:45:21 +03:00
parent 7a651027bf
commit face8319f2
2 changed files with 16 additions and 4 deletions

View File

@@ -695,11 +695,17 @@ echo " echo Force stopping Webmin server in $wadir" >>$config_dir/.stop-init
echo "else" >>$config_dir/.stop-init
echo " echo Stopping Webmin server in $wadir" >>$config_dir/.stop-init
echo "fi" >>$config_dir/.stop-init
echo "pids=\`ps axww -o pid= -o command= | awk -v wd=\"$wadir/\" '\$0 ~ wd && \$0 !~ /miniserv\\.pl/ {print \$1}'\`" >>$config_dir/.stop-init
echo "targets=\"stats.pl shellserver.pl\"" >>$config_dir/.stop-init
echo "collect_pids() {" >>$config_dir/.stop-init
echo " for s in \$targets; do" >>$config_dir/.stop-init
echo " ps axww | grep \"$wadir/\" | grep \"/\$s\" | grep -v grep" >>$config_dir/.stop-init
echo " done | awk '{print \$1}' | sort -u" >>$config_dir/.stop-init
echo "}" >>$config_dir/.stop-init
echo "pids=\$(collect_pids)" >>$config_dir/.stop-init
echo "[ -n \"\$pids\" ] && kill \$pids 2>/dev/null || true" >>$config_dir/.stop-init
echo "if [ \"\$1\" = \"--kill\" ]; then" >>$config_dir/.stop-init
echo " sleep 1" >>$config_dir/.stop-init
echo " pids=\`ps axww -o pid= -o command= | awk -v wd=\"$wadir/\" '\$0 ~ wd && \$0 !~ /miniserv\\.pl/ {print \$1}'\`" >>$config_dir/.stop-init
echo " pids=\$(collect_pids)" >>$config_dir/.stop-init
echo " [ -n \"\$pids\" ] && kill -KILL \$pids 2>/dev/null || true" >>$config_dir/.stop-init
echo "fi" >>$config_dir/.stop-init
echo "pidfile=\`grep \"^pidfile=\" $config_dir/miniserv.conf | sed -e 's/pidfile=//g'\`" >>$config_dir/.stop-init