HEX
Server: Apache
System: Linux vps-cdc32557.vps.ovh.ca 5.15.0-156-generic #166-Ubuntu SMP Sat Aug 9 00:02:46 UTC 2025 x86_64
User: hanode (1017)
PHP: 7.4.33
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
File: //usr/share/perl5/Virtualmin/Config/Plugin/Limits.pm
package Virtualmin::Config::Plugin::Limits;
use strict;
use warnings;
no warnings qw(once);
use parent 'Virtualmin::Config::Plugin';

our $config_directory;
our (%gconfig, %miniserv);
our $trust_unknown_referers = 1;

my $log = Log::Log4perl->get_logger("virtualmin-config-system");

sub new {
  my ($class, %args) = @_;

  # inherit from Plugin
  my $self = $class->SUPER::new(name => 'Limits', %args);

  return $self;
}

# actions method performs whatever configuration is needed for this
# plugin. XXX Needs to make a backup so changes can be reverted.
sub actions {
  my $self = shift;

  use Cwd;
  my $cwd  = getcwd();
  my $root = $self->root();
  chdir($root);
  $0 = "$root/virtual-server/config-system.pl";
  push(@INC, $root);
  push(@INC, "$root/vendor_perl");
  eval 'use WebminCore';    ## no critic
  init_config();

  $self->spin();
  eval {
    # Do we have /etc/sysctl.d?
    if (-d '/etc/sysctl.d') {
      open(my $fh, '>', '/etc/sysctl.d/10-virtualmin.conf')
        or die 'Unable to open /etc/sysctl.d/10-virtualmin.conf for writing';
      print $fh '# Increase inotify limit, for noticron';
      print $fh
        '# If, for some reason, you have more than a few thousand files';
      print $fh '# in /etc, increase this value (will use more memory).';
      print $fh 'fs.inotify.max_user_watches = 32768';
      close $fh;
    }
    elsif (-e '/etc/sysctl.conf') {    # sysctl.d, stick it into sysctl.conf
      open(my $fh, '+<', '/etc/sysctl.conf')
        or die 'Unable to open /etc/sysctl.conf for editing';
      my $skip;
      while (my $line = <$fh>) {
        if ($line =~ /fs.inotify.max_user_watches/) {
          $log->warning('Found existing configuration: $line');
          $log->warning('Cowardly refusing to overwrite it.');
          $skip = 1;
        }
      }
      unless ($skip) {
        print $fh 'fs.inotify.max_user_watches = 32768';
      }
      close $fh;
    }
  };
  if ($@) {
    $self->done(0);
  }
}

1;

=pod

=head1 Virtualmin::Config::Plugin::Limits

Modify limits in sysctl.conf or sysctl.d.

=head1 SYNOPSIS

virtualmin config-system --include Limits

=head1 LICENSE AND COPYRIGHT

Licensed under the GPLv3. Copyright 2017, Joe Cooper <joe@virtualmin.com>

=cut