0
# Core V2ray Management
1
2
Essential service management operations for controlling V2ray/Xray proxy services. Handles service lifecycle, configuration management, version control, and supports both Docker and systemd deployments.
3
4
## Capabilities
5
6
### Service Control
7
8
Start, stop, and restart V2ray/Xray services with automatic status checking and error handling.
9
10
```python { .api }
11
class V2ray:
12
@classmethod
13
def start(cls):
14
"""
15
Start the V2ray/Xray service.
16
17
Detects Docker or systemd environment and uses appropriate commands.
18
Automatically checks status after starting and reports success/failure.
19
"""
20
21
@classmethod
22
def stop(cls):
23
"""
24
Stop the V2ray/Xray service.
25
26
Gracefully stops the service and verifies shutdown.
27
"""
28
29
@classmethod
30
def restart(cls):
31
"""
32
Restart the V2ray/Xray service.
33
34
Performs stop followed by start with status verification.
35
"""
36
```
37
38
### Status and Information
39
40
Check service status and display configuration information.
41
42
```python { .api }
43
@staticmethod
44
def status():
45
"""
46
Check V2ray/Xray service status.
47
48
Reports whether service is active, inactive, or failed.
49
"""
50
51
@staticmethod
52
def info():
53
"""
54
Display current V2ray configuration information.
55
56
Shows configured users, ports, protocols, and connection details
57
including VMess/VLESS connection strings.
58
"""
59
60
@staticmethod
61
def version():
62
"""
63
Display V2ray/Xray version information.
64
65
Shows currently installed version and build information.
66
"""
67
```
68
69
### Configuration Management
70
71
Create, modify, and remove V2ray configurations.
72
73
```python { .api }
74
@classmethod
75
def new(cls):
76
"""
77
Create new V2ray configuration from scratch.
78
79
Generates random ports and selects random mKCP header masquerading.
80
Displays configuration information after creation.
81
"""
82
83
@classmethod
84
def check(cls):
85
"""
86
Check V2ray installation and configuration validity.
87
88
Verifies service installation, configuration file syntax,
89
and required dependencies.
90
"""
91
92
@classmethod
93
def remove(cls):
94
"""
95
Uninstall V2ray/Xray completely.
96
97
Removes service, configuration files, and all related components.
98
"""
99
```
100
101
### Version Management
102
103
Update V2ray/Xray to specific or latest versions.
104
105
```python { .api }
106
@staticmethod
107
def update(version=None):
108
"""
109
Update V2ray/Xray to specified or latest version.
110
111
Parameters:
112
- version (str, optional): Specific version to install.
113
If None, installs latest release.
114
115
Downloads and installs the specified version, preserving
116
existing configuration files.
117
"""
118
```
119
120
### Log Management
121
122
Access and manage V2ray logs for debugging and monitoring.
123
124
```python { .api }
125
@staticmethod
126
def log(error_log=False):
127
"""
128
Display V2ray logs.
129
130
Parameters:
131
- error_log (bool): If True, shows error logs.
132
If False, shows access logs.
133
134
Displays real-time or recent log entries for debugging.
135
"""
136
137
@staticmethod
138
def cleanLog():
139
"""
140
Clean V2ray log files.
141
142
Removes old log files to free disk space.
143
"""
144
```
145
146
### Docker Support
147
148
Specialized methods for Docker deployments.
149
150
```python { .api }
151
@staticmethod
152
def docker_run(command, keyword):
153
"""
154
Execute Docker commands for V2ray container management.
155
156
Parameters:
157
- command (str): Docker command to execute
158
- keyword (str): Operation description for logging
159
160
Executes Docker commands with status monitoring and reporting.
161
"""
162
163
@staticmethod
164
def docker_status():
165
"""
166
Check Docker V2ray container status.
167
168
Returns:
169
bool: True if container is running, False otherwise
170
"""
171
```
172
173
## Usage Examples
174
175
### Basic Service Management
176
177
```python
178
from v2ray_util.util_core.v2ray import V2ray
179
180
# Start the service
181
V2ray.start()
182
183
# Check if it's running
184
V2ray.status()
185
186
# View configuration
187
V2ray.info()
188
189
# Restart service
190
V2ray.restart()
191
```
192
193
### Version Management
194
195
```python
196
# Update to latest version
197
V2ray.update()
198
199
# Update to specific version
200
V2ray.update("4.45.2")
201
202
# Check current version
203
V2ray.version()
204
```
205
206
### Configuration and Logs
207
208
```python
209
# Create new configuration
210
V2ray.new()
211
212
# Check installation
213
V2ray.check()
214
215
# View logs
216
V2ray.log() # Access logs
217
V2ray.log(error_log=True) # Error logs
218
219
# Clean old logs
220
V2ray.cleanLog()
221
```
222
223
## Decorator
224
225
```python { .api }
226
def restart(port_open=False):
227
"""
228
Decorator to automatically restart V2ray after function execution.
229
230
Parameters:
231
- port_open (bool): If True, also opens ports in firewall after restart
232
233
Usage:
234
@restart(port_open=True)
235
def modify_config():
236
# Configuration modifications
237
pass
238
"""
239
```
240
241
## Error Handling
242
243
All service management functions handle common error conditions:
244
245
- Service not installed or not found
246
- Permission denied (requires root/sudo)
247
- Configuration file syntax errors
248
- Network connectivity issues for updates
249
- Docker daemon not running (for Docker deployments)
250
251
Functions provide colored output indicating success (green) or failure (red) status.