diff --git a/init/atboot.pl b/init/atboot.pl index d2734ba41..9fe2a0c53 100755 --- a/init/atboot.pl +++ b/init/atboot.pl @@ -7,17 +7,19 @@ require './init-lib.pl'; $product = $ARGV[0] || "webmin"; $ucproduct = ucfirst($product); +$< == 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' => { + '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", - 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/init/init-lib.pl b/init/init-lib.pl index 56fb203ff..be7884619 100755 --- a/init/init-lib.pl +++ b/init/init-lib.pl @@ -2400,13 +2400,18 @@ 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"; } 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/init/updateboot.pl b/init/updateboot.pl new file mode 100755 index 000000000..c235bb69b --- /dev/null +++ b/init/updateboot.pl @@ -0,0 +1,26 @@ +#!/usr/bin/perl +# updateboot.pl +# Called by setup.sh to update boot script + +$no_acl_check++; +require './init-lib.pl'; +$product = $ARGV[0]; + +$< == 0 || die "updateboot.pl must be run as root"; + +# Update boot script +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 daemon-reload >/dev/null 2>&1"); + }; + } diff --git a/makedebian.pl b/makedebian.pl index a25adeaad..d761542fa 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 ."); @@ -266,7 +262,7 @@ print SCRIPT </dev/null 2>&1 /dev/null 2>&1 && systemctl daemon-reload + 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 + /etc/$baseproduct/stop >/dev/null 2>&1 /dev/null 2>&1 /dev/null 2>&1 -fi + cat >/etc/$baseproduct/uninstall.sh <>\$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); @@ -369,8 +361,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 /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 fi EOF diff --git a/makedist.pl b/makedist.pl index 0b3774e32..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", @@ -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"); diff --git a/makerpm.pl b/makerpm.pl index 76d74c257..82c1a75cb 100755 --- a/makerpm.pl +++ b/makerpm.pl @@ -105,24 +105,13 @@ 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 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 -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 -ln -s /usr/libexec/webmin/bin/webmin %{buildroot}/usr/bin echo rpm >%{buildroot}/usr/libexec/webmin/install-type %clean @@ -133,14 +122,6 @@ echo rpm >%{buildroot}/usr/libexec/webmin/install-type %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 @@ -164,7 +145,6 @@ if [ ! -r /etc/webmin/config ]; then echo Unable to identify operating system exit 2 fi - echo Operating system is \$oscheck if [ "\$WEBMIN_PORT\" != \"\" ]; then port=\$WEBMIN_PORT else @@ -193,13 +173,13 @@ inetd=`grep "^inetd=" /etc/webmin/miniserv.conf 2>/dev/null | sed -e 's/inetd=// startafter=0 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 startafter=1 fi - /etc/init.d/webmin stop >/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 -which systemctl >/dev/null 2>&1 && systemctl daemon-reload +cd /usr/libexec/webmin if [ "\$inetd" != "1" -a "\$startafter" = "1" ]; then - /etc/init.d/webmin stop - /etc/init.d/webmin start + /etc/webmin/stop >/dev/null 2>&1 /dev/null 2>&1 /etc/webmin/uninstall.sh <>\$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 @@ -282,10 +267,9 @@ 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) - /etc/init.d/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 /dev/null 2>&1 $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"; @@ -535,21 +539,131 @@ else { close(START); $start_cmd = "$config_directory/start"; - 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/.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"; + 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/.restart-by-force-kill-init"); + chmod(0755, "$config_directory/.reload-init"); + + # Re-generating supplementary + + # Clear existing + unlink("$config_directory/start"); + unlink("$config_directory/stop"); + unlink("$config_directory/restart"); + unlink("$config_directory/restart-by-force-kill"); + unlink("$config_directory/reload"); + + # 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/.restart-by-force-kill-init", "$config_directory/restart-by-force-kill"); + # Reload init.d + symlink("$config_directory/.reload-init", "$config_directory/reload"); + + # For systemd + my $systemctlcmd = `which systemctl`; + $systemctlcmd =~ s/\s+$//; + if (-x $systemctlcmd) { + + # Clear existing + unlink("$config_directory/start"); + unlink("$config_directory/stop"); + unlink("$config_directory/restart"); + unlink("$config_directory/restart-by-force-kill"); + unlink("$config_directory/reload"); + + # 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/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"; + 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/restart-by-force-kill"); + 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 +756,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 >$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/.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 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 "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 +# 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 +# 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 +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 "" -echo "#!/bin/sh" >>$config_dir/restart -echo "$config_dir/stop --kill && $config_dir/start" >>$config_dir/restart +# Re-generating supplementary -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 +# Clear existing +rm -f $config_dir/stop $config_dir/start $config_dir/restart $config_dir/restart-by-force-kill $config_dir/reload -chmod 755 $config_dir/start $config_dir/stop $config_dir/restart $config_dir/reload +# 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/.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/restart-by-force-kill $config_dir/reload + + echo "Creating start and stop scripts (systemd).." + # Start systemd + echo "#!/bin/sh" >>$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 + # Restart systemd + echo "#!/bin/sh" >>$config_dir/restart + 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 "$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 + + # 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/restart-by-force-kill $config_dir/reload +else + # Creating symlinks + echo "Creating start and stop init symlinks to scripts .." +fi echo "..done" echo "" @@ -773,7 +837,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 /dev/null 2>&1 /dev/null 2>&1 @@ -69,12 +70,16 @@ restart) $STOP ; $START RETVAL=$? ;; +restart-by-force-kill) + $FORCERESTART + RETVAL=$? + ;; 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 diff --git a/webmin-systemd b/webmin-systemd new file mode 100755 index 000000000..fad208d31 --- /dev/null +++ b/webmin-systemd @@ -0,0 +1,13 @@ +[Unit] +Description=Webmin server daemon +After=syslog.target + +[Service] +ExecStart=/etc/webmin/.start-init +ExecStop=/etc/webmin/.stop-init +PIDFile=/var/webmin/miniserv.pid +Type=forking +KillMode=none + +[Install] +WantedBy=multi-user.target