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