Add support for native systemd webmin.service unit

This commit is contained in:
Ilia
2022-04-21 03:55:33 +03:00
parent e1abbd61e3
commit a3680e0173
6 changed files with 119 additions and 131 deletions

View File

@@ -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",

View File

@@ -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";

View File

@@ -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
rmdir %{buildroot}/etc/sysconfig/daemons >/dev/null 2>&1 </dev/null
rm -f %{buildroot}/etc/init.d/webmin >/dev/null 2>&1 </dev/null
rm -f %{buildroot}/etc/rc.d/rc2.d/S99webmin >/dev/null 2>&1 </dev/null
rm -f %{buildroot}/etc/rc.d/rc3.d/S99webmin >/dev/null 2>&1 </dev/null
rm -f %{buildroot}/etc/rc.d/rc5.d/S99webmin >/dev/null 2>&1 </dev/null
rm -f %{buildroot}/etc/rc.d/rc0.d/K10webmin >/dev/null 2>&1 </dev/null
rm -f %{buildroot}/etc/rc.d/rc1.d/K10webmin >/dev/null 2>&1 </dev/null
rm -f %{buildroot}/etc/rc.d/rc6.d/K10webmin >/dev/null 2>&1 </dev/null
rmdir %{buildroot}/etc/rc.d/rc2.d >/dev/null 2>&1 </dev/null
rmdir %{buildroot}/etc/rc.d/rc3.d >/dev/null 2>&1 </dev/null
rmdir %{buildroot}/etc/rc.d/rc5.d >/dev/null 2>&1 </dev/null
rmdir %{buildroot}/etc/rc.d/rc0.d >/dev/null 2>&1 </dev/null
rmdir %{buildroot}/etc/rc.d/rc1.d >/dev/null 2>&1 </dev/null
rmdir %{buildroot}/etc/rc.d/rc6.d >/dev/null 2>&1 </dev/null
else
rm -f %{buildroot}/etc/systemd/system/webmin.service >/dev/null 2>&1 </dev/null
fi
perl <<EOD;
$maketemp
EOD
@@ -213,7 +248,7 @@ if [ "\$1" != 1 ]; then
if [ "\$?" = 0 ]; then
startafter=1
fi
/etc/init.d/webmin stop >/dev/null 2>&1 </dev/null
/etc/webmin/stop >/dev/null 2>&1 </dev/null
fi
else
startafter=1
@@ -254,13 +289,8 @@ if command -v systemctl >/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
/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
/etc/webmin/stop >/dev/null 2>&1 </dev/null
/etc/webmin/start >/dev/null 2>&1 </dev/null
fi
cat >/etc/webmin/uninstall.sh <<EOFF
#!/bin/sh
@@ -304,8 +334,8 @@ if [ "\$1" = 0 ]; then
# RPM is being removed, and no new version of webmin
# 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
/etc/init.d/webmin stop >/dev/null 2>&1 </dev/null
/etc/webmin/stop >/dev/null 2>&1 </dev/null
/etc/webmin/stop-init --kill >/dev/null 2>&1 </dev/null
fi
fi
/bin/true
@@ -331,13 +361,8 @@ 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
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
/etc/webmin/stop >/dev/null 2>&1 </dev/null
/etc/webmin/start >/dev/null 2>&1 </dev/null
else
rm -rf /etc/.webmin-backup
fi

View File

@@ -663,16 +663,13 @@ if command -v systemctl >/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

View File

@@ -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=$?
;;
*)

16
webmin-systemd Executable file
View File

@@ -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