mirror of
https://github.com/webmin/webmin.git
synced 2026-02-11 01:32:03 +00:00
Fix to use native commands on systemd systems
This commit is contained in:
@@ -269,15 +269,10 @@ print SCRIPT <<EOF;
|
||||
if [ -d /etc/webmin ]; then
|
||||
cat >/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
|
||||
|
||||
26
makerpm.pl
26
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
|
||||
/etc/init.d/webmin start >/dev/null 2>&1 </dev/null
|
||||
if command -v systemctl >/dev/null 2>&1; then
|
||||
/etc/webmin/stop >/dev/null 2>&1 </dev/null
|
||||
/etc/webmin/start >/dev/null 2>&1 </dev/null
|
||||
else
|
||||
/etc/init.d/webmin stop >/dev/null 2>&1 </dev/null
|
||||
/etc/init.d/webmin start >/dev/null 2>&1 </dev/null
|
||||
fi
|
||||
fi
|
||||
cat >/etc/webmin/uninstall.sh <<EOFF
|
||||
#!/bin/sh
|
||||
@@ -328,8 +331,13 @@ if [ ! -r /etc/webmin/miniserv.conf -a -d /etc/.webmin-backup -a "\$1" = 2 ]; th
|
||||
rm -rf /etc/.webmin-broken
|
||||
mv /etc/webmin /etc/.webmin-broken
|
||||
mv /etc/.webmin-backup /etc/webmin
|
||||
/etc/init.d/webmin stop >/dev/null 2>&1 </dev/null
|
||||
/etc/init.d/webmin start >/dev/null 2>&1 </dev/null
|
||||
if command -v systemctl >/dev/null 2>&1; then
|
||||
/etc/webmin/stop >/dev/null 2>&1 </dev/null
|
||||
/etc/webmin/start >/dev/null 2>&1 </dev/null
|
||||
else
|
||||
/etc/init.d/webmin stop >/dev/null 2>&1 </dev/null
|
||||
/etc/init.d/webmin start >/dev/null 2>&1 </dev/null
|
||||
fi
|
||||
else
|
||||
rm -rf /etc/.webmin-backup
|
||||
fi
|
||||
|
||||
124
setup.sh
124
setup.sh
@@ -602,53 +602,96 @@ if [ "$noperlpath" = "" ]; then
|
||||
echo ""
|
||||
fi
|
||||
|
||||
echo "Creating start and stop scripts.."
|
||||
rm -f $config_dir/stop $config_dir/start $config_dir/restart $config_dir/reload
|
||||
echo "#!/bin/sh" >>$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!"
|
||||
|
||||
118
webmin-init
118
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
|
||||
RETVAL=$?
|
||||
if [ "$RETVAL" = "0" ]; then
|
||||
touch $LOCKFILE >/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=$?
|
||||
;;
|
||||
*)
|
||||
|
||||
Reference in New Issue
Block a user