| Conditions | 21 |
| Paths | 8192 |
| Total Lines | 191 |
| Code Lines | 121 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 112 | public function startSystem(): bool |
||
| 113 | { |
||
| 114 | // Is the configuration default? |
||
| 115 | // Try restore config... |
||
| 116 | $systemConfiguration = new SystemConfiguration(); |
||
| 117 | if ($systemConfiguration->isDefaultConf() && !$this->isRecoveryMode) { |
||
| 118 | $this->echoStartMsg(' - Try restore backup of settings... '); |
||
| 119 | $systemConfiguration->tryRestoreConf(); |
||
| 120 | $this->echoResultMsg(); |
||
| 121 | } |
||
| 122 | |||
| 123 | // Check if the system is running on T2SDELinux |
||
| 124 | $itIsT2SDELinux = Util::isT2SdeLinux(); |
||
| 125 | |||
| 126 | // Mark the registry as booting |
||
| 127 | System::setBooting(true); |
||
| 128 | |||
| 129 | // Start the ACPID daemon |
||
| 130 | if (!$this->isDocker) { |
||
| 131 | $this->echoStartMsg(PHP_EOL); |
||
| 132 | $this->echoStartMsg(' - Start acpid daemon...'); |
||
| 133 | $ACPIDConf = new ACPIDConf(); |
||
| 134 | $ACPIDStatus = $ACPIDConf->reStart(); |
||
| 135 | $this->echoResultMsg($ACPIDStatus ? SystemMessages::RESULT_DONE : SystemMessages::RESULT_FAILED); |
||
| 136 | } |
||
| 137 | // Start the Beanstalkd daemon |
||
| 138 | $this->echoStartMsg(' - Start beanstalkd daemon...'); |
||
| 139 | $beanstalkConf = new BeanstalkConf(); |
||
| 140 | $beanstalkStatus = $beanstalkConf->reStart(); |
||
| 141 | $this->echoResultMsg($beanstalkStatus ? SystemMessages::RESULT_DONE : SystemMessages::RESULT_FAILED); |
||
| 142 | |||
| 143 | // Start the Redis daemon |
||
| 144 | $this->echoStartMsg(' - Start redis daemon...'); |
||
| 145 | $redisConf = new RedisConf(); |
||
| 146 | $redisStatus = $redisConf->reStart(); |
||
| 147 | $this->echoResultMsg($redisStatus ? SystemMessages::RESULT_DONE : SystemMessages::RESULT_FAILED); |
||
| 148 | |||
| 149 | // Configure Sentry error logger |
||
| 150 | $this->echoStartMsg(' - Configuring sentry error logger ...'); |
||
| 151 | if (!$this->isRecoveryMode) { |
||
| 152 | $sentryConf = new SentryConf(); |
||
| 153 | $sentryConf->configure(); |
||
| 154 | $this->echoResultMsg(); |
||
| 155 | } else { |
||
| 156 | $this->echoResultMsg(SystemMessages::RESULT_SKIPPED); |
||
| 157 | } |
||
| 158 | |||
| 159 | // Configure the system timezone |
||
| 160 | $this->echoStartMsg(' - Configuring timezone...'); |
||
| 161 | if (!$this->isRecoveryMode) { |
||
| 162 | System::timezoneConfigure(); |
||
| 163 | $this->echoResultMsg(); |
||
| 164 | } else { |
||
| 165 | $this->echoResultMsg(SystemMessages::RESULT_SKIPPED); |
||
| 166 | } |
||
| 167 | |||
| 168 | // Configure locales UTF-8 |
||
| 169 | $this->echoStartMsg(' - Start update locales...'); |
||
| 170 | System::setupLocales(); |
||
| 171 | $this->echoResultMsg(); |
||
| 172 | |||
| 173 | // Mount the storage disk |
||
| 174 | $storage = new Storage(); |
||
| 175 | if ($itIsT2SDELinux) { |
||
| 176 | // Do not need to set on Docker or Debian linux |
||
| 177 | $storage->saveFstab(); |
||
| 178 | } |
||
| 179 | $storage->configure(); |
||
| 180 | $this->echoStartMsg(' - Mount storage disk...'); |
||
| 181 | $this->echoResultMsg(); |
||
| 182 | |||
| 183 | // Recreate database connections |
||
| 184 | $this->echoStartMsg(' - Recreate modules database connections...'); |
||
| 185 | ModulesDBConnectionsProvider::recreateModulesDBConnections(); |
||
| 186 | $this->echoResultMsg(); |
||
| 187 | |||
| 188 | // Additional tasks for T2SDELinux |
||
| 189 | if ($itIsT2SDELinux) { |
||
| 190 | $this->echoStartMsg(' - Connect swap...'); |
||
| 191 | Processes::mwExecBg('/etc/rc/connect_swap'); |
||
| 192 | $this->echoResultMsg(); |
||
| 193 | } |
||
| 194 | |||
| 195 | // Start the syslogd daemon |
||
| 196 | $this->echoStartMsg(' - Start syslogd daemon...'); |
||
| 197 | $syslogConf = new SyslogConf(); |
||
| 198 | $syslogStatus = $syslogConf->reStart(); |
||
| 199 | $this->echoResultMsg($syslogStatus ? SystemMessages::RESULT_DONE : SystemMessages::RESULT_FAILED); |
||
| 200 | |||
| 201 | // Update the database structure |
||
| 202 | $dbUpdater = new UpdateDatabase(); |
||
| 203 | $dbUpdater->updateDatabaseStructure(); |
||
| 204 | |||
| 205 | // Create directories required by modules after DB upgrade |
||
| 206 | $this->echoStartMsg(' - Create modules links and folders...'); |
||
| 207 | $storage->createWorkDirsAfterDBUpgrade(); |
||
| 208 | $this->echoResultMsg(); |
||
| 209 | |||
| 210 | // Update the system configuration and applications |
||
| 211 | $this->echoStartMsg(' - Update configs and applications...' . PHP_EOL); |
||
| 212 | $confUpdate = new UpdateSystemConfig(); |
||
| 213 | $confUpdate->updateConfigs(); |
||
| 214 | $this->echoStartMsg(' - Update configs...'); |
||
| 215 | $this->echoResultMsg(); |
||
| 216 | |||
| 217 | // Configure VM tools |
||
| 218 | $this->echoStartMsg(' - Configuring VM tools...'); |
||
| 219 | if (!$this->isRecoveryMode) { |
||
| 220 | $vmwareTools = new VmToolsConf(); |
||
| 221 | $resultVMTools = $vmwareTools->configure(); |
||
| 222 | $this->echoResultMsg((string)$resultVMTools); |
||
| 223 | } else { |
||
| 224 | $this->echoResultMsg(SystemMessages::RESULT_SKIPPED); |
||
| 225 | } |
||
| 226 | |||
| 227 | // Configure the system hostname |
||
| 228 | $this->echoStartMsg(' - Configuring hostname...'); |
||
| 229 | $network = new Network(); |
||
| 230 | $network->hostnameConfigure(); |
||
| 231 | $this->echoResultMsg(); |
||
| 232 | |||
| 233 | // Generate resolv.conf |
||
| 234 | $this->echoStartMsg(' - Configuring resolv.conf...'); |
||
| 235 | $network->resolvConfGenerate(); |
||
| 236 | $this->echoResultMsg(); |
||
| 237 | |||
| 238 | // Configure LAN interface |
||
| 239 | $this->echoStartMsg(' - Configuring LAN interface...'); |
||
| 240 | if ($this->isDocker) { |
||
| 241 | $network->configureLanInDocker(); |
||
| 242 | } else { |
||
| 243 | $network->lanConfigure(); |
||
| 244 | } |
||
| 245 | $this->echoResultMsg(); |
||
| 246 | |||
| 247 | // SSL rehash |
||
| 248 | $this->echoStartMsg(' - SSL rehash...'); |
||
| 249 | System::sslRehash(); |
||
| 250 | $this->echoResultMsg(); |
||
| 251 | |||
| 252 | // Configure the firewall |
||
| 253 | $this->echoStartMsg(' - Configuring Firewall...'); |
||
| 254 | $firewall = new IptablesConf(); |
||
| 255 | $firewall->applyConfig(); |
||
| 256 | $this->echoResultMsg(); |
||
| 257 | |||
| 258 | // Configure NTP |
||
| 259 | $this->echoStartMsg(' - Configuring ntpd...'); |
||
| 260 | if (!$this->isRecoveryMode) { |
||
| 261 | NTPConf::configure(); |
||
| 262 | $this->echoResultMsg(); |
||
| 263 | } else { |
||
| 264 | $this->echoResultMsg(SystemMessages::RESULT_SKIPPED); |
||
| 265 | } |
||
| 266 | |||
| 267 | // Do not need to set Debian SSH service |
||
| 268 | if (!Util::isSystemctl()) { |
||
| 269 | $this->echoStartMsg(' - Configuring SSH console...'); |
||
| 270 | $sshConf = new SSHConf(); |
||
| 271 | $resSsh = $sshConf->configure(); |
||
| 272 | $this->echoResultMsg((string)$resSsh); |
||
| 273 | } |
||
| 274 | |||
| 275 | // Start cloud provisioning |
||
| 276 | if (!$this->isDocker && !$this->isRecoveryMode) { |
||
| 277 | $this->echoStartMsg(' - Attempt to cloud provisioning...' . PHP_EOL); |
||
| 278 | CloudProvisioning::start(); |
||
| 279 | } else { |
||
| 280 | $this->echoStartMsg(' - Attempt to cloud provisioning...'); |
||
| 281 | $this->echoResultMsg(SystemMessages::RESULT_SKIPPED); |
||
| 282 | } |
||
| 283 | |||
| 284 | // Connect storage in a cloud if needed |
||
| 285 | $this->echoStartMsg(' - Auto connect storage for a cloud ...'); |
||
| 286 | if (!$this->isDocker && !$this->isRecoveryMode) { |
||
| 287 | $connectResult = Storage::connectStorageInCloud(); |
||
| 288 | $this->echoResultMsg($connectResult); |
||
| 289 | } else { |
||
| 290 | $this->echoResultMsg(SystemMessages::RESULT_SKIPPED); |
||
| 291 | } |
||
| 292 | |||
| 293 | // Update external IP if needed |
||
| 294 | if (!$this->isRecoveryMode) { |
||
| 295 | $this->echoStartMsg(' - Update external IP...'); |
||
| 296 | $network->updateExternalIp(); |
||
| 297 | $this->echoResultMsg(); |
||
| 298 | } else { |
||
| 299 | $this->echoResultMsg(SystemMessages::RESULT_SKIPPED); |
||
| 300 | } |
||
| 301 | |||
| 302 | return true; |
||
| 303 | } |
||
| 374 |