From 1089bc8fb5dc9083e4b84d0175306e9b58235b3d Mon Sep 17 00:00:00 2001 From: Ilia Date: Tue, 19 Apr 2022 17:04:02 +0300 Subject: [PATCH 01/52] Fix STDOUT prints --- makerpm.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/makerpm.pl b/makerpm.pl index 4234e4bb8..a60c7ee9a 100755 --- a/makerpm.pl +++ b/makerpm.pl @@ -258,8 +258,8 @@ chmod 600 \$tempdir/webmin-setup.out rm -f /var/lock/subsys/webmin which systemctl >/dev/null 2>&1 && systemctl daemon-reload if [ "\$inetd" != "1" -a "\$startafter" = "1" ]; then - /etc/init.d/webmin stop - /etc/init.d/webmin start + /etc/init.d/webmin stop >/dev/null 2>&1 /dev/null 2>&1 /etc/webmin/uninstall.sh < Date: Tue, 19 Apr 2022 18:16:24 +0300 Subject: [PATCH 02/52] Avoid printing to STDOUT, print to `webmin-setup.out` when necessary --- makedebian.pl | 17 ++++++++--------- makerpm.pl | 17 ++++++----------- setup.sh | 1 + 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/makedebian.pl b/makedebian.pl index 278b317ac..6f7438829 100755 --- a/makedebian.pl +++ b/makedebian.pl @@ -351,8 +351,8 @@ read answer printf "\\n" if [ "\\\$answer" = "y" ]; then echo "Removing $ucproduct package .." - dpkg --remove $product - echo "Done!" + dpkg --remove --force-depends $product + echo ".. done" fi EOFF chmod +x /etc/$baseproduct/uninstall.sh @@ -366,15 +366,15 @@ if [ "\$?" = "0" ]; then fi fi if [ "\$sslmode" = "1" ]; then - echo "$ucproduct install complete. You can now login to https://\$host:\$port/" + echo "$ucproduct install complete. You can now login to https://\$host:\$port/" >>\$tempdir/$product-setup.out 2>&1 else - echo "$ucproduct install complete. You can now login to http://\$host:\$port/" + echo "$ucproduct install complete. You can now login to http://\$host:\$port/" >>\$tempdir/$product-setup.out 2>&1 fi if [ "$product" = "webmin" ]; then - echo "as root with your root password, or as any user who can use sudo" - echo "to run commands as root." + echo "as root with your root password, or as any user who can use sudo" >>\$tempdir/$product-setup.out 2>&1 + echo "to run commands as root." >>\$tempdir/$product-setup.out 2>&1 else - echo "as any user on the system." + echo "as any user on the system." >>\$tempdir/$product-setup.out 2>&1 fi EOF close(SCRIPT); @@ -390,8 +390,7 @@ if [ "\$1" != "upgrade" -a "\$1" != "abort-upgrade" ]; then # Package is being removed, and no new version of webmin # has taken it's place. Run uninstalls and stop the server if [ "$product" = "webmin" ]; then - echo "Running uninstall scripts .." - (cd /usr/share/$baseproduct ; WEBMIN_CONFIG=/etc/$baseproduct WEBMIN_VAR=/var/$baseproduct LANG= /usr/share/$baseproduct/run-uninstalls.pl) + (cd /usr/share/$baseproduct ; WEBMIN_CONFIG=/etc/$baseproduct WEBMIN_VAR=/var/$baseproduct LANG= /usr/share/$baseproduct/run-uninstalls.pl) >/dev/null 2>&1 /dev/null 2>&1 /etc/webmin/stop 2>/dev/null <<'EOD' #!/bin/sh -echo Stopping Webmin server in /usr/libexec/webmin pidfile=`grep "^pidfile=" /etc/webmin/miniserv.conf | sed -e 's/pidfile=//g'` pid=`cat \$pidfile` if [ "\$pid" != "" ]; then @@ -267,9 +265,9 @@ printf "Are you sure you want to uninstall Webmin? (y/n) : " read answer printf "\\n" if [ "\\\$answer" = "y" ]; then - echo "Removing webmin RPM .." + echo "Removing Webmin RPM package.." rpm -e --nodeps webmin - echo "Done!" + echo ".. done" fi EOFF chmod +x /etc/webmin/uninstall.sh @@ -288,11 +286,11 @@ if [ "$musthost" != "" ]; then fi if [ "\$1" == 1 ]; then if [ "\$sslmode" = "1" ]; then - echo "Webmin install complete. You can now login to https://\$host:\$port/" + echo "Webmin install complete. You can now login to https://\$host:\$port/" >>\$tempdir/webmin-setup.out 2>&1 else - echo "Webmin install complete. You can now login to http://\$host:\$port/" + echo "Webmin install complete. You can now login to http://\$host:\$port/" >>\$tempdir/webmin-setup.out 2>&1 fi - echo "as root with your root password." + echo "as root with your root password." >>\$tempdir/webmin-setup.out 2>&1 fi /bin/true @@ -302,8 +300,7 @@ if [ "\$1" = 0 ]; then if [ "\$?" = 0 ]; then # RPM is being removed, and no new version of webmin # has taken it's place. Run uninstalls and stop the server - echo "Running uninstall scripts .." - (cd /usr/libexec/webmin ; WEBMIN_CONFIG=/etc/webmin WEBMIN_VAR=/var/webmin LANG= /usr/libexec/webmin/run-uninstalls.pl) + (cd /usr/libexec/webmin ; WEBMIN_CONFIG=/etc/webmin WEBMIN_VAR=/var/webmin LANG= /usr/libexec/webmin/run-uninstalls.pl) >/dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 Date: Tue, 19 Apr 2022 19:48:21 +0300 Subject: [PATCH 03/52] Remove obsolete code --- makedist.pl | 5 ----- 1 file changed, 5 deletions(-) diff --git a/makedist.pl b/makedist.pl index 0b3774e32..b5f9de081 100755 --- a/makedist.pl +++ b/makedist.pl @@ -106,11 +106,6 @@ if (!$release || !-d "$tardir/$dir") { system("rm -rf $tardir/$dir/file/plugin.jar"); system("rm -rf $tardir/$dir/authentic-theme/update"); - # Clear out minified JS - if (-d "$tardir/$dir/authentic-theme/extensions") { - system("cat /dev/null >$tardir/$dir/authentic-theme/extensions/csf.min.js"); - } - # Remove theme settings files if (-d "$tardir/$dir/authentic-theme") { system("find $tardir/$dir/authentic-theme -name 'settings_*.js' | xargs rm"); From 0c892589c9912d003a799b60d99c3d0ebbb08192 Mon Sep 17 00:00:00 2001 From: Ilia Date: Tue, 19 Apr 2022 20:20:09 +0300 Subject: [PATCH 04/52] Fix `force-reload` command --- webmin-init | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/webmin-init b/webmin-init index cdb64699e..4669b7d54 100755 --- a/webmin-init +++ b/webmin-init @@ -69,7 +69,11 @@ restart) $STOP ; $START RETVAL=$? ;; -reload|force-reload) +force-reload) + $STOP --kill ; $START + RETVAL=$? + ;; +reload) $RELOAD RETVAL=$? ;; From 02e523b402146a39391d350ecb4e3fab271ff937 Mon Sep 17 00:00:00 2001 From: Ilia Date: Wed, 20 Apr 2022 03:40:07 +0300 Subject: [PATCH 05/52] Fix to use native commands on `systemd` systems --- makedebian.pl | 9 ++-- makerpm.pl | 26 +++++++---- setup.sh | 124 ++++++++++++++++++++++++++++++++++---------------- webmin-init | 118 ++++++++++++++++++++++++++++++++++------------- 4 files changed, 191 insertions(+), 86 deletions(-) diff --git a/makedebian.pl b/makedebian.pl index 6f7438829..d95b25a1f 100755 --- a/makedebian.pl +++ b/makedebian.pl @@ -269,15 +269,10 @@ print SCRIPT </etc/webmin/stop 2>/dev/null <<'EOD' #!/bin/sh -echo Stopping Webmin server in /usr/libexec/webmin pidfile=`grep "^pidfile=" /etc/webmin/miniserv.conf | sed -e 's/pidfile=//g'` pid=`cat \$pidfile` if [ "\$pid" != "" ]; then kill \$pid || exit 1 - if [ "\$1" = "--kill" ]; then - sleep 1 - (kill -9 -- -\$pid || kill -9 \$pid) 2>/dev/null - fi exit 0 else exit 1 @@ -331,7 +326,9 @@ if [ "$product" = "webmin" ]; then fi fi rm -f /var/lock/subsys/$baseproduct -which systemctl >/dev/null 2>&1 && systemctl daemon-reload +if command -v systemctl >/dev/null 2>&1; then + systemctl daemon-reload >/dev/null 2>&1 +fi if [ "$inetd" != "1" ]; then if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then invoke-rc.d $baseproduct stop diff --git a/makerpm.pl b/makerpm.pl index 27aaf8391..451fdf3c0 100755 --- a/makerpm.pl +++ b/makerpm.pl @@ -199,10 +199,6 @@ pidfile=`grep "^pidfile=" /etc/webmin/miniserv.conf | sed -e 's/pidfile=//g'` pid=`cat \$pidfile` if [ "\$pid" != "" ]; then kill \$pid || exit 1 - if [ "\$1" = "--kill" ]; then - sleep 1 - (kill -9 -- -\$pid || kill -9 \$pid) 2>/dev/null - fi exit 0 else exit 1 @@ -254,10 +250,17 @@ export config_dir var_dir perl autoos port login crypt host ssl nochown autothir ./setup.sh >\$tempdir/webmin-setup.out 2>&1 chmod 600 \$tempdir/webmin-setup.out rm -f /var/lock/subsys/webmin -which systemctl >/dev/null 2>&1 && systemctl daemon-reload +if command -v systemctl >/dev/null 2>&1; then + systemctl daemon-reload >/dev/null 2>&1 +fi if [ "\$inetd" != "1" -a "\$startafter" = "1" ]; then - /etc/init.d/webmin stop >/dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1; then + /etc/webmin/stop >/dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /etc/webmin/uninstall.sh </dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1; then + /etc/webmin/stop >/dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 >$config_dir/start -echo "echo Starting Webmin server in $wadir" >>$config_dir/start -echo "trap '' 1" >>$config_dir/start -echo "LANG=" >>$config_dir/start -echo "export LANG" >>$config_dir/start -echo "#PERLIO=:raw" >>$config_dir/start -echo "unset PERLIO" >>$config_dir/start -echo "export PERLIO" >>$config_dir/start -echo "PERLLIB=$PERLLIB" >>$config_dir/start -echo "export PERLLIB" >>$config_dir/start +# Re-generating main +rm -f $config_dir/stop-init $config_dir/start-init $config_dir/restart-init $config_dir/force-reload-init $config_dir/reload-init +echo "Creating start and stop init scripts.." +# Start main +echo "#!/bin/sh" >>$config_dir/start-init +echo "echo Starting Webmin server in $wadir" >>$config_dir/start-init +echo "trap '' 1" >>$config_dir/start-init +echo "LANG=" >>$config_dir/start-init +echo "export LANG" >>$config_dir/start-init +echo "#PERLIO=:raw" >>$config_dir/start-init +echo "unset PERLIO" >>$config_dir/start-init +echo "export PERLIO" >>$config_dir/start-init +echo "PERLLIB=$PERLLIB" >>$config_dir/start-init +echo "export PERLLIB" >>$config_dir/start-init uname -a | grep -i 'HP/*UX' >/dev/null if [ $? = "0" ]; then - echo "exec '$wadir/miniserv.pl' \$* $config_dir/miniserv.conf &" >>$config_dir/start + echo "exec '$wadir/miniserv.pl' \$* $config_dir/miniserv.conf &" >>$config_dir/start-init else - echo "exec '$wadir/miniserv.pl' \$* $config_dir/miniserv.conf" >>$config_dir/start + echo "exec '$wadir/miniserv.pl' \$* $config_dir/miniserv.conf" >>$config_dir/start-init fi +# Stop main +echo "#!/bin/sh" >>$config_dir/stop-init +echo "echo Stopping Webmin server in $wadir" >>$config_dir/stop-init +echo "pidfile=\`grep \"^pidfile=\" $config_dir/miniserv.conf | sed -e 's/pidfile=//g'\`" >>$config_dir/stop-init +echo "pid=\`cat \$pidfile\`" >>$config_dir/stop-init +echo "if [ \"\$pid\" != \"\" ]; then" >>$config_dir/stop-init +echo " kill \$pid || exit 1" >>$config_dir/stop-init +echo " touch $var_dir/stop-flag" >>$config_dir/stop-init +echo " if [ \"\$1\" = \"--kill\" ]; then" >>$config_dir/stop-init +echo " sleep 2" >>$config_dir/stop-init +echo " (kill -9 -- -\$pid || kill -9 \$pid) 2>/dev/null" >>$config_dir/stop-init +echo " fi" >>$config_dir/stop-init +echo " exit 0" >>$config_dir/stop-init +echo "else" >>$config_dir/stop-init +echo " exit 1" >>$config_dir/stop-init +echo "fi" >>$config_dir/stop-init +# Restart main +echo "#!/bin/sh" >>$config_dir/restart-init +echo "$config_dir/stop-init" >>$config_dir/restart-init +echo "$config_dir/start-init" >>$config_dir/restart-init +# Force reload main +echo "#!/bin/sh" >>$config_dir/force-reload-init +echo "$config_dir/stop-init --kill" >>$config_dir/force-reload-init +echo "$config_dir/start-init" >>$config_dir/force-reload-init +# Reload main +echo "#!/bin/sh" >>$config_dir/reload-init +echo "echo Reloading Webmin server in $wadir" >>$config_dir/reload-init +echo "pidfile=\`grep \"^pidfile=\" $config_dir/miniserv.conf | sed -e 's/pidfile=//g'\`" >>$config_dir/reload-init +echo "kill -USR1 \`cat \$pidfile\`" >>$config_dir/reload-init -echo "#!/bin/sh" >>$config_dir/stop -echo "echo Stopping Webmin server in $wadir" >>$config_dir/stop -echo "pidfile=\`grep \"^pidfile=\" $config_dir/miniserv.conf | sed -e 's/pidfile=//g'\`" >>$config_dir/stop -echo "pid=\`cat \$pidfile\`" >>$config_dir/stop -echo "if [ \"\$pid\" != \"\" ]; then" >>$config_dir/stop -echo " kill \$pid || exit 1" >>$config_dir/stop -echo " touch $var_dir/stop-flag" >>$config_dir/stop -echo " if [ \"\$1\" = \"--kill\" ]; then" >>$config_dir/stop -echo " sleep 2" >>$config_dir/stop -echo " (kill -9 -- -\$pid || kill -9 \$pid) 2>/dev/null" >>$config_dir/stop -echo " fi" >>$config_dir/stop -echo " exit 0" >>$config_dir/stop -echo "else" >>$config_dir/stop -echo " exit 1" >>$config_dir/stop -echo "fi" >>$config_dir/stop - -echo "#!/bin/sh" >>$config_dir/restart -echo "$config_dir/stop --kill && $config_dir/start" >>$config_dir/restart - -echo "#!/bin/sh" >>$config_dir/reload -echo "echo Reloading Webmin server in $wadir" >>$config_dir/reload -echo "pidfile=\`grep \"^pidfile=\" $config_dir/miniserv.conf | sed -e 's/pidfile=//g'\`" >>$config_dir/reload -echo "kill -USR1 \`cat \$pidfile\`" >>$config_dir/reload - -chmod 755 $config_dir/start $config_dir/stop $config_dir/restart $config_dir/reload +chmod 755 $config_dir/stop-init $config_dir/start-init $config_dir/restart-init $config_dir/force-reload-init $config_dir/reload-init echo "..done" echo "" +# Re-generating supplementary +rm -f $config_dir/stop $config_dir/start $config_dir/restart $config_dir/force-reload $config_dir/reload +if command -v systemctl >/dev/null 2>&1; then + systemctlcmd=`which systemctl` + echo "Creating start and stop scripts (systemd).." + # Start systemd + echo "#!/bin/sh" >>$config_dir/start + echo "$config_dir/stop" >>$config_dir/start + echo "$systemctlcmd start webmin" >>$config_dir/start + # Stop systemd + echo "#!/bin/sh" >>$config_dir/stop + echo "$systemctlcmd stop webmin" >>$config_dir/stop + echo "$config_dir/stop-init >/dev/null 2>&1" >>$config_dir/stop + # Restart systemd + echo "#!/bin/sh" >>$config_dir/restart + echo "$config_dir/stop" >>$config_dir/restart + echo "$systemctlcmd start webmin" >>$config_dir/restart + # Force reload systemd + echo "#!/bin/sh" >>$config_dir/force-reload + echo "$config_dir/stop-init --kill >/dev/null 2>&1" >>$config_dir/force-reload + echo "$systemctlcmd stop webmin" >>$config_dir/force-reload + echo "$systemctlcmd start webmin" >>$config_dir/force-reload + # Reload systemd + echo "#!/bin/sh" >>$config_dir/reload + echo "$config_dir/reload-init >/dev/null 2>&1" >>$config_dir/reload + + chmod 755 $config_dir/stop $config_dir/start $config_dir/restart $config_dir/force-reload $config_dir/reload +else + echo "Creating start and stop init scripts (symlinks for old systems).." + ln -s $config_dir/start-init $config_dir/start + ln -s $config_dir/stop-init $config_dir/stop + ln -s $config_dir/restart-init $config_dir/restart + ln -s $config_dir/force-reload-init $config_dir/force-reload + ln -s $config_dir/reload-init $config_dir/reload +fi + if [ "$upgrading" = 1 -a "$inetd" != "1" ]; then # Stop old version, with updated stop script $config_dir/stop >/dev/null 2>&1 @@ -856,6 +899,9 @@ fi if [ "$nostart" = "" ]; then if [ "$inetd" != "1" ]; then echo "Attempting to start Webmin mini web server.." + if command -v systemctl >/dev/null 2>&1; then + systemctl daemon-reload + fi $config_dir/start if [ $? != "0" ]; then echo "ERROR: Failed to start web server!" diff --git a/webmin-init b/webmin-init index 4669b7d54..38f8eaf0b 100755 --- a/webmin-init +++ b/webmin-init @@ -18,63 +18,117 @@ PATH=/sbin:/usr/sbin:/bin:/usr/bin DESC="web-based administration interface for Unix systems" NAME=Webmin PIDFILE=/var/webmin/miniserv.pid -SCRIPTNAME=/etc/init.d/$NAME -START=/etc/webmin/start -STOP=/etc/webmin/stop -RELOAD=/etc/webmin/reload +SCRIPTNAME=/etc/init.d/webmin +START=/etc/webmin/start-init +STOP=/etc/webmin/stop-init +RELOAD=/etc/webmin/reload-init +FORCERELOAD=/etc/webmin/force-reload-init LOCKFILE=/var/lock/subsys/webmin CONFFILE=/etc/webmin/miniserv.conf +# Check if run directly, i.e. /etc/init.d/webmin start +# This is critical to have it resolved correctly +if [ -n "$HOME" ] && [ "$BASH_SUBSHELL" = 0 ]; then + # Check for systemd system + if command -v systemctl >/dev/null 2>&1; then + STARTSYSD=/etc/webmin/start + STOPSYSD=/etc/webmin/stop + RESTARTSYSD=/etc/webmin/restart + RELOADSYSD=/etc/webmin/reload + FORCERELOADSYSD=/etc/webmin/force-reload + WARNSYSD="WARN : [webmin] You are using traditional 'webmin' init script. It is advised to use \`systemctl $1 webmin\` directly." + fi +fi + case "$1" in start) - $START >/dev/null 2>&1 /dev/null 2>&1 + if [ -n "$STARTSYSD" ]; then + echo $WARNSYSD + echo "Starting $NAME (via systemctl)" + $STARTSYSD + RETVAL=$? + else + $START + RETVAL=$? + if [ "$RETVAL" = "0" ]; then + touch $LOCKFILE >/dev/null 2>&1 + fi fi ;; stop) - $STOP - RETVAL=$? - if [ "$RETVAL" = "0" ]; then - rm -f $LOCKFILE + if [ -n "$STOPSYSD" ]; then + echo $WARNSYSD + echo "Stopping $NAME (via systemctl)" + $STOPSYSD + RETVAL=$? + else + $STOP + RETVAL=$? + if [ "$RETVAL" = "0" ]; then + rm -f $LOCKFILE + pidfile=`grep "^pidfile=" $CONFFILE | sed -e 's/pidfile=//g'` + if [ "$pidfile" = "" ]; then + pidfile=$PIDFILE + fi + rm -f $pidfile + fi + fi + ;; +status) + if [ -n "$STARTSYSD" ]; then + echo $WARNSYSD + echo "$NAME status (via systemctl)" + systemctl status webmin + RETVAL=$? + else pidfile=`grep "^pidfile=" $CONFFILE | sed -e 's/pidfile=//g'` if [ "$pidfile" = "" ]; then pidfile=$PIDFILE fi - rm -f $pidfile - fi - ;; -status) - pidfile=`grep "^pidfile=" $CONFFILE | sed -e 's/pidfile=//g'` - if [ "$pidfile" = "" ]; then - pidfile=$PIDFILE - fi - if [ -s $pidfile ]; then - pid=`cat $pidfile` - kill -0 $pid >/dev/null 2>&1 - if [ "$?" = "0" ]; then - echo "$NAME (pid $pid) is running" - RETVAL=0 + if [ -s $pidfile ]; then + pid=`cat $pidfile` + kill -0 $pid >/dev/null 2>&1 + if [ "$?" = "0" ]; then + echo "$NAME (pid $pid) is running" + RETVAL=0 + else + echo "$NAME is stopped" + RETVAL=1 + fi else echo "$NAME is stopped" RETVAL=1 fi - else - echo "$NAME is stopped" - RETVAL=1 fi ;; restart) - $STOP ; $START + if [ -n "$RESTARTSYSD" ]; then + echo $WARNSYSD + echo "Restarting $NAME (via systemctl)" + $RESTARTSYSD + else + $STOP ; $START + fi RETVAL=$? ;; force-reload) - $STOP --kill ; $START + if [ -n "$FORCERELOADSYSD" ]; then + echo $WARNSYSD + echo "Force restarting $NAME (via systemctl)" + $FORCERELOADSYSD + else + $FORCERELOAD + fi RETVAL=$? ;; reload) - $RELOAD + if [ -n "$RELOADSYSD" ]; then + echo $WARNSYSD + echo "Reloading $NAME configuration (via systemctl)" + $RELOADSYSD + else + $RELOAD + fi RETVAL=$? ;; *) From e1abbd61e3bf30614ecc5d2629a3a6b7c3b4eb55 Mon Sep 17 00:00:00 2001 From: Ilia Date: Wed, 20 Apr 2022 04:01:12 +0300 Subject: [PATCH 06/52] Add extra `euid` check --- webmin-init | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/webmin-init b/webmin-init index 38f8eaf0b..db412ceaf 100755 --- a/webmin-init +++ b/webmin-init @@ -28,7 +28,9 @@ CONFFILE=/etc/webmin/miniserv.conf # Check if run directly, i.e. /etc/init.d/webmin start # This is critical to have it resolved correctly -if [ -n "$HOME" ] && [ "$BASH_SUBSHELL" = 0 ]; then +if [ "$BASH_SUBSHELL" = 0 ] && + [ "$EUID" = 0 ] && + [ -n "$HOME" ]; then # Check for systemd system if command -v systemctl >/dev/null 2>&1; then STARTSYSD=/etc/webmin/start From a3680e0173531c4a937ba2f89940d0f0a9a55c11 Mon Sep 17 00:00:00 2001 From: Ilia Date: Thu, 21 Apr 2022 03:55:33 +0300 Subject: [PATCH 07/52] Add support for native `systemd webmin.service` unit --- makedist.pl | 2 +- makepackage.pl | 17 +++++--- makerpm.pl | 99 ++++++++++++++++++++++++++----------------- setup.sh | 5 +-- webmin-init | 111 +++++++++++++------------------------------------ webmin-systemd | 16 +++++++ 6 files changed, 119 insertions(+), 131 deletions(-) create mode 100755 webmin-systemd diff --git a/makedist.pl b/makedist.pl index b5f9de081..9af050302 100755 --- a/makedist.pl +++ b/makedist.pl @@ -29,7 +29,7 @@ $vers || usage(); "group_chooser.cgi", "config-irix", "config-osf1", "thirdparty.pl", "oschooser.pl", "config-unixware", "config-openserver", "switch_user.cgi", "lang", "lang_list.txt", - "webmin-init", "webmin-daemon", + "webmin-systemd", "webmin-init", "webmin-daemon", "config-openbsd", "config-macos", "LICENCE", "session_login.cgi", "acl_security.pl", diff --git a/makepackage.pl b/makepackage.pl index f901b1b8d..80e8adc23 100755 --- a/makepackage.pl +++ b/makepackage.pl @@ -37,12 +37,17 @@ system("find . -print | grep -v \"^prototype\" | pkgproto >>prototype"); open(PROTO, ">> prototype"); print PROTO "i postinstall=./postinstall\n"; print PROTO "i preremove=./preremove\n"; -print PROTO "f none /etc/init.d/webmin=webmin-init 0755 root sys\n"; -print PROTO "l none /etc/rc3.d/S99webmin=/etc/init.d/webmin\n"; -print PROTO "l none /etc/rc0.d/K10webmin=/etc/init.d/webmin\n"; -print PROTO "l none /etc/rc1.d/K10webmin=/etc/init.d/webmin\n"; -print PROTO "l none /etc/rc2.d/K10webmin=/etc/init.d/webmin\n"; -print PROTO "l none /etc/rcS.d/K10webmin=/etc/init.d/webmin\n"; +if (-x "/usr/bin/systemctl") { + print PROTO "f none /etc/systemd/system/webmin.service=webmin-systemd 0755 root root\n"; + } +else { + print PROTO "f none /etc/init.d/webmin=webmin-init 0755 root sys\n"; + print PROTO "l none /etc/rc3.d/S99webmin=/etc/init.d/webmin\n"; + print PROTO "l none /etc/rc0.d/K10webmin=/etc/init.d/webmin\n"; + print PROTO "l none /etc/rc1.d/K10webmin=/etc/init.d/webmin\n"; + print PROTO "l none /etc/rc2.d/K10webmin=/etc/init.d/webmin\n"; + print PROTO "l none /etc/rcS.d/K10webmin=/etc/init.d/webmin\n"; + } close(PROTO); print ".. done\n\n"; diff --git a/makerpm.pl b/makerpm.pl index 451fdf3c0..042e64f03 100755 --- a/makerpm.pl +++ b/makerpm.pl @@ -105,45 +105,80 @@ chmod -R og-w . %install mkdir -p %{buildroot}/usr/libexec/webmin -mkdir -p %{buildroot}/etc/sysconfig/daemons -mkdir -p %{buildroot}/etc/rc.d/{rc0.d,rc1.d,rc2.d,rc3.d,rc5.d,rc6.d} -mkdir -p %{buildroot}/etc/init.d +if command -v systemctl >/dev/null 2>&1; then + mkdir -p %{buildroot}/etc/systemd/system/ +else + mkdir -p %{buildroot}/etc/sysconfig/daemons + mkdir -p %{buildroot}/etc/rc.d/{rc0.d,rc1.d,rc2.d,rc3.d,rc5.d,rc6.d} + mkdir -p %{buildroot}/etc/init.d +fi mkdir -p %{buildroot}/etc/pam.d mkdir -p %{buildroot}/usr/bin cp -rp * %{buildroot}/usr/libexec/webmin rm %{buildroot}/usr/libexec/webmin/blue-theme cp -rp %{buildroot}/usr/libexec/webmin/gray-theme %{buildroot}/usr/libexec/webmin/blue-theme -cp webmin-daemon %{buildroot}/etc/sysconfig/daemons/webmin -cp webmin-init %{buildroot}/etc/init.d/webmin -cp webmin-pam %{buildroot}/etc/pam.d/webmin -ln -s /etc/init.d/webmin %{buildroot}/etc/rc.d/rc2.d/S99webmin -ln -s /etc/init.d/webmin %{buildroot}/etc/rc.d/rc3.d/S99webmin -ln -s /etc/init.d/webmin %{buildroot}/etc/rc.d/rc5.d/S99webmin -ln -s /etc/init.d/webmin %{buildroot}/etc/rc.d/rc0.d/K10webmin -ln -s /etc/init.d/webmin %{buildroot}/etc/rc.d/rc1.d/K10webmin -ln -s /etc/init.d/webmin %{buildroot}/etc/rc.d/rc6.d/K10webmin +if command -v systemctl >/dev/null 2>&1; then + cp webmin-systemd %{buildroot}/etc/systemd/system/webmin.service +else + cp webmin-daemon %{buildroot}/etc/sysconfig/daemons/webmin + cp webmin-init %{buildroot}/etc/init.d/webmin + ln -s /etc/init.d/webmin %{buildroot}/etc/rc.d/rc2.d/S99webmin + ln -s /etc/init.d/webmin %{buildroot}/etc/rc.d/rc3.d/S99webmin + ln -s /etc/init.d/webmin %{buildroot}/etc/rc.d/rc5.d/S99webmin + ln -s /etc/init.d/webmin %{buildroot}/etc/rc.d/rc0.d/K10webmin + ln -s /etc/init.d/webmin %{buildroot}/etc/rc.d/rc1.d/K10webmin + ln -s /etc/init.d/webmin %{buildroot}/etc/rc.d/rc6.d/K10webmin +fi ln -s /usr/libexec/webmin/bin/webmin %{buildroot}/usr/bin +cp webmin-pam %{buildroot}/etc/pam.d/webmin echo rpm >%{buildroot}/usr/libexec/webmin/install-type +EXTRA_FILES="" +if command -v systemctl >/dev/null 2>&1; then + echo /etc/systemd/system/webmin.service > %{EXTRA_FILES} +else + echo %config /etc/sysconfig/daemons/webmin > %{EXTRA_FILES} + echo /etc/init.d/webmin >> %{EXTRA_FILES} + echo /etc/rc.d/rc2.d/S99webmin >> %{EXTRA_FILES} + echo /etc/rc.d/rc3.d/S99webmin >> %{EXTRA_FILES} + echo /etc/rc.d/rc5.d/S99webmin >> %{EXTRA_FILES} + echo /etc/rc.d/rc0.d/K10webmin >> %{EXTRA_FILES} + echo /etc/rc.d/rc1.d/K10webmin >> %{EXTRA_FILES} + echo /etc/rc.d/rc6.d/K10webmin >> %{EXTRA_FILES} +fi + %clean #%{rmDESTDIR} [ "%{buildroot}" != "/" ] && rm -rf %{buildroot} -%files +%files -f %{EXTRA_FILES} %defattr(-,root,root) /usr/libexec/webmin /usr/bin/webmin -%config /etc/sysconfig/daemons/webmin -/etc/init.d/webmin -/etc/rc.d/rc2.d/S99webmin -/etc/rc.d/rc3.d/S99webmin -/etc/rc.d/rc5.d/S99webmin -/etc/rc.d/rc0.d/K10webmin -/etc/rc.d/rc1.d/K10webmin -/etc/rc.d/rc6.d/K10webmin %config /etc/pam.d/webmin %pre +rm -f %{EXTRA_FILES} +if command -v systemctl >/dev/null 2>&1; then + rm -f %{buildroot}/etc/sysconfig/daemons/webmin >/dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1; then systemctl daemon-reload >/dev/null 2>&1 fi if [ "\$inetd" != "1" -a "\$startafter" = "1" ]; then - if command -v systemctl >/dev/null 2>&1; then - /etc/webmin/stop >/dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /etc/webmin/uninstall.sh </dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1; then - /etc/webmin/stop >/dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1; then echo "Creating start and stop scripts (systemd).." # Start systemd echo "#!/bin/sh" >>$config_dir/start - echo "$config_dir/stop" >>$config_dir/start echo "$systemctlcmd start webmin" >>$config_dir/start # Stop systemd echo "#!/bin/sh" >>$config_dir/stop echo "$systemctlcmd stop webmin" >>$config_dir/stop - echo "$config_dir/stop-init >/dev/null 2>&1" >>$config_dir/stop # Restart systemd echo "#!/bin/sh" >>$config_dir/restart - echo "$config_dir/stop" >>$config_dir/restart - echo "$systemctlcmd start webmin" >>$config_dir/restart + echo "$systemctlcmd restart webmin" >>$config_dir/restart # Force reload systemd echo "#!/bin/sh" >>$config_dir/force-reload echo "$config_dir/stop-init --kill >/dev/null 2>&1" >>$config_dir/force-reload diff --git a/webmin-init b/webmin-init index db412ceaf..74a782e68 100755 --- a/webmin-init +++ b/webmin-init @@ -26,111 +26,56 @@ FORCERELOAD=/etc/webmin/force-reload-init LOCKFILE=/var/lock/subsys/webmin CONFFILE=/etc/webmin/miniserv.conf -# Check if run directly, i.e. /etc/init.d/webmin start -# This is critical to have it resolved correctly -if [ "$BASH_SUBSHELL" = 0 ] && - [ "$EUID" = 0 ] && - [ -n "$HOME" ]; then - # Check for systemd system - if command -v systemctl >/dev/null 2>&1; then - STARTSYSD=/etc/webmin/start - STOPSYSD=/etc/webmin/stop - RESTARTSYSD=/etc/webmin/restart - RELOADSYSD=/etc/webmin/reload - FORCERELOADSYSD=/etc/webmin/force-reload - WARNSYSD="WARN : [webmin] You are using traditional 'webmin' init script. It is advised to use \`systemctl $1 webmin\` directly." - fi -fi - case "$1" in start) - if [ -n "$STARTSYSD" ]; then - echo $WARNSYSD - echo "Starting $NAME (via systemctl)" - $STARTSYSD - RETVAL=$? - else - $START - RETVAL=$? - if [ "$RETVAL" = "0" ]; then - touch $LOCKFILE >/dev/null 2>&1 - fi + $START + RETVAL=$? + if [ "$RETVAL" = "0" ]; then + touch $LOCKFILE >/dev/null 2>&1 fi ;; stop) - if [ -n "$STOPSYSD" ]; then - echo $WARNSYSD - echo "Stopping $NAME (via systemctl)" - $STOPSYSD - RETVAL=$? - else - $STOP - RETVAL=$? - if [ "$RETVAL" = "0" ]; then - rm -f $LOCKFILE - pidfile=`grep "^pidfile=" $CONFFILE | sed -e 's/pidfile=//g'` - if [ "$pidfile" = "" ]; then - pidfile=$PIDFILE - fi - rm -f $pidfile - fi - fi - ;; -status) - if [ -n "$STARTSYSD" ]; then - echo $WARNSYSD - echo "$NAME status (via systemctl)" - systemctl status webmin - RETVAL=$? - else + $STOP + RETVAL=$? + if [ "$RETVAL" = "0" ]; then + rm -f $LOCKFILE pidfile=`grep "^pidfile=" $CONFFILE | sed -e 's/pidfile=//g'` if [ "$pidfile" = "" ]; then pidfile=$PIDFILE fi - if [ -s $pidfile ]; then - pid=`cat $pidfile` - kill -0 $pid >/dev/null 2>&1 - if [ "$?" = "0" ]; then - echo "$NAME (pid $pid) is running" - RETVAL=0 - else - echo "$NAME is stopped" - RETVAL=1 - fi + rm -f $pidfile + fi + ;; +status) + pidfile=`grep "^pidfile=" $CONFFILE | sed -e 's/pidfile=//g'` + if [ "$pidfile" = "" ]; then + pidfile=$PIDFILE + fi + if [ -s $pidfile ]; then + pid=`cat $pidfile` + kill -0 $pid >/dev/null 2>&1 + if [ "$?" = "0" ]; then + echo "$NAME (pid $pid) is running" + RETVAL=0 else echo "$NAME is stopped" RETVAL=1 fi + else + echo "$NAME is stopped" + RETVAL=1 fi ;; restart) - if [ -n "$RESTARTSYSD" ]; then - echo $WARNSYSD - echo "Restarting $NAME (via systemctl)" - $RESTARTSYSD - else - $STOP ; $START - fi + $STOP ; $START RETVAL=$? ;; force-reload) - if [ -n "$FORCERELOADSYSD" ]; then - echo $WARNSYSD - echo "Force restarting $NAME (via systemctl)" - $FORCERELOADSYSD - else - $FORCERELOAD - fi + $FORCERELOAD RETVAL=$? ;; reload) - if [ -n "$RELOADSYSD" ]; then - echo $WARNSYSD - echo "Reloading $NAME configuration (via systemctl)" - $RELOADSYSD - else - $RELOAD - fi + $RELOAD RETVAL=$? ;; *) diff --git a/webmin-systemd b/webmin-systemd new file mode 100755 index 000000000..4765c7508 --- /dev/null +++ b/webmin-systemd @@ -0,0 +1,16 @@ +[Unit] +Description=Webmin server daemon +After=syslog.target +StartLimitIntervalSec=3 +StartLimitBurst=2 + +[Service] +Type=forking +PIDFile=/var/webmin/miniserv.pid +ExecStart=/etc/webmin/start-init +ExecStop=/etc/webmin/stop-init +KillMode=none +Restart=on-failure + +[Install] +WantedBy=multi-user.target From 13619825d9e50de7502d7c86f3fb869f84db0845 Mon Sep 17 00:00:00 2001 From: Ilia Date: Thu, 21 Apr 2022 14:25:13 +0300 Subject: [PATCH 08/52] Fix to properly deal with both `init.d` and `systemd` systems https://github.com/webmin/webmin/commit/a3680e0173531c4a937ba2f89940d0f0a9a55c11#r71796872 --- makerpm.pl | 95 +++++++++++++++++++++--------------------------------- setup.sh | 24 ++++++++++---- 2 files changed, 55 insertions(+), 64 deletions(-) diff --git a/makerpm.pl b/makerpm.pl index 042e64f03..9b871cb4a 100755 --- a/makerpm.pl +++ b/makerpm.pl @@ -105,80 +105,26 @@ chmod -R og-w . %install mkdir -p %{buildroot}/usr/libexec/webmin -if command -v systemctl >/dev/null 2>&1; then - mkdir -p %{buildroot}/etc/systemd/system/ -else - mkdir -p %{buildroot}/etc/sysconfig/daemons - mkdir -p %{buildroot}/etc/rc.d/{rc0.d,rc1.d,rc2.d,rc3.d,rc5.d,rc6.d} - mkdir -p %{buildroot}/etc/init.d -fi mkdir -p %{buildroot}/etc/pam.d mkdir -p %{buildroot}/usr/bin cp -rp * %{buildroot}/usr/libexec/webmin +cp webmin-pam %{buildroot}/etc/pam.d/webmin +ln -s /usr/libexec/webmin/bin/webmin %{buildroot}/usr/bin rm %{buildroot}/usr/libexec/webmin/blue-theme cp -rp %{buildroot}/usr/libexec/webmin/gray-theme %{buildroot}/usr/libexec/webmin/blue-theme -if command -v systemctl >/dev/null 2>&1; then - cp webmin-systemd %{buildroot}/etc/systemd/system/webmin.service -else - cp webmin-daemon %{buildroot}/etc/sysconfig/daemons/webmin - cp webmin-init %{buildroot}/etc/init.d/webmin - ln -s /etc/init.d/webmin %{buildroot}/etc/rc.d/rc2.d/S99webmin - ln -s /etc/init.d/webmin %{buildroot}/etc/rc.d/rc3.d/S99webmin - ln -s /etc/init.d/webmin %{buildroot}/etc/rc.d/rc5.d/S99webmin - ln -s /etc/init.d/webmin %{buildroot}/etc/rc.d/rc0.d/K10webmin - ln -s /etc/init.d/webmin %{buildroot}/etc/rc.d/rc1.d/K10webmin - ln -s /etc/init.d/webmin %{buildroot}/etc/rc.d/rc6.d/K10webmin -fi -ln -s /usr/libexec/webmin/bin/webmin %{buildroot}/usr/bin -cp webmin-pam %{buildroot}/etc/pam.d/webmin echo rpm >%{buildroot}/usr/libexec/webmin/install-type -EXTRA_FILES="" -if command -v systemctl >/dev/null 2>&1; then - echo /etc/systemd/system/webmin.service > %{EXTRA_FILES} -else - echo %config /etc/sysconfig/daemons/webmin > %{EXTRA_FILES} - echo /etc/init.d/webmin >> %{EXTRA_FILES} - echo /etc/rc.d/rc2.d/S99webmin >> %{EXTRA_FILES} - echo /etc/rc.d/rc3.d/S99webmin >> %{EXTRA_FILES} - echo /etc/rc.d/rc5.d/S99webmin >> %{EXTRA_FILES} - echo /etc/rc.d/rc0.d/K10webmin >> %{EXTRA_FILES} - echo /etc/rc.d/rc1.d/K10webmin >> %{EXTRA_FILES} - echo /etc/rc.d/rc6.d/K10webmin >> %{EXTRA_FILES} -fi - %clean #%{rmDESTDIR} [ "%{buildroot}" != "/" ] && rm -rf %{buildroot} -%files -f %{EXTRA_FILES} +%files %defattr(-,root,root) /usr/libexec/webmin /usr/bin/webmin %config /etc/pam.d/webmin %pre -rm -f %{EXTRA_FILES} -if command -v systemctl >/dev/null 2>&1; then - rm -f %{buildroot}/etc/sysconfig/daemons/webmin >/dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 \$tempdir/webmin-setup.out 2>&1 chmod 600 \$tempdir/webmin-setup.out rm -f /var/lock/subsys/webmin -if command -v systemctl >/dev/null 2>&1; then +cd /usr/libexec/webmin +if [ -x "\$(command -v systemctl)" >/dev/null 2>&1 ] && [ -d "/etc/systemd" ]; then + + rm -f /etc/sysconfig/daemons/webmin >/dev/null 2>&1 + rmdir /etc/sysconfig/daemons >/dev/null 2>&1 + rm -f /etc/init.d/webmin >/dev/null 2>&1 + rm -f /etc/rc.d/rc2.d/S99webmin >/dev/null 2>&1 + rm -f /etc/rc.d/rc3.d/S99webmin >/dev/null 2>&1 + rm -f /etc/rc.d/rc5.d/S99webmin >/dev/null 2>&1 + rm -f /etc/rc.d/rc0.d/K10webmin >/dev/null 2>&1 + rm -f /etc/rc.d/rc1.d/K10webmin >/dev/null 2>&1 + rm -f /etc/rc.d/rc6.d/K10webmin >/dev/null 2>&1 + rmdir /etc/rc.d/rc2.d >/dev/null 2>&1 + rmdir /etc/rc.d/rc3.d >/dev/null 2>&1 + rmdir /etc/rc.d/rc5.d >/dev/null 2>&1 + rmdir /etc/rc.d/rc0.d >/dev/null 2>&1 + rmdir /etc/rc.d/rc1.d >/dev/null 2>&1 + rmdir /etc/rc.d/rc6.d >/dev/null 2>&1 + + mkdir /etc/systemd/system + cp -p webmin-systemd /etc/systemd/system/webmin.service systemctl daemon-reload >/dev/null 2>&1 +else + mkdir -p /etc/sysconfig/daemons + cp -p webmin-daemon /etc/sysconfig/daemons/webmin + + cp -p webmin-init /etc/init.d/webmin + + mkdir -p /etc/rc.d/{rc0.d,rc1.d,rc2.d,rc3.d,rc5.d,rc6.d} >/dev/null 2>&1 + ln -s /etc/init.d/webmin /etc/rc.d/rc2.d/S99webmin >/dev/null 2>&1 + ln -s /etc/init.d/webmin /etc/rc.d/rc3.d/S99webmin >/dev/null 2>&1 + ln -s /etc/init.d/webmin /etc/rc.d/rc5.d/S99webmin >/dev/null 2>&1 + ln -s /etc/init.d/webmin /etc/rc.d/rc0.d/K10webmin >/dev/null 2>&1 + ln -s /etc/init.d/webmin /etc/rc.d/rc1.d/K10webmin >/dev/null 2>&1 + ln -s /etc/init.d/webmin /etc/rc.d/rc6.d/K10webmin >/dev/null 2>&1 fi if [ "\$inetd" != "1" -a "\$startafter" = "1" ]; then /etc/webmin/stop >/dev/null 2>&1 /dev/null 2>&1; then chmod 755 $config_dir/stop $config_dir/start $config_dir/restart $config_dir/force-reload $config_dir/reload else - echo "Creating start and stop init scripts (symlinks for old systems).." - ln -s $config_dir/start-init $config_dir/start - ln -s $config_dir/stop-init $config_dir/stop - ln -s $config_dir/restart-init $config_dir/restart - ln -s $config_dir/force-reload-init $config_dir/force-reload - ln -s $config_dir/reload-init $config_dir/reload + echo "Creating start and stop init scripts (init.d for older systems).." + # Start init.d + echo "#!/bin/sh" >>$config_dir/start + echo "/etc/init.d/webmin start" >>$config_dir/start + # Stop init.d + echo "#!/bin/sh" >>$config_dir/stop + echo "/etc/init.d/webmin stop" >>$config_dir/stop + # Restart init.d + echo "#!/bin/sh" >>$config_dir/restart + echo "/etc/init.d/webmin restart" >>$config_dir/restart + # Force reload init.d + echo "#!/bin/sh" >>$config_dir/force-reload + echo "$config_dir/stop-init --kill >/dev/null 2>&1" >>$config_dir/force-reload + echo "/etc/init.d/webmin stop" >>$config_dir/force-reload + echo "/etc/init.d/webmin start" >>$config_dir/force-reload + # Reload init.d + echo "#!/bin/sh" >>$config_dir/reload + echo "/etc/init.d/webmin reload >/dev/null 2>&1" >>$config_dir/reload fi if [ "$upgrading" = 1 -a "$inetd" != "1" ]; then From 64c14c79759792ae408341ffae428daaa7cba5a1 Mon Sep 17 00:00:00 2001 From: Ilia Date: Thu, 21 Apr 2022 17:06:41 +0300 Subject: [PATCH 09/52] Clear generated files upon installation --- makerpm.pl | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/makerpm.pl b/makerpm.pl index 9b871cb4a..bad0b2395 100755 --- a/makerpm.pl +++ b/makerpm.pl @@ -250,14 +250,14 @@ if [ -x "\$(command -v systemctl)" >/dev/null 2>&1 ] && [ -d "/etc/systemd" ]; t rmdir /etc/rc.d/rc1.d >/dev/null 2>&1 rmdir /etc/rc.d/rc6.d >/dev/null 2>&1 - mkdir /etc/systemd/system - cp -p webmin-systemd /etc/systemd/system/webmin.service + mkdir /etc/systemd/system >/dev/null 2>&1 + cp -p webmin-systemd /etc/systemd/system/webmin.service >/dev/null 2>&1 systemctl daemon-reload >/dev/null 2>&1 else - mkdir -p /etc/sysconfig/daemons - cp -p webmin-daemon /etc/sysconfig/daemons/webmin + mkdir -p /etc/sysconfig/daemons >/dev/null 2>&1 + cp -p webmin-daemon /etc/sysconfig/daemons/webmin >/dev/null 2>&1 - cp -p webmin-init /etc/init.d/webmin + cp -p webmin-init /etc/init.d/webmin >/dev/null 2>&1 mkdir -p /etc/rc.d/{rc0.d,rc1.d,rc2.d,rc3.d,rc5.d,rc6.d} >/dev/null 2>&1 ln -s /etc/init.d/webmin /etc/rc.d/rc2.d/S99webmin >/dev/null 2>&1 @@ -328,6 +328,27 @@ if [ "\$1" = 0 ]; then rm -rf /etc/webmin.rpmsave mv /etc/webmin /etc/webmin.rpmsave rm -rf /var/webmin + + rm -f /etc/sysconfig/daemons/webmin >/dev/null 2>&1 + rmdir /etc/sysconfig/daemons >/dev/null 2>&1 + rm -f /etc/init.d/webmin >/dev/null 2>&1 + rm -f /etc/rc.d/rc2.d/S99webmin >/dev/null 2>&1 + rm -f /etc/rc.d/rc3.d/S99webmin >/dev/null 2>&1 + rm -f /etc/rc.d/rc5.d/S99webmin >/dev/null 2>&1 + rm -f /etc/rc.d/rc0.d/K10webmin >/dev/null 2>&1 + rm -f /etc/rc.d/rc1.d/K10webmin >/dev/null 2>&1 + rm -f /etc/rc.d/rc6.d/K10webmin >/dev/null 2>&1 + rmdir /etc/rc.d/rc2.d >/dev/null 2>&1 + rmdir /etc/rc.d/rc3.d >/dev/null 2>&1 + rmdir /etc/rc.d/rc5.d >/dev/null 2>&1 + rmdir /etc/rc.d/rc0.d >/dev/null 2>&1 + rmdir /etc/rc.d/rc1.d >/dev/null 2>&1 + rmdir /etc/rc.d/rc6.d >/dev/null 2>&1 + + rm -f /etc/systemd/system/webmin.service >/dev/null 2>&1 + if [ -x "\$(command -v systemctl)" >/dev/null 2>&1 ]; then + systemctl daemon-reload >/dev/null 2>&1 + fi fi fi /bin/true From 349741ce88daf99fd704fa66aadc3eedb85f3b1d Mon Sep 17 00:00:00 2001 From: Ilia Date: Thu, 21 Apr 2022 19:00:05 +0300 Subject: [PATCH 10/52] Fix generated scripts mod --- setup.sh | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/setup.sh b/setup.sh index 1e2df5964..9b48f1d32 100755 --- a/setup.sh +++ b/setup.sh @@ -677,9 +677,7 @@ if command -v systemctl >/dev/null 2>&1; then echo "$systemctlcmd start webmin" >>$config_dir/force-reload # Reload systemd echo "#!/bin/sh" >>$config_dir/reload - echo "$config_dir/reload-init >/dev/null 2>&1" >>$config_dir/reload - - chmod 755 $config_dir/stop $config_dir/start $config_dir/restart $config_dir/force-reload $config_dir/reload + echo "$config_dir/reload-init >/dev/null 2>&1" >>$config_dir/reload else echo "Creating start and stop init scripts (init.d for older systems).." # Start init.d @@ -700,6 +698,7 @@ else echo "#!/bin/sh" >>$config_dir/reload echo "/etc/init.d/webmin reload >/dev/null 2>&1" >>$config_dir/reload fi +chmod 755 $config_dir/stop $config_dir/start $config_dir/restart $config_dir/force-reload $config_dir/reload if [ "$upgrading" = 1 -a "$inetd" != "1" ]; then # Stop old version, with updated stop script From 68042ecec6f9102b87879367b8a8a2492327a68d Mon Sep 17 00:00:00 2001 From: Ilia Date: Fri, 22 Apr 2022 13:58:30 +0300 Subject: [PATCH 11/52] Fix systemctl test --- makedebian.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makedebian.pl b/makedebian.pl index d95b25a1f..45b948efe 100755 --- a/makedebian.pl +++ b/makedebian.pl @@ -326,7 +326,7 @@ if [ "$product" = "webmin" ]; then fi fi rm -f /var/lock/subsys/$baseproduct -if command -v systemctl >/dev/null 2>&1; then +if [ -x "\$(command -v systemctl)" >/dev/null 2>&1 ] && [ -d "/etc/systemd" ]; then systemctl daemon-reload >/dev/null 2>&1 fi if [ "$inetd" != "1" ]; then From 574c5a39b422e7364c4d5dd00e25e295e6730675 Mon Sep 17 00:00:00 2001 From: Ilia Date: Fri, 22 Apr 2022 14:41:14 +0300 Subject: [PATCH 12/52] Unroll previous changes --- makepackage.pl | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/makepackage.pl b/makepackage.pl index 80e8adc23..f901b1b8d 100755 --- a/makepackage.pl +++ b/makepackage.pl @@ -37,17 +37,12 @@ system("find . -print | grep -v \"^prototype\" | pkgproto >>prototype"); open(PROTO, ">> prototype"); print PROTO "i postinstall=./postinstall\n"; print PROTO "i preremove=./preremove\n"; -if (-x "/usr/bin/systemctl") { - print PROTO "f none /etc/systemd/system/webmin.service=webmin-systemd 0755 root root\n"; - } -else { - print PROTO "f none /etc/init.d/webmin=webmin-init 0755 root sys\n"; - print PROTO "l none /etc/rc3.d/S99webmin=/etc/init.d/webmin\n"; - print PROTO "l none /etc/rc0.d/K10webmin=/etc/init.d/webmin\n"; - print PROTO "l none /etc/rc1.d/K10webmin=/etc/init.d/webmin\n"; - print PROTO "l none /etc/rc2.d/K10webmin=/etc/init.d/webmin\n"; - print PROTO "l none /etc/rcS.d/K10webmin=/etc/init.d/webmin\n"; - } +print PROTO "f none /etc/init.d/webmin=webmin-init 0755 root sys\n"; +print PROTO "l none /etc/rc3.d/S99webmin=/etc/init.d/webmin\n"; +print PROTO "l none /etc/rc0.d/K10webmin=/etc/init.d/webmin\n"; +print PROTO "l none /etc/rc1.d/K10webmin=/etc/init.d/webmin\n"; +print PROTO "l none /etc/rc2.d/K10webmin=/etc/init.d/webmin\n"; +print PROTO "l none /etc/rcS.d/K10webmin=/etc/init.d/webmin\n"; close(PROTO); print ".. done\n\n"; From 5640bd6028d4bf72885dfd6b1dd57eb6ccf78f98 Mon Sep 17 00:00:00 2001 From: Ilia Date: Fri, 22 Apr 2022 14:42:04 +0300 Subject: [PATCH 13/52] Remove creating init.d on package creation time --- makedebian.pl | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/makedebian.pl b/makedebian.pl index 45b948efe..acda6bb7d 100755 --- a/makedebian.pl +++ b/makedebian.pl @@ -31,7 +31,7 @@ $copyright_file = "$doc_dir/copyright"; $usr_dir = "$tmp_dir/usr/share/$baseproduct"; $bin_dir = "$tmp_dir/usr/bin"; $pam_dir = "$tmp_dir/etc/pam.d"; -$init_dir = "$tmp_dir/etc/init.d"; +# $init_dir = "$tmp_dir/etc/init.d"; $pam_file = "$pam_dir/$baseproduct"; $preinstall_file = "$debian_dir/preinst"; $postinstall_file = "$debian_dir/postinst"; @@ -61,7 +61,7 @@ mkdir($tmp_dir, 0755); chmod(0755, $tmp_dir); mkdir($debian_dir, 0755); system("mkdir -p $pam_dir"); -system("mkdir -p $init_dir"); +# system("mkdir -p $init_dir"); system("mkdir -p $usr_dir"); system("mkdir -p $doc_dir"); system("mkdir -p $bin_dir"); @@ -83,8 +83,8 @@ if ($product eq "webmin") { } # Create init script -system("mv $usr_dir/$baseproduct-init $init_dir/$baseproduct"); -chmod(0755, "$init_dir/$baseproduct"); +# system("mv $usr_dir/$baseproduct-init $init_dir/$baseproduct"); +# chmod(0755, "$init_dir/$baseproduct"); system("echo deb >$usr_dir/install-type"); system("echo $product >$usr_dir/deb-name"); system("cd $usr_dir && chmod -R og-w ."); @@ -328,6 +328,7 @@ fi rm -f /var/lock/subsys/$baseproduct if [ -x "\$(command -v systemctl)" >/dev/null 2>&1 ] && [ -d "/etc/systemd" ]; then systemctl daemon-reload >/dev/null 2>&1 + fi if [ "$inetd" != "1" ]; then if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then From 8f3b2e350f7832b038b8f19b44123df4e85dfde7 Mon Sep 17 00:00:00 2001 From: Ilia Date: Fri, 22 Apr 2022 15:05:17 +0300 Subject: [PATCH 14/52] Prevent fixing already fixed stop script --- makedebian.pl | 9 +++++---- makerpm.pl | 7 ++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/makedebian.pl b/makedebian.pl index acda6bb7d..38f193440 100755 --- a/makedebian.pl +++ b/makedebian.pl @@ -265,8 +265,9 @@ open(SCRIPT, ">$postinstall_file"); print SCRIPT </etc/webmin/stop 2>/dev/null <<'EOD' #!/bin/sh pidfile=`grep "^pidfile=" /etc/webmin/miniserv.conf | sed -e 's/pidfile=//g'` @@ -282,7 +283,7 @@ fi inetd=`grep "^inetd=" /etc/$baseproduct/miniserv.conf 2>/dev/null | sed -e 's/inetd=//g'` if [ "\$1" = "upgrade" -a "\$1" != "abort-upgrade" ]; then - # Upgrading the package, so stop the old webmin properly + # Upgrading the package, so stop the old Webmin properly if [ "\$inetd" != "1" ]; then /etc/$baseproduct/stop >/dev/null 2>&1 /dev/null 2>&1 ] && [ -d "/etc/systemd" ]; then systemctl daemon-reload >/dev/null 2>&1 - + fi if [ "$inetd" != "1" ]; then if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then diff --git a/makerpm.pl b/makerpm.pl index bad0b2395..2a60b7d23 100755 --- a/makerpm.pl +++ b/makerpm.pl @@ -172,8 +172,9 @@ fi inetd=`grep "^inetd=" /etc/webmin/miniserv.conf 2>/dev/null | sed -e 's/inetd=//g'` startafter=0 -# Fix old versions of Webmin that might kill the UI process on upgrade -if [ -d /etc/webmin ]; then +# Fix old versions of Webmin that might kill the UI +# process on upgrade, unless it's already fixed version +if [ -d /etc/webmin ] && [ ! -f "/etc/webmin/stop-init" ]; then cat >/etc/webmin/stop 2>/dev/null <<'EOD' #!/bin/sh pidfile=`grep "^pidfile=" /etc/webmin/miniserv.conf | sed -e 's/pidfile=//g'` @@ -188,7 +189,7 @@ EOD fi if [ "\$1" != 1 ]; then - # Upgrading the RPM, so stop the old webmin properly + # Upgrading the RPM, so stop the old Webmin properly if [ "\$inetd" != "1" ]; then kill -0 `cat /var/webmin/miniserv.pid 2>/dev/null` 2>/dev/null if [ "\$?" = 0 ]; then From c466274443600cae2af35d5595b7f708fc9fb016 Mon Sep 17 00:00:00 2001 From: Ilia Date: Fri, 22 Apr 2022 17:17:01 +0300 Subject: [PATCH 15/52] Switch to creating centralized startup service in `setup.sh` 1/2 --- init/isboot.pl | 12 ++++++++++++ makedebian.pl | 16 +++------------- makerpm.pl | 35 +---------------------------------- setup.sh | 46 ++++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 58 insertions(+), 51 deletions(-) create mode 100755 init/isboot.pl diff --git a/init/isboot.pl b/init/isboot.pl new file mode 100755 index 000000000..72452c3ea --- /dev/null +++ b/init/isboot.pl @@ -0,0 +1,12 @@ +#!/usr/bin/perl +# isboot.pl +# Called by setup.sh to check if given service is enabled + +$no_acl_check++; +require './init-lib.pl'; +$product = $ARGV[0] || "webmin"; +if (&action_status($product) == 2) { + print 1; + exit; + }; +print 0; diff --git a/makedebian.pl b/makedebian.pl index 38f193440..80508ee8a 100755 --- a/makedebian.pl +++ b/makedebian.pl @@ -327,22 +327,12 @@ if [ "$product" = "webmin" ]; then fi fi rm -f /var/lock/subsys/$baseproduct -if [ -x "\$(command -v systemctl)" >/dev/null 2>&1 ] && [ -d "/etc/systemd" ]; then - systemctl daemon-reload >/dev/null 2>&1 -fi if [ "$inetd" != "1" ]; then - if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then - invoke-rc.d $baseproduct stop - invoke-rc.d $baseproduct start - else - /etc/$baseproduct/stop - /etc/$baseproduct/start - fi -fi -if [ "$product" = "usermin" ]; then - (insserv $baseproduct || update-rc.d $baseproduct defaults) >/dev/null 2>&1 + /etc/$baseproduct/stop + /etc/$baseproduct/start fi + cat >/etc/$baseproduct/uninstall.sh </dev/null 2>&1 ] && [ -d "/etc/systemd" ]; then - rm -f /etc/sysconfig/daemons/webmin >/dev/null 2>&1 - rmdir /etc/sysconfig/daemons >/dev/null 2>&1 - rm -f /etc/init.d/webmin >/dev/null 2>&1 - rm -f /etc/rc.d/rc2.d/S99webmin >/dev/null 2>&1 - rm -f /etc/rc.d/rc3.d/S99webmin >/dev/null 2>&1 - rm -f /etc/rc.d/rc5.d/S99webmin >/dev/null 2>&1 - rm -f /etc/rc.d/rc0.d/K10webmin >/dev/null 2>&1 - rm -f /etc/rc.d/rc1.d/K10webmin >/dev/null 2>&1 - rm -f /etc/rc.d/rc6.d/K10webmin >/dev/null 2>&1 - rmdir /etc/rc.d/rc2.d >/dev/null 2>&1 - rmdir /etc/rc.d/rc3.d >/dev/null 2>&1 - rmdir /etc/rc.d/rc5.d >/dev/null 2>&1 - rmdir /etc/rc.d/rc0.d >/dev/null 2>&1 - rmdir /etc/rc.d/rc1.d >/dev/null 2>&1 - rmdir /etc/rc.d/rc6.d >/dev/null 2>&1 - - mkdir /etc/systemd/system >/dev/null 2>&1 - cp -p webmin-systemd /etc/systemd/system/webmin.service >/dev/null 2>&1 - systemctl daemon-reload >/dev/null 2>&1 -else - mkdir -p /etc/sysconfig/daemons >/dev/null 2>&1 - cp -p webmin-daemon /etc/sysconfig/daemons/webmin >/dev/null 2>&1 - - cp -p webmin-init /etc/init.d/webmin >/dev/null 2>&1 - - mkdir -p /etc/rc.d/{rc0.d,rc1.d,rc2.d,rc3.d,rc5.d,rc6.d} >/dev/null 2>&1 - ln -s /etc/init.d/webmin /etc/rc.d/rc2.d/S99webmin >/dev/null 2>&1 - ln -s /etc/init.d/webmin /etc/rc.d/rc3.d/S99webmin >/dev/null 2>&1 - ln -s /etc/init.d/webmin /etc/rc.d/rc5.d/S99webmin >/dev/null 2>&1 - ln -s /etc/init.d/webmin /etc/rc.d/rc0.d/K10webmin >/dev/null 2>&1 - ln -s /etc/init.d/webmin /etc/rc.d/rc1.d/K10webmin >/dev/null 2>&1 - ln -s /etc/init.d/webmin /etc/rc.d/rc6.d/K10webmin >/dev/null 2>&1 -fi if [ "\$inetd" != "1" -a "\$startafter" = "1" ]; then /etc/webmin/stop >/dev/null 2>&1 /dev/null 2>&1 /etc/webmin/uninstall.sh </dev/null 2>&1 +rmdir "/etc/sysconfig/daemons" >/dev/null 2>&1 +rm -f "/etc/init.d/webmin" >/dev/null 2>&1 +rm -f "/etc/rc.d/rc2.d/S99webmin" >/dev/null 2>&1 +rm -f "/etc/rc.d/rc3.d/S99webmin" >/dev/null 2>&1 +rm -f "/etc/rc.d/rc5.d/S99webmin" >/dev/null 2>&1 +rm -f "/etc/rc.d/rc0.d/K10webmin" >/dev/null 2>&1 +rm -f "/etc/rc.d/rc1.d/K10webmin" >/dev/null 2>&1 +rm -f "/etc/rc.d/rc6.d/K10webmin" >/dev/null 2>&1 +rmdir "/etc/rc.d/rc2.d" >/dev/null 2>&1 +rmdir "/etc/rc.d/rc3.d" >/dev/null 2>&1 +rmdir "/etc/rc.d/rc5.d" >/dev/null 2>&1 +rmdir "/etc/rc.d/rc0.d" >/dev/null 2>&1 +rmdir "/etc/rc.d/rc1.d" >/dev/null 2>&1 +rmdir "/etc/rc.d/rc6.d" >/dev/null 2>&1 +rm -f "/etc/systemd/system/$currprod.service" >/dev/null 2>&1 + # Re-generating supplementary rm -f $config_dir/stop $config_dir/start $config_dir/restart $config_dir/force-reload $config_dir/reload if command -v systemctl >/dev/null 2>&1; then @@ -677,7 +710,12 @@ if command -v systemctl >/dev/null 2>&1; then echo "$systemctlcmd start webmin" >>$config_dir/force-reload # Reload systemd echo "#!/bin/sh" >>$config_dir/reload - echo "$config_dir/reload-init >/dev/null 2>&1" >>$config_dir/reload + echo "$config_dir/reload-init >/dev/null 2>&1" >>$config_dir/reload + + # Copy systemd webmin.service and reload daemon + mkdir -p "/etc/systemd/system" >/dev/null 2>&1 + cp -p "$wadir/webmin-systemd" "/etc/systemd/system/webmin.service" >/dev/null 2>&1 + systemctl daemon-reload >/dev/null 2>&1 else echo "Creating start and stop init scripts (init.d for older systems).." # Start init.d @@ -697,6 +735,9 @@ else # Reload init.d echo "#!/bin/sh" >>$config_dir/reload echo "/etc/init.d/webmin reload >/dev/null 2>&1" >>$config_dir/reload + + # Copy init.d webmin script + cp -p "$wadir/webmin-init" "/etc/init.d/webmin" >/dev/null 2>&1 fi chmod 755 $config_dir/stop $config_dir/start $config_dir/restart $config_dir/force-reload $config_dir/reload @@ -907,9 +948,6 @@ fi if [ "$nostart" = "" ]; then if [ "$inetd" != "1" ]; then echo "Attempting to start Webmin mini web server.." - if command -v systemctl >/dev/null 2>&1; then - systemctl daemon-reload - fi $config_dir/start if [ $? != "0" ]; then echo "ERROR: Failed to start web server!" From b70a9f9917e9f766c106507765d319840b46945f Mon Sep 17 00:00:00 2001 From: Ilia Date: Fri, 22 Apr 2022 23:43:44 +0300 Subject: [PATCH 16/52] Enable only when switching to new `systemd` mode --- init/isboot.pl | 8 ++++---- setup.sh | 3 --- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/init/isboot.pl b/init/isboot.pl index 72452c3ea..28b03a0fd 100755 --- a/init/isboot.pl +++ b/init/isboot.pl @@ -5,8 +5,8 @@ $no_acl_check++; require './init-lib.pl'; $product = $ARGV[0] || "webmin"; -if (&action_status($product) == 2) { - print 1; - exit; +# Is enabled and system supports systemd +if (&action_status($product) == 2 && + $init_mode eq "systemd") { + &enable_at_boot($product); }; -print 0; diff --git a/setup.sh b/setup.sh index 68a79c06b..a899c742c 100755 --- a/setup.sh +++ b/setup.sh @@ -609,9 +609,6 @@ currprod=`grep "^product=" /etc/webmin/config | sed -e 's/product=//g'` # re-enable service afterwards if was enabled before if [ "$upgrading" = 1 ] && [ ! -f "$config_dir/stop-init" ]; then upgatboot=`(cd "$wadir/init" ; WEBMIN_CONFIG=$config_dir WEBMIN_VAR=$var_dir "$wadir/init/isboot.pl")` - if [ "$upgatboot" = 1 ]; then - makeboot=1 - fi fi # Return back to root From 9b7e14d7816948ed71c1ab13d7fe2be9a5fc5817 Mon Sep 17 00:00:00 2001 From: Ilia Date: Fri, 22 Apr 2022 23:44:20 +0300 Subject: [PATCH 17/52] No need to store variable --- setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.sh b/setup.sh index a899c742c..414cb247c 100755 --- a/setup.sh +++ b/setup.sh @@ -608,7 +608,7 @@ currprod=`grep "^product=" /etc/webmin/config | sed -e 's/product=//g'` # Test if transitioning from init.d to systemd, and # re-enable service afterwards if was enabled before if [ "$upgrading" = 1 ] && [ ! -f "$config_dir/stop-init" ]; then - upgatboot=`(cd "$wadir/init" ; WEBMIN_CONFIG=$config_dir WEBMIN_VAR=$var_dir "$wadir/init/isboot.pl")` + (cd "$wadir/init" ; WEBMIN_CONFIG=$config_dir WEBMIN_VAR=$var_dir "$wadir/init/isboot.pl") fi # Return back to root From 3b722daa81e77b6a31352653032451b526df9f76 Mon Sep 17 00:00:00 2001 From: Ilia Date: Fri, 22 Apr 2022 23:58:02 +0300 Subject: [PATCH 18/52] Enable service only after script is ready --- setup.sh | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/setup.sh b/setup.sh index 414cb247c..17e6189e9 100755 --- a/setup.sh +++ b/setup.sh @@ -605,12 +605,6 @@ fi # Get current product currprod=`grep "^product=" /etc/webmin/config | sed -e 's/product=//g'` -# Test if transitioning from init.d to systemd, and -# re-enable service afterwards if was enabled before -if [ "$upgrading" = 1 ] && [ ! -f "$config_dir/stop-init" ]; then - (cd "$wadir/init" ; WEBMIN_CONFIG=$config_dir WEBMIN_VAR=$var_dir "$wadir/init/isboot.pl") -fi - # Return back to root cd "$wadir" @@ -713,6 +707,12 @@ if command -v systemctl >/dev/null 2>&1; then mkdir -p "/etc/systemd/system" >/dev/null 2>&1 cp -p "$wadir/webmin-systemd" "/etc/systemd/system/webmin.service" >/dev/null 2>&1 systemctl daemon-reload >/dev/null 2>&1 + + # Test if transitioning from init.d to systemd, and + # re-enable service afterwards if was enabled before + if [ "$upgrading" = 1 ] && [ ! -f "$config_dir/stop-init" ]; then + (cd "$wadir/init" ; WEBMIN_CONFIG=$config_dir WEBMIN_VAR=$var_dir "$wadir/init/isboot.pl") + fi else echo "Creating start and stop init scripts (init.d for older systems).." # Start init.d From e0ece6d26b24099b141ea59fc577827bcd425a12 Mon Sep 17 00:00:00 2001 From: Ilia Date: Sat, 23 Apr 2022 00:13:39 +0300 Subject: [PATCH 19/52] Partially revert incorrect assumptions in centralized startup 2/2 --- setup.sh | 38 -------------------------------------- 1 file changed, 38 deletions(-) diff --git a/setup.sh b/setup.sh index 17e6189e9..180368810 100755 --- a/setup.sh +++ b/setup.sh @@ -602,12 +602,6 @@ if [ "$noperlpath" = "" ]; then echo "" fi -# Get current product -currprod=`grep "^product=" /etc/webmin/config | sed -e 's/product=//g'` - -# Return back to root -cd "$wadir" - # Re-generating main rm -f $config_dir/stop-init $config_dir/start-init $config_dir/restart-init $config_dir/force-reload-init $config_dir/reload-init echo "Creating start and stop init scripts.." @@ -662,24 +656,6 @@ chmod 755 $config_dir/stop-init $config_dir/start-init $config_dir/restart-init echo "..done" echo "" -# Clear old installs -rm -f "/etc/sysconfig/daemons/webmin" >/dev/null 2>&1 -rmdir "/etc/sysconfig/daemons" >/dev/null 2>&1 -rm -f "/etc/init.d/webmin" >/dev/null 2>&1 -rm -f "/etc/rc.d/rc2.d/S99webmin" >/dev/null 2>&1 -rm -f "/etc/rc.d/rc3.d/S99webmin" >/dev/null 2>&1 -rm -f "/etc/rc.d/rc5.d/S99webmin" >/dev/null 2>&1 -rm -f "/etc/rc.d/rc0.d/K10webmin" >/dev/null 2>&1 -rm -f "/etc/rc.d/rc1.d/K10webmin" >/dev/null 2>&1 -rm -f "/etc/rc.d/rc6.d/K10webmin" >/dev/null 2>&1 -rmdir "/etc/rc.d/rc2.d" >/dev/null 2>&1 -rmdir "/etc/rc.d/rc3.d" >/dev/null 2>&1 -rmdir "/etc/rc.d/rc5.d" >/dev/null 2>&1 -rmdir "/etc/rc.d/rc0.d" >/dev/null 2>&1 -rmdir "/etc/rc.d/rc1.d" >/dev/null 2>&1 -rmdir "/etc/rc.d/rc6.d" >/dev/null 2>&1 -rm -f "/etc/systemd/system/$currprod.service" >/dev/null 2>&1 - # Re-generating supplementary rm -f $config_dir/stop $config_dir/start $config_dir/restart $config_dir/force-reload $config_dir/reload if command -v systemctl >/dev/null 2>&1; then @@ -702,17 +678,6 @@ if command -v systemctl >/dev/null 2>&1; then # Reload systemd echo "#!/bin/sh" >>$config_dir/reload echo "$config_dir/reload-init >/dev/null 2>&1" >>$config_dir/reload - - # Copy systemd webmin.service and reload daemon - mkdir -p "/etc/systemd/system" >/dev/null 2>&1 - cp -p "$wadir/webmin-systemd" "/etc/systemd/system/webmin.service" >/dev/null 2>&1 - systemctl daemon-reload >/dev/null 2>&1 - - # Test if transitioning from init.d to systemd, and - # re-enable service afterwards if was enabled before - if [ "$upgrading" = 1 ] && [ ! -f "$config_dir/stop-init" ]; then - (cd "$wadir/init" ; WEBMIN_CONFIG=$config_dir WEBMIN_VAR=$var_dir "$wadir/init/isboot.pl") - fi else echo "Creating start and stop init scripts (init.d for older systems).." # Start init.d @@ -732,9 +697,6 @@ else # Reload init.d echo "#!/bin/sh" >>$config_dir/reload echo "/etc/init.d/webmin reload >/dev/null 2>&1" >>$config_dir/reload - - # Copy init.d webmin script - cp -p "$wadir/webmin-init" "/etc/init.d/webmin" >/dev/null 2>&1 fi chmod 755 $config_dir/stop $config_dir/start $config_dir/restart $config_dir/force-reload $config_dir/reload From 98d3a1d98400402b49ba46ff10d01f55a8bd3ec4 Mon Sep 17 00:00:00 2001 From: Ilia Date: Sat, 23 Apr 2022 00:18:39 +0300 Subject: [PATCH 20/52] Further revert back for RPM --- makerpm.pl | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/makerpm.pl b/makerpm.pl index d07135797..2df6321c9 100755 --- a/makerpm.pl +++ b/makerpm.pl @@ -233,7 +233,41 @@ export config_dir var_dir perl autoos port login crypt host ssl nochown autothir chmod 600 \$tempdir/webmin-setup.out rm -f /var/lock/subsys/webmin cd /usr/libexec/webmin +if [ -x "\$(command -v systemctl)" >/dev/null 2>&1 ] && [ -d "/etc/systemd" ]; then + rm -f /etc/sysconfig/daemons/webmin >/dev/null 2>&1 + rmdir /etc/sysconfig/daemons >/dev/null 2>&1 + rm -f /etc/init.d/webmin >/dev/null 2>&1 + rm -f /etc/rc.d/rc2.d/S99webmin >/dev/null 2>&1 + rm -f /etc/rc.d/rc3.d/S99webmin >/dev/null 2>&1 + rm -f /etc/rc.d/rc5.d/S99webmin >/dev/null 2>&1 + rm -f /etc/rc.d/rc0.d/K10webmin >/dev/null 2>&1 + rm -f /etc/rc.d/rc1.d/K10webmin >/dev/null 2>&1 + rm -f /etc/rc.d/rc6.d/K10webmin >/dev/null 2>&1 + rmdir /etc/rc.d/rc2.d >/dev/null 2>&1 + rmdir /etc/rc.d/rc3.d >/dev/null 2>&1 + rmdir /etc/rc.d/rc5.d >/dev/null 2>&1 + rmdir /etc/rc.d/rc0.d >/dev/null 2>&1 + rmdir /etc/rc.d/rc1.d >/dev/null 2>&1 + rmdir /etc/rc.d/rc6.d >/dev/null 2>&1 + + mkdir /etc/systemd/system >/dev/null 2>&1 + cp -p webmin-systemd /etc/systemd/system/webmin.service >/dev/null 2>&1 + systemctl daemon-reload >/dev/null 2>&1 +else + mkdir -p /etc/sysconfig/daemons >/dev/null 2>&1 + cp -p webmin-daemon /etc/sysconfig/daemons/webmin >/dev/null 2>&1 + + cp -p webmin-init /etc/init.d/webmin >/dev/null 2>&1 + + mkdir -p /etc/rc.d/{rc0.d,rc1.d,rc2.d,rc3.d,rc5.d,rc6.d} >/dev/null 2>&1 + ln -s /etc/init.d/webmin /etc/rc.d/rc2.d/S99webmin >/dev/null 2>&1 + ln -s /etc/init.d/webmin /etc/rc.d/rc3.d/S99webmin >/dev/null 2>&1 + ln -s /etc/init.d/webmin /etc/rc.d/rc5.d/S99webmin >/dev/null 2>&1 + ln -s /etc/init.d/webmin /etc/rc.d/rc0.d/K10webmin >/dev/null 2>&1 + ln -s /etc/init.d/webmin /etc/rc.d/rc1.d/K10webmin >/dev/null 2>&1 + ln -s /etc/init.d/webmin /etc/rc.d/rc6.d/K10webmin >/dev/null 2>&1 +fi if [ "\$inetd" != "1" -a "\$startafter" = "1" ]; then /etc/webmin/stop >/dev/null 2>&1 /dev/null 2>&1 Date: Sat, 23 Apr 2022 00:34:27 +0300 Subject: [PATCH 21/52] Don't restart on failure --- webmin-systemd | 1 - 1 file changed, 1 deletion(-) diff --git a/webmin-systemd b/webmin-systemd index 4765c7508..9e9778a67 100755 --- a/webmin-systemd +++ b/webmin-systemd @@ -10,7 +10,6 @@ PIDFile=/var/webmin/miniserv.pid ExecStart=/etc/webmin/start-init ExecStop=/etc/webmin/stop-init KillMode=none -Restart=on-failure [Install] WantedBy=multi-user.target From 05ed0be5730672d2900b9490492265c1e42b6e5b Mon Sep 17 00:00:00 2001 From: Ilia Date: Sat, 23 Apr 2022 01:06:24 +0300 Subject: [PATCH 22/52] Fix `systemd` script generation for manual installs --- init/atboot.pl | 18 ++++++++++++++++-- webmin-systemd | 7 ++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/init/atboot.pl b/init/atboot.pl index d2734ba41..00595f548 100755 --- a/init/atboot.pl +++ b/init/atboot.pl @@ -117,8 +117,22 @@ elsif ($init_mode eq "win32") { $perl_path = &get_perl_path(); &enable_at_boot($product, $ucproduct, $perl_path." "."e_path("$root_directory/miniserv.pl")." "."e_path("$config_directory/miniserv.conf")); } -elsif ($init_mode eq "rc" || $init_mode eq "upstart" || - $init_mode eq "systemd") { +elsif ($init_mode eq "systemd") { + # Create systemd + &enable_at_boot( + $product, + "$ucproduct server daemon", + "$config_directory/start-init", + "$config_directory/stop-init", + undef, + { 'pidfile' => $var_directory."/miniserv.pid", + 'opts' => { + 'type' => 'forking', + 'killmode' => 'none' + }}, + ); + } +elsif ($init_mode eq "rc" || $init_mode eq "upstart") { # Create RC or upstart script &enable_at_boot($product, $ucproduct, "$config_directory/start", "$config_directory/stop", diff --git a/webmin-systemd b/webmin-systemd index 9e9778a67..b5cb870d9 100755 --- a/webmin-systemd +++ b/webmin-systemd @@ -1,14 +1,11 @@ [Unit] Description=Webmin server daemon -After=syslog.target -StartLimitIntervalSec=3 -StartLimitBurst=2 [Service] -Type=forking -PIDFile=/var/webmin/miniserv.pid ExecStart=/etc/webmin/start-init ExecStop=/etc/webmin/stop-init +PIDFile=/var/webmin/miniserv.pid +Type=forking KillMode=none [Install] From 9079d6121a13a402e895ac915dd95f88b6d62bc8 Mon Sep 17 00:00:00 2001 From: Ilia Date: Sat, 23 Apr 2022 01:14:19 +0300 Subject: [PATCH 23/52] Use recommended `/etc/systemd/system` by default --- init/init-lib.pl | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/init/init-lib.pl b/init/init-lib.pl index c22445bf6..4d7a31fe9 100755 --- a/init/init-lib.pl +++ b/init/init-lib.pl @@ -2400,12 +2400,17 @@ sub get_systemd_root { my ($name) = @_; if ($name) { - foreach my $p ("/etc/systemd/system", "/usr/lib/systemd/system", - "/lib/systemd/system") { + foreach my $p ( + "/etc/systemd/system", + "/usr/lib/systemd/system", + "/lib/systemd/system") { if (-r "$p/$name.service" || -r "$p/$name") { return $p; } + } } +if (-d "/etc/systemd/system") { + return "/etc/systemd/system"; } if (-d "/usr/lib/systemd/system") { return "/usr/lib/systemd/system"; From eeeae8a2f633694aa579a83e5547af26761ff82a Mon Sep 17 00:00:00 2001 From: Ilia Date: Sat, 23 Apr 2022 01:20:32 +0300 Subject: [PATCH 24/52] Fix indent --- init/init-lib.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init/init-lib.pl b/init/init-lib.pl index 4d7a31fe9..eb97693ca 100755 --- a/init/init-lib.pl +++ b/init/init-lib.pl @@ -2407,8 +2407,8 @@ if ($name) { if (-r "$p/$name.service" || -r "$p/$name") { return $p; } - } } + } if (-d "/etc/systemd/system") { return "/etc/systemd/system"; } From d3ad394bd81f1a568053c0a3a5a121e7439ff532 Mon Sep 17 00:00:00 2001 From: Ilia Date: Sat, 23 Apr 2022 02:03:09 +0300 Subject: [PATCH 25/52] Always update `systemd` script --- init/updateboot.pl | 21 +++++++++++++++++++++ setup.sh | 4 ++++ 2 files changed, 25 insertions(+) create mode 100755 init/updateboot.pl diff --git a/init/updateboot.pl b/init/updateboot.pl new file mode 100755 index 000000000..488bec6d3 --- /dev/null +++ b/init/updateboot.pl @@ -0,0 +1,21 @@ +#!/usr/bin/perl +# updateboot.pl +# Called by setup.sh to update boot script + +$no_acl_check++; +require './init-lib.pl'; +$product = $ARGV[0]; + +# Update boot script +if ($init_mode eq "systemd") { + my $systemd_root = &get_systemd_root($product); + if (-r "$systemd_root/webmin.service") { + unlink("$systemd_root/webmin.service"); + copy_source_dest("../webmin-systemd", "$systemd_root/webmin.service"); + } + elsif (-r "$systemd_root/webmin") { + unlink("$systemd_root/webmin"); + copy_source_dest("../webmin-systemd", "$systemd_root/webmin"); + } + system("systemctl --system daemon-reload >/dev/null 2>&1"); + }; diff --git a/setup.sh b/setup.sh index 180368810..bb1b987a8 100755 --- a/setup.sh +++ b/setup.sh @@ -658,6 +658,7 @@ echo "" # Re-generating supplementary rm -f $config_dir/stop $config_dir/start $config_dir/restart $config_dir/force-reload $config_dir/reload +# For systemd if command -v systemctl >/dev/null 2>&1; then systemctlcmd=`which systemctl` echo "Creating start and stop scripts (systemd).." @@ -678,6 +679,9 @@ if command -v systemctl >/dev/null 2>&1; then # Reload systemd echo "#!/bin/sh" >>$config_dir/reload echo "$config_dir/reload-init >/dev/null 2>&1" >>$config_dir/reload + + # Fix existing systemd webmin.service file to update start and stop commands + (cd "$wadir/init" ; WEBMIN_CONFIG=$config_dir WEBMIN_VAR=$var_dir "$wadir/init/updateboot.pl" "webmin") else echo "Creating start and stop init scripts (init.d for older systems).." # Start init.d From 6846bfdda4ae6cda3f3b33fc131bdfc2eaba0470 Mon Sep 17 00:00:00 2001 From: Ilia Date: Sat, 23 Apr 2022 02:17:25 +0300 Subject: [PATCH 26/52] Update boot properly --- init/updateboot.pl | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/init/updateboot.pl b/init/updateboot.pl index 488bec6d3..d4008521e 100755 --- a/init/updateboot.pl +++ b/init/updateboot.pl @@ -6,16 +6,21 @@ $no_acl_check++; require './init-lib.pl'; $product = $ARGV[0]; +$< == 0 || die "updateboot.pl must be run as root"; + # Update boot script -if ($init_mode eq "systemd") { - my $systemd_root = &get_systemd_root($product); - if (-r "$systemd_root/webmin.service") { - unlink("$systemd_root/webmin.service"); - copy_source_dest("../webmin-systemd", "$systemd_root/webmin.service"); - } - elsif (-r "$systemd_root/webmin") { - unlink("$systemd_root/webmin"); - copy_source_dest("../webmin-systemd", "$systemd_root/webmin"); - } - system("systemctl --system daemon-reload >/dev/null 2>&1"); - }; +if ($product) { + if ($init_mode eq "systemd") { + # Delete all possible service files + my $systemd_root = &get_systemd_root(); + foreach my $p ( + "/etc/systemd/system", + "/usr/lib/systemd/system", + "/lib/systemd/system") { + unlink("$p/$product.service"); + unlink("$p/$product"); + } + copy_source_dest("../webmin-systemd", "$systemd_root/$product.service"); + system("systemctl --system daemon-reload >/dev/null 2>&1"); + }; + } From dd1927b54c49de5c1de58d41fb43aa1b93b8da5e Mon Sep 17 00:00:00 2001 From: Ilia Date: Sat, 23 Apr 2022 02:18:16 +0300 Subject: [PATCH 27/52] Drop new file --- init/isboot.pl | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100755 init/isboot.pl diff --git a/init/isboot.pl b/init/isboot.pl deleted file mode 100755 index 28b03a0fd..000000000 --- a/init/isboot.pl +++ /dev/null @@ -1,12 +0,0 @@ -#!/usr/bin/perl -# isboot.pl -# Called by setup.sh to check if given service is enabled - -$no_acl_check++; -require './init-lib.pl'; -$product = $ARGV[0] || "webmin"; -# Is enabled and system supports systemd -if (&action_status($product) == 2 && - $init_mode eq "systemd") { - &enable_at_boot($product); - }; From 4b9895b33438b1c917540b1c9907f91523c4d6ff Mon Sep 17 00:00:00 2001 From: Ilia Date: Sat, 23 Apr 2022 02:20:55 +0300 Subject: [PATCH 28/52] Add sec check --- init/atboot.pl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/init/atboot.pl b/init/atboot.pl index 00595f548..9c0650ff5 100755 --- a/init/atboot.pl +++ b/init/atboot.pl @@ -7,6 +7,8 @@ require './init-lib.pl'; $product = $ARGV[0] || "webmin"; $ucproduct = ucfirst($product); +$< == 0 || die "updateboot.pl must be run as root"; + if ($init_mode eq "osx") { # Darwin System &enable_at_boot("webmin", "Webmin administration server", From ba321fcd7e85695ee16d42b698acd5430f59c09a Mon Sep 17 00:00:00 2001 From: Ilia Date: Sat, 23 Apr 2022 02:21:54 +0300 Subject: [PATCH 29/52] Remove `sysconfig/daemons` and don't clear `rc*.d` --- makerpm.pl | 9 --------- 1 file changed, 9 deletions(-) diff --git a/makerpm.pl b/makerpm.pl index 2df6321c9..e7f21c19f 100755 --- a/makerpm.pl +++ b/makerpm.pl @@ -244,20 +244,11 @@ if [ -x "\$(command -v systemctl)" >/dev/null 2>&1 ] && [ -d "/etc/systemd" ]; t rm -f /etc/rc.d/rc0.d/K10webmin >/dev/null 2>&1 rm -f /etc/rc.d/rc1.d/K10webmin >/dev/null 2>&1 rm -f /etc/rc.d/rc6.d/K10webmin >/dev/null 2>&1 - rmdir /etc/rc.d/rc2.d >/dev/null 2>&1 - rmdir /etc/rc.d/rc3.d >/dev/null 2>&1 - rmdir /etc/rc.d/rc5.d >/dev/null 2>&1 - rmdir /etc/rc.d/rc0.d >/dev/null 2>&1 - rmdir /etc/rc.d/rc1.d >/dev/null 2>&1 - rmdir /etc/rc.d/rc6.d >/dev/null 2>&1 mkdir /etc/systemd/system >/dev/null 2>&1 cp -p webmin-systemd /etc/systemd/system/webmin.service >/dev/null 2>&1 systemctl daemon-reload >/dev/null 2>&1 else - mkdir -p /etc/sysconfig/daemons >/dev/null 2>&1 - cp -p webmin-daemon /etc/sysconfig/daemons/webmin >/dev/null 2>&1 - cp -p webmin-init /etc/init.d/webmin >/dev/null 2>&1 mkdir -p /etc/rc.d/{rc0.d,rc1.d,rc2.d,rc3.d,rc5.d,rc6.d} >/dev/null 2>&1 From da3b4c62967ef269ed04cea6960e91bf3d132a10 Mon Sep 17 00:00:00 2001 From: Ilia Date: Sat, 23 Apr 2022 02:45:04 +0300 Subject: [PATCH 30/52] Clear `systemd` and do uninstall silently --- init/uninstall.pl | 4 ++++ setup.sh | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/init/uninstall.pl b/init/uninstall.pl index b29c9310f..2ab57d3f7 100755 --- a/init/uninstall.pl +++ b/init/uninstall.pl @@ -59,6 +59,10 @@ elsif ($init_mode eq "win32") { # Delete win32 service &delete_win32_service($product); } +elsif ($init_mode eq "systemd") { + # Delete systemd service + &delete_systemd_service($product); + } } 1; diff --git a/setup.sh b/setup.sh index bb1b987a8..3408f7fce 100755 --- a/setup.sh +++ b/setup.sh @@ -829,7 +829,7 @@ printf "\n" if [ "\$answer" = "y" ]; then $config_dir/stop echo "Running uninstall scripts .." - (cd "$wadir" ; WEBMIN_CONFIG=$config_dir WEBMIN_VAR=$var_dir LANG= "$wadir/run-uninstalls.pl") + (cd "$wadir" ; WEBMIN_CONFIG=$config_dir WEBMIN_VAR=$var_dir LANG= "$wadir/run-uninstalls.pl") >/dev/null 2>&1 Date: Sat, 23 Apr 2022 02:52:34 +0300 Subject: [PATCH 31/52] Add After --- webmin-systemd | 1 + 1 file changed, 1 insertion(+) diff --git a/webmin-systemd b/webmin-systemd index b5cb870d9..08e595600 100755 --- a/webmin-systemd +++ b/webmin-systemd @@ -1,5 +1,6 @@ [Unit] Description=Webmin server daemon +After=syslog.target [Service] ExecStart=/etc/webmin/start-init From d8cd3c8ac8d976ac40dfdbe9c391a1e6f570b0a0 Mon Sep 17 00:00:00 2001 From: Ilia Date: Sat, 23 Apr 2022 03:36:38 +0300 Subject: [PATCH 32/52] Just remove commented out earlier --- makedebian.pl | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/makedebian.pl b/makedebian.pl index 80508ee8a..b23afeb1e 100755 --- a/makedebian.pl +++ b/makedebian.pl @@ -31,7 +31,6 @@ $copyright_file = "$doc_dir/copyright"; $usr_dir = "$tmp_dir/usr/share/$baseproduct"; $bin_dir = "$tmp_dir/usr/bin"; $pam_dir = "$tmp_dir/etc/pam.d"; -# $init_dir = "$tmp_dir/etc/init.d"; $pam_file = "$pam_dir/$baseproduct"; $preinstall_file = "$debian_dir/preinst"; $postinstall_file = "$debian_dir/postinst"; @@ -61,7 +60,6 @@ mkdir($tmp_dir, 0755); chmod(0755, $tmp_dir); mkdir($debian_dir, 0755); system("mkdir -p $pam_dir"); -# system("mkdir -p $init_dir"); system("mkdir -p $usr_dir"); system("mkdir -p $doc_dir"); system("mkdir -p $bin_dir"); @@ -82,9 +80,7 @@ if ($product eq "webmin") { system("cd $usr_dir && rm -rf acl/Authen-SolarisRBAC-0.1*"); } -# Create init script -# system("mv $usr_dir/$baseproduct-init $init_dir/$baseproduct"); -# chmod(0755, "$init_dir/$baseproduct"); +# Set install type system("echo deb >$usr_dir/install-type"); system("echo $product >$usr_dir/deb-name"); system("cd $usr_dir && chmod -R og-w ."); From c1d660a9967ce0a94c640917d8b397015cbc94da Mon Sep 17 00:00:00 2001 From: Ilia Date: Sat, 23 Apr 2022 03:56:18 +0300 Subject: [PATCH 33/52] This will be cleared by uninstall --- makerpm.pl | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/makerpm.pl b/makerpm.pl index e7f21c19f..62ed34e4f 100755 --- a/makerpm.pl +++ b/makerpm.pl @@ -321,27 +321,6 @@ if [ "\$1" = 0 ]; then rm -rf /etc/webmin.rpmsave mv /etc/webmin /etc/webmin.rpmsave rm -rf /var/webmin - - rm -f /etc/sysconfig/daemons/webmin >/dev/null 2>&1 - rmdir /etc/sysconfig/daemons >/dev/null 2>&1 - rm -f /etc/init.d/webmin >/dev/null 2>&1 - rm -f /etc/rc.d/rc2.d/S99webmin >/dev/null 2>&1 - rm -f /etc/rc.d/rc3.d/S99webmin >/dev/null 2>&1 - rm -f /etc/rc.d/rc5.d/S99webmin >/dev/null 2>&1 - rm -f /etc/rc.d/rc0.d/K10webmin >/dev/null 2>&1 - rm -f /etc/rc.d/rc1.d/K10webmin >/dev/null 2>&1 - rm -f /etc/rc.d/rc6.d/K10webmin >/dev/null 2>&1 - rmdir /etc/rc.d/rc2.d >/dev/null 2>&1 - rmdir /etc/rc.d/rc3.d >/dev/null 2>&1 - rmdir /etc/rc.d/rc5.d >/dev/null 2>&1 - rmdir /etc/rc.d/rc0.d >/dev/null 2>&1 - rmdir /etc/rc.d/rc1.d >/dev/null 2>&1 - rmdir /etc/rc.d/rc6.d >/dev/null 2>&1 - - rm -f /etc/systemd/system/webmin.service >/dev/null 2>&1 - if [ -x "\$(command -v systemctl)" >/dev/null 2>&1 ]; then - systemctl daemon-reload >/dev/null 2>&1 - fi fi fi /bin/true From 3696c8ac74942a8ce99bbc8723fd403d1e1cc95d Mon Sep 17 00:00:00 2001 From: Ilia Date: Sat, 23 Apr 2022 03:56:41 +0300 Subject: [PATCH 34/52] We must clear the mess for `systemd` --- makerpm.pl | 43 ++++++++++++++++++------------------------- 1 file changed, 18 insertions(+), 25 deletions(-) diff --git a/makerpm.pl b/makerpm.pl index 62ed34e4f..f3d0458df 100755 --- a/makerpm.pl +++ b/makerpm.pl @@ -220,6 +220,7 @@ fi host=`hostname` ssl=1 atboot=1 +makeboot=1 nochown=1 autothird=1 noperlpath=1 @@ -228,36 +229,28 @@ nostart=1 if [ "\$tempdir" = "" ]; then tempdir=/tmp/.webmin fi -export config_dir var_dir perl autoos port login crypt host ssl nochown autothird noperlpath nouninstall nostart allow atboot +export config_dir var_dir perl autoos port login crypt host ssl nochown autothird noperlpath nouninstall nostart allow atboot makeboot ./setup.sh >\$tempdir/webmin-setup.out 2>&1 chmod 600 \$tempdir/webmin-setup.out rm -f /var/lock/subsys/webmin cd /usr/libexec/webmin +# Fix to just always clear old mess for systemd if [ -x "\$(command -v systemctl)" >/dev/null 2>&1 ] && [ -d "/etc/systemd" ]; then - - rm -f /etc/sysconfig/daemons/webmin >/dev/null 2>&1 - rmdir /etc/sysconfig/daemons >/dev/null 2>&1 - rm -f /etc/init.d/webmin >/dev/null 2>&1 - rm -f /etc/rc.d/rc2.d/S99webmin >/dev/null 2>&1 - rm -f /etc/rc.d/rc3.d/S99webmin >/dev/null 2>&1 - rm -f /etc/rc.d/rc5.d/S99webmin >/dev/null 2>&1 - rm -f /etc/rc.d/rc0.d/K10webmin >/dev/null 2>&1 - rm -f /etc/rc.d/rc1.d/K10webmin >/dev/null 2>&1 - rm -f /etc/rc.d/rc6.d/K10webmin >/dev/null 2>&1 - - mkdir /etc/systemd/system >/dev/null 2>&1 - cp -p webmin-systemd /etc/systemd/system/webmin.service >/dev/null 2>&1 - systemctl daemon-reload >/dev/null 2>&1 -else - cp -p webmin-init /etc/init.d/webmin >/dev/null 2>&1 - - mkdir -p /etc/rc.d/{rc0.d,rc1.d,rc2.d,rc3.d,rc5.d,rc6.d} >/dev/null 2>&1 - ln -s /etc/init.d/webmin /etc/rc.d/rc2.d/S99webmin >/dev/null 2>&1 - ln -s /etc/init.d/webmin /etc/rc.d/rc3.d/S99webmin >/dev/null 2>&1 - ln -s /etc/init.d/webmin /etc/rc.d/rc5.d/S99webmin >/dev/null 2>&1 - ln -s /etc/init.d/webmin /etc/rc.d/rc0.d/K10webmin >/dev/null 2>&1 - ln -s /etc/init.d/webmin /etc/rc.d/rc1.d/K10webmin >/dev/null 2>&1 - ln -s /etc/init.d/webmin /etc/rc.d/rc6.d/K10webmin >/dev/null 2>&1 + rm -f /etc/sysconfig/daemons/webmin >/dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 Date: Sat, 23 Apr 2022 15:14:01 +0300 Subject: [PATCH 35/52] Remove stray PAM on uninstall --- makedebian.pl | 1 + 1 file changed, 1 insertion(+) diff --git a/makedebian.pl b/makedebian.pl index b23afeb1e..5acce982d 100755 --- a/makedebian.pl +++ b/makedebian.pl @@ -395,6 +395,7 @@ if [ "\$1" != "upgrade" -a "\$1" != "abort-upgrade" ]; then # Package is being removed, and no new version of webmin # has taken it's place. Delete the config files rm -rf /etc/$baseproduct /var/$baseproduct + rm -f /etc/pam.d/$baseproduct fi fi EOF From 468945a74dbf16b2902f3f155b8b4a8c4bfa11df Mon Sep 17 00:00:00 2001 From: Ilia Date: Sat, 23 Apr 2022 15:48:56 +0300 Subject: [PATCH 36/52] Don't assume default --- init/updateboot.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init/updateboot.pl b/init/updateboot.pl index d4008521e..c235bb69b 100755 --- a/init/updateboot.pl +++ b/init/updateboot.pl @@ -21,6 +21,6 @@ if ($product) { unlink("$p/$product"); } copy_source_dest("../webmin-systemd", "$systemd_root/$product.service"); - system("systemctl --system daemon-reload >/dev/null 2>&1"); + system("systemctl daemon-reload >/dev/null 2>&1"); }; } From ee8e260664e6b47643cfea41d57c9f6cd5bff157 Mon Sep 17 00:00:00 2001 From: Ilia Date: Sat, 23 Apr 2022 16:44:52 +0300 Subject: [PATCH 37/52] Fail proof way of stopping Webmin server --- setup.sh | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/setup.sh b/setup.sh index 3408f7fce..373daea44 100755 --- a/setup.sh +++ b/setup.sh @@ -624,19 +624,25 @@ else fi # Stop main echo "#!/bin/sh" >>$config_dir/stop-init -echo "echo Stopping Webmin server in $wadir" >>$config_dir/stop-init +echo "if [ \"\$1\" = \"--kill\" ]; then" >>$config_dir/stop-init +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 "pidfile=\`grep \"^pidfile=\" $config_dir/miniserv.conf | sed -e 's/pidfile=//g'\`" >>$config_dir/stop-init -echo "pid=\`cat \$pidfile\`" >>$config_dir/stop-init +echo "pid=\`cat \$pidfile\` 2>/dev/null" >>$config_dir/stop-init echo "if [ \"\$pid\" != \"\" ]; then" >>$config_dir/stop-init echo " kill \$pid || exit 1" >>$config_dir/stop-init echo " touch $var_dir/stop-flag" >>$config_dir/stop-init echo " if [ \"\$1\" = \"--kill\" ]; then" >>$config_dir/stop-init -echo " sleep 2" >>$config_dir/stop-init -echo " (kill -9 -- -\$pid || kill -9 \$pid) 2>/dev/null" >>$config_dir/stop-init +echo " sleep 1" >>$config_dir/stop-init +echo " ((ps axf | grep \"webmin\/miniserv\.pl\" | awk '{print \"kill -9 -- -\" \$1}' | bash) || kill -9 -- -\$pid || kill -9 \$pid) 2>/dev/null" >>$config_dir/stop-init echo " fi" >>$config_dir/stop-init echo " exit 0" >>$config_dir/stop-init echo "else" >>$config_dir/stop-init -echo " exit 1" >>$config_dir/stop-init +echo " if [ \"\$1\" = \"--kill\" ]; then" >>$config_dir/stop-init +echo " (ps axf | grep \"webmin\/miniserv\.pl\" | awk '{print \"kill -9 -- -\" \$1}' | bash) 2>/dev/null" >>$config_dir/stop-init +echo " fi" >>$config_dir/stop-init echo "fi" >>$config_dir/stop-init # Restart main echo "#!/bin/sh" >>$config_dir/restart-init From 4d3dc79a43da567c9974e3ef6e3f112a66ef76a0 Mon Sep 17 00:00:00 2001 From: Ilia Date: Sat, 23 Apr 2022 17:28:22 +0300 Subject: [PATCH 38/52] Be explicit when Webmin cannot be restarted in those rare cases --- makedebian.pl | 11 +++++++---- makerpm.pl | 6 ++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/makedebian.pl b/makedebian.pl index 5acce982d..4528c3235 100755 --- a/makedebian.pl +++ b/makedebian.pl @@ -325,8 +325,11 @@ fi rm -f /var/lock/subsys/$baseproduct if [ "$inetd" != "1" ]; then - /etc/$baseproduct/stop - /etc/$baseproduct/start + /etc/$baseproduct/stop >/dev/null 2>&1 /dev/null 2>&1 /etc/$baseproduct/uninstall.sh </dev/null 2>&1 if [ "\$?" = 0 ]; then - # Package is being removed, and no new version of webmin - # has taken it's place. Delete the config files + # Package is being removed, and no new version of Webmin + # has taken its place. Delete the config files rm -rf /etc/$baseproduct /var/$baseproduct rm -f /etc/pam.d/$baseproduct fi diff --git a/makerpm.pl b/makerpm.pl index f3d0458df..308baa264 100755 --- a/makerpm.pl +++ b/makerpm.pl @@ -255,6 +255,9 @@ fi if [ "\$inetd" != "1" -a "\$startafter" = "1" ]; then /etc/webmin/stop >/dev/null 2>&1 /dev/null 2>&1 /etc/webmin/uninstall.sh </dev/null 2>&1 /dev/null 2>&1 Date: Sat, 23 Apr 2022 21:01:58 +0300 Subject: [PATCH 39/52] Fix links creation --- setup.sh | 50 ++++++++++++++++++++++++++------------------------ 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/setup.sh b/setup.sh index 373daea44..a33b4885c 100755 --- a/setup.sh +++ b/setup.sh @@ -611,7 +611,6 @@ echo "echo Starting Webmin server in $wadir" >>$config_dir/start-init echo "trap '' 1" >>$config_dir/start-init echo "LANG=" >>$config_dir/start-init echo "export LANG" >>$config_dir/start-init -echo "#PERLIO=:raw" >>$config_dir/start-init echo "unset PERLIO" >>$config_dir/start-init echo "export PERLIO" >>$config_dir/start-init echo "PERLLIB=$PERLLIB" >>$config_dir/start-init @@ -663,9 +662,30 @@ echo "..done" echo "" # Re-generating supplementary -rm -f $config_dir/stop $config_dir/start $config_dir/restart $config_dir/force-reload $config_dir/reload -# For systemd -if command -v systemctl >/dev/null 2>&1; then + +# Clear existing +csupp () { + rm -f $config_dir/stop $config_dir/start $config_dir/restart $config_dir/force-reload $config_dir/reload +} +csupp + +# Creating symlinks +echo "Creating start and stop init symlinks to scripts .." +# Start init.d +ln -s $config_dir/start-init $config_dir/start >/dev/null 2>&1 +# Stop init.d +ln -s $config_dir/stop-init $config_dir/stop >/dev/null 2>&1 +# Restart init.d +ln -s $config_dir/restart-init $config_dir/restart >/dev/null 2>&1 +# Force reload init.d +ln -s $config_dir/force-reload-init $config_dir/force-reload >/dev/null 2>&1 +# Reload init.d +ln -s $config_dir/reload-init $config_dir/reload >/dev/null 2>&1 + +# For systemd create different start/stop scripts +if [ -x "$(command -v systemctl)" >/dev/null 2>&1 ]; then + csupp + systemctlcmd=`which systemctl` echo "Creating start and stop scripts (systemd).." # Start systemd @@ -688,27 +708,9 @@ if command -v systemctl >/dev/null 2>&1; then # Fix existing systemd webmin.service file to update start and stop commands (cd "$wadir/init" ; WEBMIN_CONFIG=$config_dir WEBMIN_VAR=$var_dir "$wadir/init/updateboot.pl" "webmin") -else - echo "Creating start and stop init scripts (init.d for older systems).." - # Start init.d - echo "#!/bin/sh" >>$config_dir/start - echo "/etc/init.d/webmin start" >>$config_dir/start - # Stop init.d - echo "#!/bin/sh" >>$config_dir/stop - echo "/etc/init.d/webmin stop" >>$config_dir/stop - # Restart init.d - echo "#!/bin/sh" >>$config_dir/restart - echo "/etc/init.d/webmin restart" >>$config_dir/restart - # Force reload init.d - echo "#!/bin/sh" >>$config_dir/force-reload - echo "$config_dir/stop-init --kill >/dev/null 2>&1" >>$config_dir/force-reload - echo "/etc/init.d/webmin stop" >>$config_dir/force-reload - echo "/etc/init.d/webmin start" >>$config_dir/force-reload - # Reload init.d - echo "#!/bin/sh" >>$config_dir/reload - echo "/etc/init.d/webmin reload >/dev/null 2>&1" >>$config_dir/reload + + chmod 755 $config_dir/stop $config_dir/start $config_dir/restart $config_dir/force-reload $config_dir/reload fi -chmod 755 $config_dir/stop $config_dir/start $config_dir/restart $config_dir/force-reload $config_dir/reload if [ "$upgrading" = 1 -a "$inetd" != "1" ]; then # Stop old version, with updated stop script From 0dea6e07465ad3aaa031fa867792d58da88fe806 Mon Sep 17 00:00:00 2001 From: Ilia Date: Sat, 23 Apr 2022 21:03:03 +0300 Subject: [PATCH 40/52] Fix to only test the command presence --- makerpm.pl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/makerpm.pl b/makerpm.pl index 308baa264..730722735 100755 --- a/makerpm.pl +++ b/makerpm.pl @@ -234,8 +234,8 @@ export config_dir var_dir perl autoos port login crypt host ssl nochown autothir chmod 600 \$tempdir/webmin-setup.out rm -f /var/lock/subsys/webmin cd /usr/libexec/webmin -# Fix to just always clear old mess for systemd -if [ -x "\$(command -v systemctl)" >/dev/null 2>&1 ] && [ -d "/etc/systemd" ]; then +# Fix to always clear old mess for systemd systems +if [ -x "\$(command -v systemctl)" >/dev/null 2>&1 ]; then rm -f /etc/sysconfig/daemons/webmin >/dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 Date: Sat, 23 Apr 2022 21:58:22 +0300 Subject: [PATCH 41/52] Fix `setup.pl` to accommodate latest changes with `setup.sh` --- setup.pl | 133 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 123 insertions(+), 10 deletions(-) diff --git a/setup.pl b/setup.pl index a267034b9..e73327d9a 100755 --- a/setup.pl +++ b/setup.pl @@ -516,7 +516,11 @@ if ($os_type eq "windows") { close(STOP); } else { - open(START, ">$config_directory/start"); + + # Re-generating main + + # Start main + open(START, ">$config_directory/start-init"); print START "#!/bin/sh\n"; print START "echo Starting Webmin server in $wadir\n"; print START "trap '' 1\n"; @@ -533,23 +537,132 @@ else { print START "exec '$wadir/miniserv.pl' $config_directory/miniserv.conf\n"; } close(START); - $start_cmd = "$config_directory/start"; + $start_cmd = "$config_directory/start-init"; - open(STOP, ">$config_directory/stop"); + # Stop main + open(STOP, ">$config_directory/stop-init"); print STOP "#!/bin/sh\n"; - print STOP "echo Stopping Webmin server in $wadir\n"; + print STOP "if [ \"\$1\" = \"--kill\" ]; then\n"; + print STOP " echo Force stopping Webmin server in $wadir\n"; + print STOP "else\n"; + print STOP " echo Stopping Webmin server in $wadir\n"; + print STOP "fi\n"; print STOP "pidfile=\`grep \"^pidfile=\" $config_directory/miniserv.conf | sed -e 's/pidfile=//g'\`\n"; - print STOP "kill \`cat \$pidfile\`\n"; + print STOP "pid=\`cat \$pidfile\` 2>/dev/null\n"; + print STOP "if [ \"\$pid\" != \"\" ]; then\n"; + print STOP " kill \$pid || exit 1\n"; + print STOP " touch $var_dir/stop-flag\n"; + print STOP " if [ \"\$1\" = \"--kill\" ]; then\n"; + print STOP " sleep 1\n"; + print STOP " ((ps axf | grep \"webmin\\\/miniserv\\.pl\" | awk '{print \"kill -9 -- -\" \$1}' | bash) || kill -9 -- -\$pid || kill -9 \$pid) 2>/dev/null\n"; + print STOP " fi\n"; + print STOP " exit 0\n"; + print STOP "else\n"; + print STOP " if [ \"\$1\" = \"--kill\" ]; then\n"; + print STOP " (ps axf | grep \"webmin\\\/miniserv\\.pl\" | awk '{print \"kill -9 -- -\" \$1}' | bash) 2>/dev/null\n"; + print STOP " fi\n"; + print STOP "fi\n"; close(STOP); - open(RESTART, ">$config_directory/restart"); + # Restart main + open(RESTART, ">$config_directory/restart-init"); print RESTART "#!/bin/sh\n"; - print RESTART "$config_directory/stop && $config_directory/start\n"; + print RESTART "$config_directory/stop-init\n"; + print RESTART "$config_directory/start-init\n"; close(RESTART); + + # Force reload main + open(FRELOAD, ">$config_directory/force-reload-init"); + print FRELOAD "#!/bin/sh\n"; + print FRELOAD "$config_directory/stop-init --kill\n"; + print FRELOAD "$config_directory/start-init\n"; + close(FRELOAD); - chmod(0755, "$config_directory/start", "$config_directory/stop", - "$config_directory/restart"); + # Reload main + open(RELOAD, ">$config_directory/reload-init"); + print RELOAD "#!/bin/sh\n"; + print RELOAD "echo Reloading Webmin server in $wadir\n"; + print RELOAD "pidfile=\`grep \"^pidfile=\" $config_directory/miniserv.conf | sed -e 's/pidfile=//g'\`\n"; + print RELOAD "kill -USR1 \`cat \$pidfile\`\n"; + close(RELOAD); + + chmod(0755, "$config_directory/start-init"); + chmod(0755, "$config_directory/stop-init"); + chmod(0755, "$config_directory/restart-init"); + chmod(0755, "$config_directory/force-reload-init"); + chmod(0755, "$config_directory/reload-init"); + + # Re-generating supplementary + + # Clear existing + my $csupp = sub { + unlink("$config_directory/start"); + unlink("$config_directory/stop"); + unlink("$config_directory/restart"); + unlink("$config_directory/force-reload"); + unlink("$config_directory/reload"); + }; + &$csupp(); + + # Create symlinks + # Start init.d + symlink("$config_directory/start-init", "$config_directory/start"); + # Stop init.d + symlink("$config_directory/stop-init", "$config_directory/stop"); + # Restart init.d + symlink("$config_directory/restart-init", "$config_directory/restart"); + # Force reload init.d + symlink("$config_directory/force-reload-init", "$config_directory/force-reload"); + # Reload init.d + symlink("$config_directory/reload-init", "$config_directory/reload"); + + # For systemd + my $systemctlcmd = `sh -c 'command -v systemctl'`; + if ($systemctlcmd) { + $systemctlcmd =~ s/\s+$//; + + # Clear existing + &$csupp(); + + # Start systemd + open(STARTD, ">$config_directory/start"); + print STARTD "$systemctlcmd start webmin\n"; + close(STARTD); + + # Stop systemd + open(STOPD, ">$config_directory/stop"); + print STOPD "$systemctlcmd stop webmin\n"; + close(STOPD); + + # Restart systemd + open(RESTARTD, ">$config_directory/restart"); + print RESTARTD "$systemctlcmd restart webmin\n"; + close(RESTARTD); + + # Force reload systemd + open(FRELOADD, ">$config_directory/force-reload"); + print FRELOADD "$config_directory/stop-init --kill >/dev/null 2>&1\n"; + print FRELOADD "$systemctlcmd stop webmin\n"; + print FRELOADD "$systemctlcmd start webmin\n"; + close(FRELOADD); + + # Reload systemd + open(RELOADD, ">$config_directory/reload"); + print RELOADD "$config_directory/reload-init >/dev/null 2>&1\n"; + close(RELOADD); + + chmod(0755, "$config_directory/start"); + chmod(0755, "$config_directory/stop"); + chmod(0755, "$config_directory/restart"); + chmod(0755, "$config_directory/force-reload"); + chmod(0755, "$config_directory/reload"); + + # Fix existing systemd webmin.service file to update start and stop commands + my $perl = &get_perl_path(); + chdir("$wadir/init"); + system("$perl "."e_path("$wadir/init/updateboot.pl")." webmin"); } +} print "..done\n"; print "\n"; @@ -642,7 +755,7 @@ printf "\n" if [ "\$answer" = "y" ]; then $config_directory/stop echo "Running uninstall scripts .." - (cd "$wadir" ; WEBMIN_CONFIG=$config_directory WEBMIN_VAR=$var_dir LANG= "$wadir/run-uninstalls.pl") + (cd "$wadir" ; WEBMIN_CONFIG=$config_directory WEBMIN_VAR=$var_dir LANG= "$wadir/run-uninstalls.pl") >/dev/null 2>&1 Date: Sat, 23 Apr 2022 23:50:00 +0300 Subject: [PATCH 42/52] Don't do cleaning, it will happen by the package manager --- makerpm.pl | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/makerpm.pl b/makerpm.pl index 730722735..d7610ee21 100755 --- a/makerpm.pl +++ b/makerpm.pl @@ -234,24 +234,6 @@ export config_dir var_dir perl autoos port login crypt host ssl nochown autothir chmod 600 \$tempdir/webmin-setup.out rm -f /var/lock/subsys/webmin cd /usr/libexec/webmin -# Fix to always clear old mess for systemd systems -if [ -x "\$(command -v systemctl)" >/dev/null 2>&1 ]; then - rm -f /etc/sysconfig/daemons/webmin >/dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 Date: Sat, 23 Apr 2022 23:51:49 +0300 Subject: [PATCH 43/52] Fix type - WARN instead of ERROR --- makedebian.pl | 2 +- makerpm.pl | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/makedebian.pl b/makedebian.pl index 4528c3235..ddcfba80c 100755 --- a/makedebian.pl +++ b/makedebian.pl @@ -328,7 +328,7 @@ if [ "$inetd" != "1" ]; then /etc/$baseproduct/stop >/dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 Date: Sun, 24 Apr 2022 11:21:13 +0300 Subject: [PATCH 44/52] This is `atboot.pl` not `updateboot.pl` --- init/atboot.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/init/atboot.pl b/init/atboot.pl index 9c0650ff5..843a5cc39 100755 --- a/init/atboot.pl +++ b/init/atboot.pl @@ -7,7 +7,7 @@ require './init-lib.pl'; $product = $ARGV[0] || "webmin"; $ucproduct = ucfirst($product); -$< == 0 || die "updateboot.pl must be run as root"; +$< == 0 || die "atboot.pl must be run as root"; if ($init_mode eq "osx") { # Darwin System From 1209e275318f8c3132d67179b32e1b0e37f825ca Mon Sep 17 00:00:00 2001 From: Ilia Date: Sun, 24 Apr 2022 11:39:22 +0300 Subject: [PATCH 45/52] Remove old code (sync with master) --- makedebian.pl | 17 ----------------- makerpm.pl | 17 ----------------- 2 files changed, 34 deletions(-) diff --git a/makedebian.pl b/makedebian.pl index ddcfba80c..1adf651fa 100755 --- a/makedebian.pl +++ b/makedebian.pl @@ -260,23 +260,6 @@ system("chmod 755 $preinstall_file"); open(SCRIPT, ">$postinstall_file"); print SCRIPT </etc/webmin/stop 2>/dev/null <<'EOD' -#!/bin/sh -pidfile=`grep "^pidfile=" /etc/webmin/miniserv.conf | sed -e 's/pidfile=//g'` -pid=`cat \$pidfile` -if [ "\$pid" != "" ]; then - kill \$pid || exit 1 - exit 0 -else - exit 1 -fi -EOD -fi - inetd=`grep "^inetd=" /etc/$baseproduct/miniserv.conf 2>/dev/null | sed -e 's/inetd=//g'` if [ "\$1" = "upgrade" -a "\$1" != "abort-upgrade" ]; then # Upgrading the package, so stop the old Webmin properly diff --git a/makerpm.pl b/makerpm.pl index cb9f938e8..bf8802104 100755 --- a/makerpm.pl +++ b/makerpm.pl @@ -171,23 +171,6 @@ fi %post inetd=`grep "^inetd=" /etc/webmin/miniserv.conf 2>/dev/null | sed -e 's/inetd=//g'` startafter=0 - -# Fix old versions of Webmin that might kill the UI -# process on upgrade, unless it's already fixed version -if [ -d /etc/webmin ] && [ ! -f "/etc/webmin/stop-init" ]; then - cat >/etc/webmin/stop 2>/dev/null <<'EOD' -#!/bin/sh -pidfile=`grep "^pidfile=" /etc/webmin/miniserv.conf | sed -e 's/pidfile=//g'` -pid=`cat \$pidfile` -if [ "\$pid" != "" ]; then - kill \$pid || exit 1 - exit 0 -else - exit 1 -fi -EOD -fi - if [ "\$1" != 1 ]; then # Upgrading the RPM, so stop the old Webmin properly if [ "\$inetd" != "1" ]; then From 08d7aae99ccce7ad89df925f2da44aa3464e991c Mon Sep 17 00:00:00 2001 From: Ilia Date: Sun, 24 Apr 2022 11:41:26 +0300 Subject: [PATCH 46/52] Fix new line --- makerpm.pl | 1 + 1 file changed, 1 insertion(+) diff --git a/makerpm.pl b/makerpm.pl index bf8802104..ead2e60e0 100755 --- a/makerpm.pl +++ b/makerpm.pl @@ -171,6 +171,7 @@ fi %post inetd=`grep "^inetd=" /etc/webmin/miniserv.conf 2>/dev/null | sed -e 's/inetd=//g'` startafter=0 + if [ "\$1" != 1 ]; then # Upgrading the RPM, so stop the old Webmin properly if [ "\$inetd" != "1" ]; then From c026a53cf5c4a078be67847dc9185f18078ff408 Mon Sep 17 00:00:00 2001 From: Ilia Date: Sun, 24 Apr 2022 12:48:32 +0300 Subject: [PATCH 47/52] Add missing done --- setup.sh | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/setup.sh b/setup.sh index a33b4885c..f518309c3 100755 --- a/setup.sh +++ b/setup.sh @@ -669,8 +669,6 @@ csupp () { } csupp -# Creating symlinks -echo "Creating start and stop init symlinks to scripts .." # Start init.d ln -s $config_dir/start-init $config_dir/start >/dev/null 2>&1 # Stop init.d @@ -710,7 +708,12 @@ if [ -x "$(command -v systemctl)" >/dev/null 2>&1 ]; then (cd "$wadir/init" ; WEBMIN_CONFIG=$config_dir WEBMIN_VAR=$var_dir "$wadir/init/updateboot.pl" "webmin") chmod 755 $config_dir/stop $config_dir/start $config_dir/restart $config_dir/force-reload $config_dir/reload +else + # Creating symlinks + echo "Creating start and stop init symlinks to scripts .." fi +echo "..done" +echo "" if [ "$upgrading" = 1 -a "$inetd" != "1" ]; then # Stop old version, with updated stop script From 14eacee616591f27eb694a4d77c0747735508f1b Mon Sep 17 00:00:00 2001 From: Ilia Date: Sun, 24 Apr 2022 17:42:33 +0300 Subject: [PATCH 48/52] Make warning message look better on Debian --- makedebian.pl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makedebian.pl b/makedebian.pl index 1adf651fa..b9109a595 100755 --- a/makedebian.pl +++ b/makedebian.pl @@ -311,7 +311,7 @@ if [ "$inetd" != "1" ]; then /etc/$baseproduct/stop >/dev/null 2>&1 /dev/null 2>&1 Date: Sun, 24 Apr 2022 17:46:53 +0300 Subject: [PATCH 49/52] More warning messages updates --- makedebian.pl | 2 +- makerpm.pl | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/makedebian.pl b/makedebian.pl index b9109a595..674138462 100755 --- a/makedebian.pl +++ b/makedebian.pl @@ -311,7 +311,7 @@ if [ "$inetd" != "1" ]; then /etc/$baseproduct/stop >/dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 Date: Mon, 25 Apr 2022 13:46:31 +0300 Subject: [PATCH 50/52] Fix command presence test https://github.com/webmin/webmin/pull/1628#discussion_r857203773 --- setup.pl | 25 +++++++++++++------------ setup.sh | 11 ++++------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/setup.pl b/setup.pl index e73327d9a..f3da5c415 100755 --- a/setup.pl +++ b/setup.pl @@ -595,14 +595,11 @@ else { # Re-generating supplementary # Clear existing - my $csupp = sub { - unlink("$config_directory/start"); - unlink("$config_directory/stop"); - unlink("$config_directory/restart"); - unlink("$config_directory/force-reload"); - unlink("$config_directory/reload"); - }; - &$csupp(); + unlink("$config_directory/start"); + unlink("$config_directory/stop"); + unlink("$config_directory/restart"); + unlink("$config_directory/force-reload"); + unlink("$config_directory/reload"); # Create symlinks # Start init.d @@ -617,12 +614,16 @@ else { symlink("$config_directory/reload-init", "$config_directory/reload"); # For systemd - my $systemctlcmd = `sh -c 'command -v systemctl'`; - if ($systemctlcmd) { - $systemctlcmd =~ s/\s+$//; + my $systemctlcmd = `which systemctl`; + $systemctlcmd =~ s/\s+$//; + if (-x $systemctlcmd) { # Clear existing - &$csupp(); + unlink("$config_directory/start"); + unlink("$config_directory/stop"); + unlink("$config_directory/restart"); + unlink("$config_directory/force-reload"); + unlink("$config_directory/reload"); # Start systemd open(STARTD, ">$config_directory/start"); diff --git a/setup.sh b/setup.sh index f518309c3..6b82a3d62 100755 --- a/setup.sh +++ b/setup.sh @@ -664,10 +664,7 @@ echo "" # Re-generating supplementary # Clear existing -csupp () { - rm -f $config_dir/stop $config_dir/start $config_dir/restart $config_dir/force-reload $config_dir/reload -} -csupp +rm -f $config_dir/stop $config_dir/start $config_dir/restart $config_dir/force-reload $config_dir/reload # Start init.d ln -s $config_dir/start-init $config_dir/start >/dev/null 2>&1 @@ -681,10 +678,10 @@ ln -s $config_dir/force-reload-init $config_dir/force-reload >/dev/null 2>&1 ln -s $config_dir/reload-init $config_dir/reload >/dev/null 2>&1 # For systemd create different start/stop scripts -if [ -x "$(command -v systemctl)" >/dev/null 2>&1 ]; then - csupp +systemctlcmd=`which systemctl` >/dev/null 2>&1 +if [ -x "$systemctlcmd" ]; then + rm -f $config_dir/stop $config_dir/start $config_dir/restart $config_dir/force-reload $config_dir/reload - systemctlcmd=`which systemctl` echo "Creating start and stop scripts (systemd).." # Start systemd echo "#!/bin/sh" >>$config_dir/start From dfbf80b3b13ae5de7c5a320c094d29b0067f47b4 Mon Sep 17 00:00:00 2001 From: Ilia Date: Mon, 25 Apr 2022 15:36:50 +0300 Subject: [PATCH 51/52] Call force reload as `restart-by-force-kill` to make better sense --- makedebian.pl | 2 +- makerpm.pl | 4 ++-- setup.pl | 14 +++++++------- setup.sh | 26 +++++++++++++------------- webmin-init | 8 ++++---- 5 files changed, 27 insertions(+), 27 deletions(-) diff --git a/makedebian.pl b/makedebian.pl index 674138462..d761542fa 100755 --- a/makedebian.pl +++ b/makedebian.pl @@ -311,7 +311,7 @@ if [ "$inetd" != "1" ]; then /etc/$baseproduct/stop >/dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 $config_directory/force-reload-init"); + open(FRELOAD, ">$config_directory/restart-by-force-kill-init"); print FRELOAD "#!/bin/sh\n"; print FRELOAD "$config_directory/stop-init --kill\n"; print FRELOAD "$config_directory/start-init\n"; @@ -589,7 +589,7 @@ else { chmod(0755, "$config_directory/start-init"); chmod(0755, "$config_directory/stop-init"); chmod(0755, "$config_directory/restart-init"); - chmod(0755, "$config_directory/force-reload-init"); + chmod(0755, "$config_directory/restart-by-force-kill-init"); chmod(0755, "$config_directory/reload-init"); # Re-generating supplementary @@ -598,7 +598,7 @@ else { unlink("$config_directory/start"); unlink("$config_directory/stop"); unlink("$config_directory/restart"); - unlink("$config_directory/force-reload"); + unlink("$config_directory/restart-by-force-kill"); unlink("$config_directory/reload"); # Create symlinks @@ -609,7 +609,7 @@ else { # Restart init.d symlink("$config_directory/restart-init", "$config_directory/restart"); # Force reload init.d - symlink("$config_directory/force-reload-init", "$config_directory/force-reload"); + symlink("$config_directory/restart-by-force-kill-init", "$config_directory/restart-by-force-kill"); # Reload init.d symlink("$config_directory/reload-init", "$config_directory/reload"); @@ -622,7 +622,7 @@ else { unlink("$config_directory/start"); unlink("$config_directory/stop"); unlink("$config_directory/restart"); - unlink("$config_directory/force-reload"); + unlink("$config_directory/restart-by-force-kill"); unlink("$config_directory/reload"); # Start systemd @@ -641,7 +641,7 @@ else { close(RESTARTD); # Force reload systemd - open(FRELOADD, ">$config_directory/force-reload"); + open(FRELOADD, ">$config_directory/restart-by-force-kill"); print FRELOADD "$config_directory/stop-init --kill >/dev/null 2>&1\n"; print FRELOADD "$systemctlcmd stop webmin\n"; print FRELOADD "$systemctlcmd start webmin\n"; @@ -655,7 +655,7 @@ else { chmod(0755, "$config_directory/start"); chmod(0755, "$config_directory/stop"); chmod(0755, "$config_directory/restart"); - chmod(0755, "$config_directory/force-reload"); + chmod(0755, "$config_directory/restart-by-force-kill"); chmod(0755, "$config_directory/reload"); # Fix existing systemd webmin.service file to update start and stop commands diff --git a/setup.sh b/setup.sh index 6b82a3d62..8aedd1048 100755 --- a/setup.sh +++ b/setup.sh @@ -603,7 +603,7 @@ if [ "$noperlpath" = "" ]; then fi # Re-generating main -rm -f $config_dir/stop-init $config_dir/start-init $config_dir/restart-init $config_dir/force-reload-init $config_dir/reload-init +rm -f $config_dir/stop-init $config_dir/start-init $config_dir/restart-init $config_dir/restart-by-force-kill-init $config_dir/reload-init echo "Creating start and stop init scripts.." # Start main echo "#!/bin/sh" >>$config_dir/start-init @@ -648,23 +648,23 @@ echo "#!/bin/sh" >>$config_dir/restart-init echo "$config_dir/stop-init" >>$config_dir/restart-init echo "$config_dir/start-init" >>$config_dir/restart-init # Force reload main -echo "#!/bin/sh" >>$config_dir/force-reload-init -echo "$config_dir/stop-init --kill" >>$config_dir/force-reload-init -echo "$config_dir/start-init" >>$config_dir/force-reload-init +echo "#!/bin/sh" >>$config_dir/restart-by-force-kill-init +echo "$config_dir/stop-init --kill" >>$config_dir/restart-by-force-kill-init +echo "$config_dir/start-init" >>$config_dir/restart-by-force-kill-init # Reload main echo "#!/bin/sh" >>$config_dir/reload-init echo "echo Reloading Webmin server in $wadir" >>$config_dir/reload-init echo "pidfile=\`grep \"^pidfile=\" $config_dir/miniserv.conf | sed -e 's/pidfile=//g'\`" >>$config_dir/reload-init echo "kill -USR1 \`cat \$pidfile\`" >>$config_dir/reload-init -chmod 755 $config_dir/stop-init $config_dir/start-init $config_dir/restart-init $config_dir/force-reload-init $config_dir/reload-init +chmod 755 $config_dir/stop-init $config_dir/start-init $config_dir/restart-init $config_dir/restart-by-force-kill-init $config_dir/reload-init echo "..done" echo "" # Re-generating supplementary # Clear existing -rm -f $config_dir/stop $config_dir/start $config_dir/restart $config_dir/force-reload $config_dir/reload +rm -f $config_dir/stop $config_dir/start $config_dir/restart $config_dir/restart-by-force-kill $config_dir/reload # Start init.d ln -s $config_dir/start-init $config_dir/start >/dev/null 2>&1 @@ -673,14 +673,14 @@ ln -s $config_dir/stop-init $config_dir/stop >/dev/null 2>&1 # Restart init.d ln -s $config_dir/restart-init $config_dir/restart >/dev/null 2>&1 # Force reload init.d -ln -s $config_dir/force-reload-init $config_dir/force-reload >/dev/null 2>&1 +ln -s $config_dir/restart-by-force-kill-init $config_dir/restart-by-force-kill >/dev/null 2>&1 # Reload init.d ln -s $config_dir/reload-init $config_dir/reload >/dev/null 2>&1 # For systemd create different start/stop scripts systemctlcmd=`which systemctl` >/dev/null 2>&1 if [ -x "$systemctlcmd" ]; then - rm -f $config_dir/stop $config_dir/start $config_dir/restart $config_dir/force-reload $config_dir/reload + rm -f $config_dir/stop $config_dir/start $config_dir/restart $config_dir/restart-by-force-kill $config_dir/reload echo "Creating start and stop scripts (systemd).." # Start systemd @@ -693,10 +693,10 @@ if [ -x "$systemctlcmd" ]; then echo "#!/bin/sh" >>$config_dir/restart echo "$systemctlcmd restart webmin" >>$config_dir/restart # Force reload systemd - echo "#!/bin/sh" >>$config_dir/force-reload - echo "$config_dir/stop-init --kill >/dev/null 2>&1" >>$config_dir/force-reload - echo "$systemctlcmd stop webmin" >>$config_dir/force-reload - echo "$systemctlcmd start webmin" >>$config_dir/force-reload + echo "#!/bin/sh" >>$config_dir/restart-by-force-kill + echo "$config_dir/stop-init --kill >/dev/null 2>&1" >>$config_dir/restart-by-force-kill + echo "$systemctlcmd stop webmin" >>$config_dir/restart-by-force-kill + echo "$systemctlcmd start webmin" >>$config_dir/restart-by-force-kill # Reload systemd echo "#!/bin/sh" >>$config_dir/reload echo "$config_dir/reload-init >/dev/null 2>&1" >>$config_dir/reload @@ -704,7 +704,7 @@ if [ -x "$systemctlcmd" ]; then # Fix existing systemd webmin.service file to update start and stop commands (cd "$wadir/init" ; WEBMIN_CONFIG=$config_dir WEBMIN_VAR=$var_dir "$wadir/init/updateboot.pl" "webmin") - chmod 755 $config_dir/stop $config_dir/start $config_dir/restart $config_dir/force-reload $config_dir/reload + chmod 755 $config_dir/stop $config_dir/start $config_dir/restart $config_dir/restart-by-force-kill $config_dir/reload else # Creating symlinks echo "Creating start and stop init symlinks to scripts .." diff --git a/webmin-init b/webmin-init index 74a782e68..05ed7acea 100755 --- a/webmin-init +++ b/webmin-init @@ -22,7 +22,7 @@ SCRIPTNAME=/etc/init.d/webmin START=/etc/webmin/start-init STOP=/etc/webmin/stop-init RELOAD=/etc/webmin/reload-init -FORCERELOAD=/etc/webmin/force-reload-init +FORCERELOAD=/etc/webmin/restart-by-force-kill-init LOCKFILE=/var/lock/subsys/webmin CONFFILE=/etc/webmin/miniserv.conf @@ -70,16 +70,16 @@ restart) $STOP ; $START RETVAL=$? ;; -force-reload) +restart-by-force-kill) $FORCERELOAD RETVAL=$? ;; -reload) +reload|force-reload) $RELOAD RETVAL=$? ;; *) - echo "Usage: $0 {start|stop|restart|reload|force-reload|status}" >&2 + echo "Usage: $0 {start|stop|restart|restart-by-force-kill|reload|force-reload|status}" >&2 RETVAL=1 ;; esac From d865737a4599df0f3e92504ab242e34818e8e23f Mon Sep 17 00:00:00 2001 From: Ilia Date: Mon, 25 Apr 2022 17:04:01 +0300 Subject: [PATCH 52/52] Fix to hide scripts that mustn't be run directly; fix bugs --- init/atboot.pl | 29 +++++++------- makerpm.pl | 2 +- setup.pl | 44 ++++++++++----------- setup.sh | 102 ++++++++++++++++++++++++------------------------- webmin-init | 10 ++--- webmin-systemd | 4 +- 6 files changed, 96 insertions(+), 95 deletions(-) diff --git a/init/atboot.pl b/init/atboot.pl index 843a5cc39..9fe2a0c53 100755 --- a/init/atboot.pl +++ b/init/atboot.pl @@ -12,14 +12,14 @@ $< == 0 || die "atboot.pl must be run as root"; if ($init_mode eq "osx") { # Darwin System &enable_at_boot("webmin", "Webmin administration server", - "$config_directory/start >/dev/null 2>&1 /dev/null 2>&1 [$i] !~ /^exit\s/; $i++) { } - splice(@$lref, $i, 0, "$config_directory/start >/dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 $var_directory."/miniserv.pid", 'opts' => { @@ -136,16 +136,17 @@ elsif ($init_mode eq "systemd") { } elsif ($init_mode eq "rc" || $init_mode eq "upstart") { # Create RC or upstart script - &enable_at_boot($product, $ucproduct, "$config_directory/start", - "$config_directory/stop", - undef, - { 'fork' => 1, - 'pidfile' => $var_directory."/miniserv.pid" }); + &enable_at_boot($product, $ucproduct, + "$config_directory/.start-init", + "$config_directory/.stop-init", + undef, + { 'fork' => 1, + 'pidfile' => $var_directory."/miniserv.pid" }); } elsif ($init_mode eq "launchd") { # Create launchd script &create_launchd_agent(&launchd_name($product), - "$config_directory/start --nofork", 1); + "$config_directory/.start-init --nofork", 1); } $config{'atboot_product'} = $product; diff --git a/makerpm.pl b/makerpm.pl index b1f8a297a..82c1a75cb 100755 --- a/makerpm.pl +++ b/makerpm.pl @@ -269,7 +269,7 @@ if [ "\$1" = 0 ]; then # has taken it's place. Run uninstalls and stop the server (cd /usr/libexec/webmin ; WEBMIN_CONFIG=/etc/webmin WEBMIN_VAR=/var/webmin LANG= /usr/libexec/webmin/run-uninstalls.pl) >/dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 $config_directory/start-init"); + open(START, ">$config_directory/.start-init"); print START "#!/bin/sh\n"; print START "echo Starting Webmin server in $wadir\n"; print START "trap '' 1\n"; @@ -537,10 +537,10 @@ else { print START "exec '$wadir/miniserv.pl' $config_directory/miniserv.conf\n"; } close(START); - $start_cmd = "$config_directory/start-init"; + $start_cmd = "$config_directory/start"; # Stop main - open(STOP, ">$config_directory/stop-init"); + open(STOP, ">$config_directory/.stop-init"); print STOP "#!/bin/sh\n"; print STOP "if [ \"\$1\" = \"--kill\" ]; then\n"; print STOP " echo Force stopping Webmin server in $wadir\n"; @@ -565,32 +565,32 @@ else { close(STOP); # Restart main - open(RESTART, ">$config_directory/restart-init"); + open(RESTART, ">$config_directory/.restart-init"); print RESTART "#!/bin/sh\n"; - print RESTART "$config_directory/stop-init\n"; - print RESTART "$config_directory/start-init\n"; + print RESTART "$config_directory/.stop-init\n"; + print RESTART "$config_directory/.start-init\n"; close(RESTART); # Force reload main - open(FRELOAD, ">$config_directory/restart-by-force-kill-init"); + open(FRELOAD, ">$config_directory/.restart-by-force-kill-init"); print FRELOAD "#!/bin/sh\n"; - print FRELOAD "$config_directory/stop-init --kill\n"; - print FRELOAD "$config_directory/start-init\n"; + print FRELOAD "$config_directory/.stop-init --kill\n"; + print FRELOAD "$config_directory/.start-init\n"; close(FRELOAD); # Reload main - open(RELOAD, ">$config_directory/reload-init"); + open(RELOAD, ">$config_directory/.reload-init"); print RELOAD "#!/bin/sh\n"; print RELOAD "echo Reloading Webmin server in $wadir\n"; print RELOAD "pidfile=\`grep \"^pidfile=\" $config_directory/miniserv.conf | sed -e 's/pidfile=//g'\`\n"; print RELOAD "kill -USR1 \`cat \$pidfile\`\n"; close(RELOAD); - chmod(0755, "$config_directory/start-init"); - chmod(0755, "$config_directory/stop-init"); - chmod(0755, "$config_directory/restart-init"); - chmod(0755, "$config_directory/restart-by-force-kill-init"); - chmod(0755, "$config_directory/reload-init"); + chmod(0755, "$config_directory/.start-init"); + chmod(0755, "$config_directory/.stop-init"); + chmod(0755, "$config_directory/.restart-init"); + chmod(0755, "$config_directory/.restart-by-force-kill-init"); + chmod(0755, "$config_directory/.reload-init"); # Re-generating supplementary @@ -603,15 +603,15 @@ else { # Create symlinks # Start init.d - symlink("$config_directory/start-init", "$config_directory/start"); + symlink("$config_directory/.start-init", "$config_directory/start"); # Stop init.d - symlink("$config_directory/stop-init", "$config_directory/stop"); + symlink("$config_directory/.stop-init", "$config_directory/stop"); # Restart init.d - symlink("$config_directory/restart-init", "$config_directory/restart"); + symlink("$config_directory/.restart-init", "$config_directory/restart"); # Force reload init.d - symlink("$config_directory/restart-by-force-kill-init", "$config_directory/restart-by-force-kill"); + symlink("$config_directory/.restart-by-force-kill-init", "$config_directory/restart-by-force-kill"); # Reload init.d - symlink("$config_directory/reload-init", "$config_directory/reload"); + symlink("$config_directory/.reload-init", "$config_directory/reload"); # For systemd my $systemctlcmd = `which systemctl`; @@ -642,14 +642,14 @@ else { # Force reload systemd open(FRELOADD, ">$config_directory/restart-by-force-kill"); - print FRELOADD "$config_directory/stop-init --kill >/dev/null 2>&1\n"; + print FRELOADD "$config_directory/.stop-init --kill >/dev/null 2>&1\n"; print FRELOADD "$systemctlcmd stop webmin\n"; print FRELOADD "$systemctlcmd start webmin\n"; close(FRELOADD); # Reload systemd open(RELOADD, ">$config_directory/reload"); - print RELOADD "$config_directory/reload-init >/dev/null 2>&1\n"; + print RELOADD "$config_directory/.reload-init >/dev/null 2>&1\n"; close(RELOADD); chmod(0755, "$config_directory/start"); diff --git a/setup.sh b/setup.sh index 8aedd1048..dd6cf0a6a 100755 --- a/setup.sh +++ b/setup.sh @@ -603,61 +603,61 @@ if [ "$noperlpath" = "" ]; then fi # Re-generating main -rm -f $config_dir/stop-init $config_dir/start-init $config_dir/restart-init $config_dir/restart-by-force-kill-init $config_dir/reload-init +rm -f $config_dir/.stop-init $config_dir/.start-init $config_dir/.restart-init $config_dir/.restart-by-force-kill-init $config_dir/.reload-init echo "Creating start and stop init scripts.." # Start main -echo "#!/bin/sh" >>$config_dir/start-init -echo "echo Starting Webmin server in $wadir" >>$config_dir/start-init -echo "trap '' 1" >>$config_dir/start-init -echo "LANG=" >>$config_dir/start-init -echo "export LANG" >>$config_dir/start-init -echo "unset PERLIO" >>$config_dir/start-init -echo "export PERLIO" >>$config_dir/start-init -echo "PERLLIB=$PERLLIB" >>$config_dir/start-init -echo "export PERLLIB" >>$config_dir/start-init +echo "#!/bin/sh" >>$config_dir/.start-init +echo "echo Starting Webmin server in $wadir" >>$config_dir/.start-init +echo "trap '' 1" >>$config_dir/.start-init +echo "LANG=" >>$config_dir/.start-init +echo "export LANG" >>$config_dir/.start-init +echo "unset PERLIO" >>$config_dir/.start-init +echo "export PERLIO" >>$config_dir/.start-init +echo "PERLLIB=$PERLLIB" >>$config_dir/.start-init +echo "export PERLLIB" >>$config_dir/.start-init uname -a | grep -i 'HP/*UX' >/dev/null if [ $? = "0" ]; then - echo "exec '$wadir/miniserv.pl' \$* $config_dir/miniserv.conf &" >>$config_dir/start-init + echo "exec '$wadir/miniserv.pl' \$* $config_dir/miniserv.conf &" >>$config_dir/.start-init else - echo "exec '$wadir/miniserv.pl' \$* $config_dir/miniserv.conf" >>$config_dir/start-init + echo "exec '$wadir/miniserv.pl' \$* $config_dir/miniserv.conf" >>$config_dir/.start-init fi # Stop main -echo "#!/bin/sh" >>$config_dir/stop-init -echo "if [ \"\$1\" = \"--kill\" ]; then" >>$config_dir/stop-init -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 "pidfile=\`grep \"^pidfile=\" $config_dir/miniserv.conf | sed -e 's/pidfile=//g'\`" >>$config_dir/stop-init -echo "pid=\`cat \$pidfile\` 2>/dev/null" >>$config_dir/stop-init -echo "if [ \"\$pid\" != \"\" ]; then" >>$config_dir/stop-init -echo " kill \$pid || exit 1" >>$config_dir/stop-init -echo " touch $var_dir/stop-flag" >>$config_dir/stop-init -echo " if [ \"\$1\" = \"--kill\" ]; then" >>$config_dir/stop-init -echo " sleep 1" >>$config_dir/stop-init -echo " ((ps axf | grep \"webmin\/miniserv\.pl\" | awk '{print \"kill -9 -- -\" \$1}' | bash) || kill -9 -- -\$pid || kill -9 \$pid) 2>/dev/null" >>$config_dir/stop-init -echo " fi" >>$config_dir/stop-init -echo " exit 0" >>$config_dir/stop-init -echo "else" >>$config_dir/stop-init -echo " if [ \"\$1\" = \"--kill\" ]; then" >>$config_dir/stop-init -echo " (ps axf | grep \"webmin\/miniserv\.pl\" | awk '{print \"kill -9 -- -\" \$1}' | bash) 2>/dev/null" >>$config_dir/stop-init -echo " fi" >>$config_dir/stop-init -echo "fi" >>$config_dir/stop-init +echo "#!/bin/sh" >>$config_dir/.stop-init +echo "if [ \"\$1\" = \"--kill\" ]; then" >>$config_dir/.stop-init +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 "pidfile=\`grep \"^pidfile=\" $config_dir/miniserv.conf | sed -e 's/pidfile=//g'\`" >>$config_dir/.stop-init +echo "pid=\`cat \$pidfile\` 2>/dev/null" >>$config_dir/.stop-init +echo "if [ \"\$pid\" != \"\" ]; then" >>$config_dir/.stop-init +echo " kill \$pid || exit 1" >>$config_dir/.stop-init +echo " touch $var_dir/stop-flag" >>$config_dir/.stop-init +echo " if [ \"\$1\" = \"--kill\" ]; then" >>$config_dir/.stop-init +echo " sleep 1" >>$config_dir/.stop-init +echo " ((ps axf | grep \"webmin\/miniserv\.pl\" | awk '{print \"kill -9 -- -\" \$1}' | bash) || kill -9 -- -\$pid || kill -9 \$pid) 2>/dev/null" >>$config_dir/.stop-init +echo " fi" >>$config_dir/.stop-init +echo " exit 0" >>$config_dir/.stop-init +echo "else" >>$config_dir/.stop-init +echo " if [ \"\$1\" = \"--kill\" ]; then" >>$config_dir/.stop-init +echo " (ps axf | grep \"webmin\/miniserv\.pl\" | awk '{print \"kill -9 -- -\" \$1}' | bash) 2>/dev/null" >>$config_dir/.stop-init +echo " fi" >>$config_dir/.stop-init +echo "fi" >>$config_dir/.stop-init # Restart main -echo "#!/bin/sh" >>$config_dir/restart-init -echo "$config_dir/stop-init" >>$config_dir/restart-init -echo "$config_dir/start-init" >>$config_dir/restart-init +echo "#!/bin/sh" >>$config_dir/.restart-init +echo "$config_dir/.stop-init" >>$config_dir/.restart-init +echo "$config_dir/.start-init" >>$config_dir/.restart-init # Force reload main -echo "#!/bin/sh" >>$config_dir/restart-by-force-kill-init -echo "$config_dir/stop-init --kill" >>$config_dir/restart-by-force-kill-init -echo "$config_dir/start-init" >>$config_dir/restart-by-force-kill-init +echo "#!/bin/sh" >>$config_dir/.restart-by-force-kill-init +echo "$config_dir/.stop-init --kill" >>$config_dir/.restart-by-force-kill-init +echo "$config_dir/.start-init" >>$config_dir/.restart-by-force-kill-init # Reload main -echo "#!/bin/sh" >>$config_dir/reload-init -echo "echo Reloading Webmin server in $wadir" >>$config_dir/reload-init -echo "pidfile=\`grep \"^pidfile=\" $config_dir/miniserv.conf | sed -e 's/pidfile=//g'\`" >>$config_dir/reload-init -echo "kill -USR1 \`cat \$pidfile\`" >>$config_dir/reload-init +echo "#!/bin/sh" >>$config_dir/.reload-init +echo "echo Reloading Webmin server in $wadir" >>$config_dir/.reload-init +echo "pidfile=\`grep \"^pidfile=\" $config_dir/miniserv.conf | sed -e 's/pidfile=//g'\`" >>$config_dir/.reload-init +echo "kill -USR1 \`cat \$pidfile\`" >>$config_dir/.reload-init -chmod 755 $config_dir/stop-init $config_dir/start-init $config_dir/restart-init $config_dir/restart-by-force-kill-init $config_dir/reload-init +chmod 755 $config_dir/.stop-init $config_dir/.start-init $config_dir/.restart-init $config_dir/.restart-by-force-kill-init $config_dir/.reload-init echo "..done" echo "" @@ -667,15 +667,15 @@ echo "" rm -f $config_dir/stop $config_dir/start $config_dir/restart $config_dir/restart-by-force-kill $config_dir/reload # Start init.d -ln -s $config_dir/start-init $config_dir/start >/dev/null 2>&1 +ln -s $config_dir/.start-init $config_dir/start >/dev/null 2>&1 # Stop init.d -ln -s $config_dir/stop-init $config_dir/stop >/dev/null 2>&1 +ln -s $config_dir/.stop-init $config_dir/stop >/dev/null 2>&1 # Restart init.d -ln -s $config_dir/restart-init $config_dir/restart >/dev/null 2>&1 +ln -s $config_dir/.restart-init $config_dir/restart >/dev/null 2>&1 # Force reload init.d -ln -s $config_dir/restart-by-force-kill-init $config_dir/restart-by-force-kill >/dev/null 2>&1 +ln -s $config_dir/.restart-by-force-kill-init $config_dir/restart-by-force-kill >/dev/null 2>&1 # Reload init.d -ln -s $config_dir/reload-init $config_dir/reload >/dev/null 2>&1 +ln -s $config_dir/.reload-init $config_dir/reload >/dev/null 2>&1 # For systemd create different start/stop scripts systemctlcmd=`which systemctl` >/dev/null 2>&1 @@ -694,12 +694,12 @@ if [ -x "$systemctlcmd" ]; then echo "$systemctlcmd restart webmin" >>$config_dir/restart # Force reload systemd echo "#!/bin/sh" >>$config_dir/restart-by-force-kill - echo "$config_dir/stop-init --kill >/dev/null 2>&1" >>$config_dir/restart-by-force-kill + echo "$config_dir/.stop-init --kill >/dev/null 2>&1" >>$config_dir/restart-by-force-kill echo "$systemctlcmd stop webmin" >>$config_dir/restart-by-force-kill echo "$systemctlcmd start webmin" >>$config_dir/restart-by-force-kill # Reload systemd echo "#!/bin/sh" >>$config_dir/reload - echo "$config_dir/reload-init >/dev/null 2>&1" >>$config_dir/reload + echo "$config_dir/.reload-init >/dev/null 2>&1" >>$config_dir/reload # Fix existing systemd webmin.service file to update start and stop commands (cd "$wadir/init" ; WEBMIN_CONFIG=$config_dir WEBMIN_VAR=$var_dir "$wadir/init/updateboot.pl" "webmin") diff --git a/webmin-init b/webmin-init index 05ed7acea..5957a3f84 100755 --- a/webmin-init +++ b/webmin-init @@ -19,10 +19,10 @@ DESC="web-based administration interface for Unix systems" NAME=Webmin PIDFILE=/var/webmin/miniserv.pid SCRIPTNAME=/etc/init.d/webmin -START=/etc/webmin/start-init -STOP=/etc/webmin/stop-init -RELOAD=/etc/webmin/reload-init -FORCERELOAD=/etc/webmin/restart-by-force-kill-init +START=/etc/webmin/.start-init +STOP=/etc/webmin/.stop-init +FORCERESTART=/etc/webmin/.restart-by-force-kill-init +RELOAD=/etc/webmin/.reload-init LOCKFILE=/var/lock/subsys/webmin CONFFILE=/etc/webmin/miniserv.conf @@ -71,7 +71,7 @@ restart) RETVAL=$? ;; restart-by-force-kill) - $FORCERELOAD + $FORCERESTART RETVAL=$? ;; reload|force-reload) diff --git a/webmin-systemd b/webmin-systemd index 08e595600..fad208d31 100755 --- a/webmin-systemd +++ b/webmin-systemd @@ -3,8 +3,8 @@ Description=Webmin server daemon After=syslog.target [Service] -ExecStart=/etc/webmin/start-init -ExecStop=/etc/webmin/stop-init +ExecStart=/etc/webmin/.start-init +ExecStop=/etc/webmin/.stop-init PIDFile=/var/webmin/miniserv.pid Type=forking KillMode=none