mirror of
https://github.com/webmin/webmin.git
synced 2026-03-20 08:40:24 +00:00
Merge pull request #1715 from webmin/dev/multi-installs-with-systemd
Add support to install multiple versions of Webmin with `systemd`
This commit is contained in:
@@ -12,7 +12,7 @@ my $kill = &has_command("kill");
|
||||
|
||||
if ($init_mode eq "osx") {
|
||||
# Darwin System
|
||||
&enable_at_boot("webmin", "Webmin administration server",
|
||||
&enable_at_boot($product, "Webmin administration server",
|
||||
"$config_directory/.start-init >/dev/null 2>&1 </dev/null",
|
||||
"$config_directory/.stop-init");
|
||||
}
|
||||
|
||||
71
setup.pl
71
setup.pl
@@ -9,6 +9,7 @@ use Socket;
|
||||
# Find install directory
|
||||
$ENV{'LANG'} = '';
|
||||
$0 =~ s/\\/\//g;
|
||||
$bootscript = $ENV{'bootscript'} || "webmin";
|
||||
if ($0 =~ /^(.*)\//) {
|
||||
chdir($1);
|
||||
}
|
||||
@@ -83,9 +84,13 @@ print "Webmin uses separate directories for configuration files and log files.\n
|
||||
print "Unless you want to run multiple versions of Webmin at the same time\n";
|
||||
print "you can just accept the defaults.\n";
|
||||
print "\n";
|
||||
print "Config file directory [/etc/webmin]: ";
|
||||
my $envetcdir = $ENV{'config_directory'} || "/etc/webmin";
|
||||
print "Config file directory [$envetcdir]: ";
|
||||
if ($ENV{'config_directory'}) {
|
||||
$config_directory = $ENV{'config_directory'};
|
||||
print "$envetcdir\n";
|
||||
print ".. predefined\n";
|
||||
$envetcdirexists = 1;
|
||||
}
|
||||
else {
|
||||
chop($config_directory = <STDIN>);
|
||||
@@ -96,11 +101,11 @@ if ($config_directory !~ /^([a-z]:)?\//i) {
|
||||
&errorexit("Config directory must be an absolute path");
|
||||
}
|
||||
if (!-d $config_directory) {
|
||||
mkdir($config_directory, 0755) ||
|
||||
make_dir_recursive_local($config_directory, 0755) ||
|
||||
&errorexit("Failed to create directory $config_directory");
|
||||
}
|
||||
if (-r "$config_directory/config") {
|
||||
print ".. found\n";
|
||||
print ".. found\n" if (!$envetcdirexists);
|
||||
$upgrading = 1;
|
||||
}
|
||||
|
||||
@@ -121,8 +126,17 @@ if ($upgrading) {
|
||||
open(VAR, "$config_directory/var-path");
|
||||
chop($var_dir = <VAR>);
|
||||
$var_directory = $var_dir;
|
||||
$ENV{'WEBMIN_VAR'} = $var_directory;
|
||||
close(VAR);
|
||||
|
||||
# Get current bootscript name
|
||||
if (-r "$config_directory/bootscript-name") {
|
||||
open(BOOTVAR, "$config_directory/bootscript-name");
|
||||
chop($bootscript = <BOOTVAR>);
|
||||
close(BOOTVAR);
|
||||
$bootscript ||= ($ENV{'bootscript'} || "webmin");
|
||||
}
|
||||
|
||||
# Force creation if non-existant
|
||||
mkdir($var_dir, 0755);
|
||||
|
||||
@@ -188,7 +202,8 @@ else {
|
||||
}
|
||||
|
||||
# Ask for log directory
|
||||
print "Log file directory [/var/webmin]: ";
|
||||
my $envvardir = $ENV{'var_dir'} || "/var/webmin";
|
||||
print "Log file directory [$envvardir]: ";
|
||||
if ($ENV{'var_dir'}) {
|
||||
$var_dir = $ENV{'var_dir'};
|
||||
}
|
||||
@@ -205,7 +220,7 @@ else {
|
||||
&errorexit("Log directory cannot be /");
|
||||
}
|
||||
if (!-d $var_dir) {
|
||||
mkdir($var_dir, 0755) ||
|
||||
make_dir_recursive_local($var_dir, 0755) ||
|
||||
&errorexit("Failed to create directory $var_dir");
|
||||
}
|
||||
$ENV{'WEBMIN_VAR'} = $var_dir;
|
||||
@@ -375,6 +390,9 @@ else {
|
||||
open(VAR, ">$config_directory/var-path");
|
||||
print VAR $var_dir,"\n";
|
||||
close(VAR);
|
||||
open(BOOTS, ">$config_directory/bootscript-name");
|
||||
print BOOTS $bootscript,"\n";
|
||||
close(BOOTS);
|
||||
|
||||
print "Creating web server config files ..\n";
|
||||
$ufile = "$config_directory/miniserv.users";
|
||||
@@ -540,7 +558,7 @@ if ($os_type eq "windows") {
|
||||
open(START, ">>$config_directory/start.bat");
|
||||
print START "$perl \"$wadir/miniserv.pl\" $config_directory/miniserv.conf\n";
|
||||
close(START);
|
||||
$start_cmd = "sc start ".($ENV{'bootscript'} || "webmin");
|
||||
$start_cmd = "sc start $bootscript";
|
||||
|
||||
open(STOP, ">>$config_directory/stop.bat");
|
||||
print STOP "echo Not implemented\n";
|
||||
@@ -597,12 +615,12 @@ else {
|
||||
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 " ((ps axf | grep \"$wadir\\\/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 " (ps axf | grep \"$wadir\\\/miniserv\\.pl\" | awk '{print \"kill -9 -- -\" \$1}' | bash) 2>/dev/null\n";
|
||||
print STOP " fi\n";
|
||||
print STOP "fi\n";
|
||||
close(STOP);
|
||||
@@ -694,42 +712,42 @@ else {
|
||||
|
||||
# Start systemd
|
||||
open(STARTD, ">$config_directory/start");
|
||||
print STARTD "$systemctlcmd start webmin\n";
|
||||
print STARTD "$systemctlcmd start $bootscript\n";
|
||||
close(STARTD);
|
||||
|
||||
# Stop systemd
|
||||
open(STOPD, ">$config_directory/stop");
|
||||
print STOPD "$systemctlcmd stop webmin\n";
|
||||
print STOPD "$systemctlcmd stop $bootscript\n";
|
||||
close(STOPD);
|
||||
|
||||
# Restart systemd
|
||||
open(RESTARTD, ">$config_directory/restart");
|
||||
print RESTARTD "$systemctlcmd restart webmin\n";
|
||||
print RESTARTD "$systemctlcmd restart $bootscript\n";
|
||||
close(RESTARTD);
|
||||
|
||||
# Force reload systemd
|
||||
open(FRELOADD, ">$config_directory/restart-by-force-kill");
|
||||
print FRELOADD "$systemctlcmd stop webmin\n";
|
||||
print FRELOADD "$systemctlcmd stop $bootscript\n";
|
||||
print FRELOADD "$config_directory/.stop-init --kill >/dev/null 2>&1\n";
|
||||
print FRELOADD "$systemctlcmd start webmin\n";
|
||||
print FRELOADD "$systemctlcmd start $bootscript\n";
|
||||
close(FRELOADD);
|
||||
|
||||
# Reload systemd
|
||||
open(RELOADD, ">$config_directory/reload");
|
||||
print RELOADD "$systemctlcmd reload webmin\n";
|
||||
print RELOADD "$systemctlcmd reload $bootscript\n";
|
||||
close(RELOADD);
|
||||
|
||||
# Pre install
|
||||
open(PREINSTT, ">$config_directory/.pre-install");
|
||||
print PREINSTT "#!/bin/sh\n";
|
||||
#print PREINSTT "$systemctlcmd kill --signal=SIGSTOP --kill-who=main webmin\n";
|
||||
#print PREINSTT "$systemctlcmd kill --signal=SIGSTOP --kill-who=main $bootscript\n";
|
||||
close(PREINSTT);
|
||||
|
||||
# Post install
|
||||
open(POSTINSTT, ">$config_directory/.post-install");
|
||||
print POSTINSTT "#!/bin/sh\n";
|
||||
#print POSTINSTT "$systemctlcmd kill --signal=SIGCONT --kill-who=main webmin\n";
|
||||
print POSTINSTT "$systemctlcmd kill --signal=SIGHUP --kill-who=main webmin\n";
|
||||
#print POSTINSTT "$systemctlcmd kill --signal=SIGCONT --kill-who=main $bootscript\n";
|
||||
print POSTINSTT "$systemctlcmd kill --signal=SIGHUP --kill-who=main $bootscript\n";
|
||||
close(POSTINSTT);
|
||||
|
||||
chmod(0755, "$config_directory/start");
|
||||
@@ -743,7 +761,7 @@ else {
|
||||
# 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");
|
||||
system("$perl "."e_path("$wadir/init/updateboot.pl")." $bootscript");
|
||||
}
|
||||
}
|
||||
print ".. done\n";
|
||||
@@ -805,7 +823,7 @@ $gconfig{'product'} ||= "webmin";
|
||||
if ($makeboot) {
|
||||
print "Configuring Webmin to start at boot time ..\n";
|
||||
chdir("$wadir/init");
|
||||
system("$perl "."e_path("$wadir/init/atboot.pl")." ".$ENV{'bootscript'});
|
||||
system("$perl "."e_path("$wadir/init/atboot.pl")." $bootscript");
|
||||
print ".. done\n";
|
||||
print "\n";
|
||||
}
|
||||
@@ -991,3 +1009,18 @@ closedir(DIR);
|
||||
return @rv;
|
||||
}
|
||||
|
||||
sub make_dir_recursive_local
|
||||
{
|
||||
my ($dir, $mod) = @_;
|
||||
my @folders = split(/\//, $dir);
|
||||
my $folder_created;
|
||||
foreach my $folder (@folders) {
|
||||
next if (!$folder);
|
||||
$folder_created .= "/$folder";
|
||||
if (mkdir($folder_created)) {
|
||||
chmod($mod, $folder_created)
|
||||
if ($mod && -d $folder_created);
|
||||
}
|
||||
}
|
||||
return -d $dir;
|
||||
}
|
||||
|
||||
70
setup.sh
70
setup.sh
@@ -8,6 +8,11 @@ LANG=
|
||||
export LANG
|
||||
LANGUAGE=
|
||||
export LANGUAGE
|
||||
|
||||
if [ "$bootscript" = "" ]; then
|
||||
bootscript="webmin"
|
||||
fi
|
||||
|
||||
cd `dirname $0`
|
||||
if [ -x /bin/pwd ]; then
|
||||
wadir=`/bin/pwd`
|
||||
@@ -105,7 +110,12 @@ echo "Webmin uses separate directories for configuration files and log files."
|
||||
echo "Unless you want to run multiple versions of Webmin at the same time"
|
||||
echo "you can just accept the defaults."
|
||||
echo ""
|
||||
printf "Config file directory [/etc/webmin]: "
|
||||
envetcdir="$config_dir"
|
||||
if [ "$envetcdir" = "" ]; then
|
||||
envetcdir=/etc/webmin
|
||||
envetcdirnotfound=1
|
||||
fi
|
||||
printf "Config file directory [$envetcdir]: "
|
||||
if [ "$config_dir" = "" ]; then
|
||||
read config_dir
|
||||
fi
|
||||
@@ -119,7 +129,7 @@ if [ "$abspath" = "" ]; then
|
||||
exit 2
|
||||
fi
|
||||
if [ ! -d $config_dir ]; then
|
||||
mkdir $config_dir;
|
||||
mkdir -p $config_dir;
|
||||
if [ $? != 0 ]; then
|
||||
echo "ERROR: Failed to create directory $config_dir"
|
||||
echo ""
|
||||
@@ -127,8 +137,17 @@ if [ ! -d $config_dir ]; then
|
||||
fi
|
||||
fi
|
||||
if [ -r "$config_dir/config" -a -r "$config_dir/var-path" -a -r "$config_dir/perl-path" ]; then
|
||||
echo ".. found"
|
||||
if [ "$envetcdirnotfound" = "" ]; then
|
||||
echo "$envetcdir"
|
||||
echo ".. predefined"
|
||||
else
|
||||
echo ".. found"
|
||||
fi
|
||||
upgrading=1
|
||||
else
|
||||
if [ "$envetcdirnotfound" = "" ]; then
|
||||
echo "$envetcdir"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Check if upgrading from an old version
|
||||
@@ -138,6 +157,14 @@ if [ "$upgrading" = 1 ]; then
|
||||
# Get current var path
|
||||
var_dir=`cat $config_dir/var-path`
|
||||
|
||||
# Get current bootscript
|
||||
if [ -r "$config_dir/bootscript-name" ]; then
|
||||
bootscript=`cat $config_dir/bootscript-name`
|
||||
if [ "$bootscript" = "" ]; then
|
||||
bootscript="webmin"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Force creation if non-existant
|
||||
mkdir -p $var_dir >/dev/null 2>&1
|
||||
|
||||
@@ -211,7 +238,12 @@ else
|
||||
fi
|
||||
|
||||
# Ask for log directory
|
||||
printf "Log file directory [/var/webmin]: "
|
||||
envvardir="$var_dir"
|
||||
if [ "$envvardir" = "" ]; then
|
||||
envvardir=/var/webmin
|
||||
envvardirnotfound=1
|
||||
fi
|
||||
printf "Log file directory [$envvardir]: "
|
||||
if [ "$var_dir" = "" ]; then
|
||||
read var_dir
|
||||
fi
|
||||
@@ -230,13 +262,16 @@ else
|
||||
exit 3
|
||||
fi
|
||||
if [ ! -d $var_dir ]; then
|
||||
mkdir $var_dir
|
||||
mkdir -p $var_dir
|
||||
if [ $? != 0 ]; then
|
||||
echo "ERROR: Failed to create directory $var_dir"
|
||||
echo ""
|
||||
exit 3
|
||||
fi
|
||||
fi
|
||||
if [ "$upgrading" != 1 -a "$envetcdirnotfound" = "" ]; then
|
||||
echo "$envvardir"
|
||||
fi
|
||||
echo ""
|
||||
|
||||
# Ask where perl is installed
|
||||
@@ -479,6 +514,7 @@ else
|
||||
# Create webserver config file
|
||||
echo $perl > $config_dir/perl-path
|
||||
echo $var_dir > $config_dir/var-path
|
||||
echo $bootscript > $config_dir/bootscript-name
|
||||
echo "Creating web server config files .."
|
||||
cfile=$config_dir/miniserv.conf
|
||||
echo "port=$port" >> $cfile
|
||||
@@ -653,12 +689,12 @@ 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 " ((ps axf | grep \"$wadir\/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 " (ps axf | grep \"$wadir\/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
|
||||
@@ -719,31 +755,31 @@ if [ -x "$systemctlcmd" ]; then
|
||||
echo "Creating start and stop scripts (systemd) .."
|
||||
# Start systemd
|
||||
echo "#!/bin/sh" >$config_dir/start
|
||||
echo "$systemctlcmd start webmin" >>$config_dir/start
|
||||
echo "$systemctlcmd start $bootscript" >>$config_dir/start
|
||||
# Stop systemd
|
||||
echo "#!/bin/sh" >$config_dir/stop
|
||||
echo "$systemctlcmd stop webmin" >>$config_dir/stop
|
||||
echo "$systemctlcmd stop $bootscript" >>$config_dir/stop
|
||||
# Restart systemd
|
||||
echo "#!/bin/sh" >$config_dir/restart
|
||||
echo "$systemctlcmd restart webmin" >>$config_dir/restart
|
||||
echo "$systemctlcmd restart $bootscript" >>$config_dir/restart
|
||||
# Force reload systemd
|
||||
echo "#!/bin/sh" >$config_dir/restart-by-force-kill
|
||||
echo "$systemctlcmd stop webmin" >>$config_dir/restart-by-force-kill
|
||||
echo "$systemctlcmd stop $bootscript" >>$config_dir/restart-by-force-kill
|
||||
echo "$config_dir/.stop-init --kill >/dev/null 2>&1" >>$config_dir/restart-by-force-kill
|
||||
echo "$systemctlcmd start webmin" >>$config_dir/restart-by-force-kill
|
||||
echo "$systemctlcmd start $bootscript" >>$config_dir/restart-by-force-kill
|
||||
# Reload systemd
|
||||
echo "#!/bin/sh" >$config_dir/reload
|
||||
echo "$systemctlcmd reload webmin" >>$config_dir/reload
|
||||
echo "$systemctlcmd reload $bootscript" >>$config_dir/reload
|
||||
# Pre-install on systemd
|
||||
echo "#!/bin/sh" >$config_dir/.pre-install
|
||||
# echo "$systemctlcmd kill --signal=SIGSTOP --kill-who=main webmin" >>$config_dir/.pre-install
|
||||
# echo "$systemctlcmd kill --signal=SIGSTOP --kill-who=main $bootscript" >>$config_dir/.pre-install
|
||||
# Post-install on systemd
|
||||
echo "#!/bin/sh" >$config_dir/.post-install
|
||||
# echo "$systemctlcmd kill --signal=SIGCONT --kill-who=main webmin" >>$config_dir/.post-install
|
||||
echo "$systemctlcmd kill --signal=SIGHUP --kill-who=main webmin" >>$config_dir/.post-install
|
||||
# echo "$systemctlcmd kill --signal=SIGCONT --kill-who=main $bootscript" >>$config_dir/.post-install
|
||||
echo "$systemctlcmd kill --signal=SIGHUP --kill-who=main $bootscript" >>$config_dir/.post-install
|
||||
|
||||
# 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")
|
||||
(cd "$wadir/init" ; WEBMIN_CONFIG=$config_dir WEBMIN_VAR=$var_dir "$wadir/init/updateboot.pl" "$bootscript")
|
||||
|
||||
chmod 755 $config_dir/stop $config_dir/start $config_dir/restart $config_dir/restart-by-force-kill $config_dir/reload $config_dir/.pre-install $config_dir/.post-install
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user