Bearsampp 2025.8.29
Loading...
Searching...
No Matches
class.action.service.php
Go to the documentation of this file.
1<?php
2/*
3 * Copyright (c) 2021-2024 Bearsampp
4 * License: GNU General Public License version 3 or later; see LICENSE.txt
5 * Author: Bear
6 * Website: https://bearsampp.com
7 * Github: https://github.com/Bearsampp
8 */
9
15{
16 const CREATE = 'create';
17 const START = 'start';
18 const STOP = 'stop';
19 const RESTART = 'restart';
20
21 const INSTALL = 'install';
22 const REMOVE = 'remove';
23
30 public function __construct($args)
31 {
32 global $bearsamppBins;
34
35 // Reload bins
36 $bearsamppBins->reload();
37
38 if ( isset( $args[0] ) && !empty( $args[0] ) && isset( $args[1] ) && !empty( $args[1] ) ) {
39 $sName = $args[0];
40 $bin = null;
41 $port = 0;
42 $syntaxCheckCmd = null;
43
44 if ( $sName == BinMailpit::SERVICE_NAME ) {
45 $bin = $bearsamppBins->getMailpit();
46 $port = $bin->getSmtpPort();
47 }
48 elseif ( $sName == BinMemcached::SERVICE_NAME ) {
49 $bin = $bearsamppBins->getMemcached();
50 $port = $bin->getPort();
51 }
52 elseif ( $sName == BinApache::SERVICE_NAME ) {
53 $bin = $bearsamppBins->getApache();
54 $port = $bin->getPort();
55 $syntaxCheckCmd = BinApache::CMD_SYNTAX_CHECK;
56 }
57 elseif ( $sName == BinMysql::SERVICE_NAME ) {
58 $bin = $bearsamppBins->getMysql();
59 $port = $bin->getPort();
60 $syntaxCheckCmd = BinMysql::CMD_SYNTAX_CHECK;
61 }
62 elseif ( $sName == BinMariadb::SERVICE_NAME ) {
63 $bin = $bearsamppBins->getMariadb();
64 $port = $bin->getPort();
65 $syntaxCheckCmd = BinMariadb::CMD_SYNTAX_CHECK;
66 }
67 elseif ( $sName == BinPostgresql::SERVICE_NAME ) {
68 $bin = $bearsamppBins->getPostgresql();
69 $port = $bin->getPort();
70 }
71 elseif ( $sName == BinXlight::SERVICE_NAME ) {
72 $bin = $bearsamppBins->getXlight();
73 $port = $bin->getPort();
74 }
75
76 $name = $bin->getName();
77 $service = $bin->getService();
78
79 if ( !empty( $service ) && $service instanceof Win32Service ) {
80 if ( $args[1] == self::CREATE ) {
81 $this->create( $service );
82 }
83 elseif ( $args[1] == self::START ) {
84 $this->start( $bin, $syntaxCheckCmd );
85 }
86 elseif ( $args[1] == self::STOP ) {
87 $this->stop( $service );
88 }
89 elseif ( $args[1] == self::RESTART ) {
90 $this->restart( $bin, $syntaxCheckCmd );
91 }
92 elseif ( $args[1] == self::INSTALL ) {
93 if ( !empty( $port ) ) {
94 $this->install( $bin, $port, $syntaxCheckCmd );
95 }
96 }
97 elseif ( $args[1] == self::REMOVE ) {
98 $this->remove( $service, $name );
99 }
100 }
101 }
102
104 }
105
111 private function create($service)
112 {
113 $service->create();
114 }
115
122 private function start($bin, $syntaxCheckCmd)
123 {
124 Util::startService( $bin, $syntaxCheckCmd, true );
125 }
126
132 private function stop($service)
133 {
134 $service->stop();
135 }
136
143 private function restart($bin, $syntaxCheckCmd)
144 {
145 if ( $bin->getService()->stop() ) {
146 $this->start( $bin, $syntaxCheckCmd );
147 }
148 }
149
157 private function install($bin, $port, $syntaxCheckCmd)
158 {
159 Util::installService( $bin, $port, $syntaxCheckCmd, true );
160 }
161
168 private function remove($service, $name)
169 {
170 Util::removeService( $service, $name );
171 }
172}
global $bearsamppBins
$port
start($bin, $syntaxCheckCmd)
restart($bin, $syntaxCheckCmd)
install($bin, $port, $syntaxCheckCmd)
const CMD_SYNTAX_CHECK
const SERVICE_NAME
const CMD_SYNTAX_CHECK
static installService($bin, $port, $syntaxCheckCmd, $showWindow=false)
static removeService($service, $name)
static startLoading()
static stopLoading()
static startService($bin, $syntaxCheckCmd, $showWindow=false)