Class: Yast::SystemSettingsClass

Inherits:
Module
  • Object
show all
Defined in:
../../src/modules/SystemSettings.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) Activate



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File '../../src/modules/SystemSettings.rb', line 109

def Activate
  if @ENABLE_SYSRQ != nil && Builtins.regexpmatch(@ENABLE_SYSRQ, "^[0-9]+$")
    Builtins.y2milestone("Activating SysRq config: %1", @ENABLE_SYSRQ)
    SCR.Execute(
      path(".target.bash"),
      Builtins.sformat("echo '%1' > /proc/sys/kernel/sysrq", @ENABLE_SYSRQ)
    )
  else
    Builtins.y2warning(
      "Not activating invalid ENABLE_SYSRQ value: %1",
      @ENABLE_SYSRQ
    )
  end

  if @elevator != nil
    Yast.import "Bootloader"
    new_elevator = @elevator == "" ? :missing : @elevator

    Builtins.y2milestone("Activating scheduler: %1", new_elevator)
    # set the scheduler
    Bootloader.modify_kernel_params("elevator" => new_elevator)

    # TODO FIXME: set the scheduler for all disk devices,
    # reboot is required to activate the new scheduler now
  end

  true
end

- (Object) GetIOScheduler

Kernel param 'elevator'



167
168
169
# File '../../src/modules/SystemSettings.rb', line 167

def GetIOScheduler
  @elevator
end

- (Object) GetPossibleElevatorValues



31
32
33
34
# File '../../src/modules/SystemSettings.rb', line 31

def GetPossibleElevatorValues
  # here are listed all known values of the 'elevator' variable
  ["cfq", "noop", "deadline"]
end

- (Object) GetSysRqKeysEnabled



189
190
191
# File '../../src/modules/SystemSettings.rb', line 189

def GetSysRqKeysEnabled
  @ENABLE_SYSRQ != nil && @ENABLE_SYSRQ != "0"
end

- (Object) main



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File '../../src/modules/SystemSettings.rb', line 16

def main
  textdomain "tune"

  Yast.import "Service"
  Yast.import "Mode"

  # Internal Data
  @ENABLE_SYSRQ = nil

  @elevator = nil
  # Internal Data

  @modified = false
end

- (Object) Modified



36
37
38
39
# File '../../src/modules/SystemSettings.rb', line 36

def Modified
  Builtins.y2milestone("Modified: %1", @modified)
  @modified
end

- (Object) Read



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File '../../src/modules/SystemSettings.rb', line 41

def Read
  @ENABLE_SYSRQ = Convert.to_string(
    SCR.Read(path(".etc.sysctl_conf.\"kernel.sysrq\""))
  )
  Builtins.y2milestone("SysRq enabled: %1", @ENABLE_SYSRQ)

  current_sysrq = Convert.to_string(
    SCR.Read(path(".target.string"), "/proc/sys/kernel/sysrq")
  )

  # read just the first line
  current_sysrq = Ops.get(Builtins.splitstring(current_sysrq, "\n"), 0, "")

  if @ENABLE_SYSRQ != nil && current_sysrq != @ENABLE_SYSRQ
    Builtins.y2warning(
      "SysRq mismatch: sysconfig value: '%1', current: '%2'",
      @ENABLE_SYSRQ,
      current_sysrq
    )
  end

  # display the current value if it not configured
  @ENABLE_SYSRQ = current_sysrq if @ENABLE_SYSRQ == nil

  # I have to admit that this is very ugly but it is here
  # to avoid of the very long starting time of the yast module
  # because the Storage module (which is imported by the Bootloader (imported by the SystemSettings module))
  # has a Read() function call in its constructor.
  Yast.import "Bootloader"

  if Mode.normal
    # runtime - read the settings
    Bootloader.Read
  end

  # get 'elevator' option from the default section
  elevator_parameter = Bootloader.kernel_param(:common, "elevator")

  Builtins.y2milestone("elevator_parameter: %1", elevator_parameter)

  # Variable is not set
  if elevator_parameter == :missing
    @elevator = ""
    # Variable is set but has not parameter
  elsif elevator_parameter == :present
    Builtins.y2warning("'elevator' variable has to have some value")
    @elevator = ""
    # Variable is set but hasn't any known value
  elsif !Builtins.contains(
      GetPossibleElevatorValues(),
      Convert.to_string(elevator_parameter)
    )
    Builtins.y2warning(
      "'elevator' variable has to have a value from %1 instead of being set to %2",
      GetPossibleElevatorValues(),
      elevator_parameter
    )
    @elevator = ""
    # Variable is OK
  else
    @elevator = Convert.to_string(elevator_parameter)
  end

  Builtins.y2milestone("Global IO scheduler: %1", @elevator)

  true
end

- (Object) SetIOScheduler(io_scheduler)



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File '../../src/modules/SystemSettings.rb', line 171

def SetIOScheduler(io_scheduler)
  # empty string = use the default scheduler
  if Builtins.contains(GetPossibleElevatorValues(), io_scheduler) ||
      io_scheduler == ""
    @modified = true if @elevator != io_scheduler

    @elevator = io_scheduler
  else
    Builtins.y2error(
      "unknown IO scheduler '%1', use: %2",
      io_scheduler,
      GetPossibleElevatorValues()
    )
  end

  nil
end

- (Object) SetSysRqKeysEnabled(enable_sysrq)



193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# File '../../src/modules/SystemSettings.rb', line 193

def SetSysRqKeysEnabled(enable_sysrq)
  if enable_sysrq == nil
    Builtins.y2warning("enable_sysrq should be 'true' or 'false'")
    return
  end

  enable_sysrq_string = enable_sysrq ? "1" : "0"

  @modified = true if @ENABLE_SYSRQ != enable_sysrq_string

  @ENABLE_SYSRQ = enable_sysrq_string
  Builtins.y2milestone("SysRq was set to %1", @ENABLE_SYSRQ)

  nil
end

- (Object) Write



139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File '../../src/modules/SystemSettings.rb', line 139

def Write
  # writing SysRq settings
  if @ENABLE_SYSRQ != nil && Builtins.regexpmatch(@ENABLE_SYSRQ, "^[0-9]+$")
    # save the SysRq setting
    Builtins.y2milestone("Saving ENABLE_SYSRQ: %1", @ENABLE_SYSRQ)
    SCR.Write(path(".etc.sysctl_conf.\"kernel.sysrq\""), @ENABLE_SYSRQ)
    SCR.Write(path(".etc.sysctl_conf"), nil)
  else
    Builtins.y2warning(
      "Not writing invalid ENABLE_SYSRQ value: %1",
      @ENABLE_SYSRQ
    )
  end

  # enable boot.sysctl service which sets the value after boot
  Service.Enable("boot.sysctl")

  # the bootloader configuration is written at the end of the first stage
  if Mode.normal
    # write the elevator setting
    Yast.import "Bootloader"
    Bootloader.Write
  end

  true
end