srinetwork commited on
Commit
aefd890
Β·
verified Β·
1 Parent(s): 112315d

Update Dockerfile

Browse files
Files changed (1) hide show
  1. Dockerfile +33 -6
Dockerfile CHANGED
@@ -8,8 +8,13 @@ RUN apt-get update && apt-get install -y \
8
  git \
9
  procps \
10
  psmisc \
 
11
  && rm -rf /var/lib/apt/lists/*
12
 
 
 
 
 
13
  # Install Python dependencies
14
  RUN pip3 install flask flask-sock psutil requests --break-system-packages
15
 
@@ -25,6 +30,7 @@ cd /app
25
  echo "=========================================="
26
  echo "πŸš€ Starting Minecraft Server with Web Terminal"
27
  echo "⏰ $(date)"
 
28
  echo "=========================================="
29
 
30
  # Kill any existing processes on port 7860
@@ -217,7 +223,8 @@ import requests
217
  from flask import Flask, render_template_string
218
  from flask_sock import Sock
219
  import psutil
220
- from datetime import datetime
 
221
 
222
  app = Flask(__name__)
223
  sock = Sock(app)
@@ -235,6 +242,19 @@ UPTIME_FILE = "/app/logs/server_start_time.txt"
235
  GITHUB_TOKEN = os.environ.get('GITHUB_TOKEN', '')
236
  GITHUB_REPO = "Walukapah/mcserver"
237
 
 
 
 
 
 
 
 
 
 
 
 
 
 
238
  def load_logs_from_file():
239
  """Load previous logs from local file"""
240
  global logs_history
@@ -286,7 +306,7 @@ def push_logs_to_github():
286
  encoded_content = base64.b64encode(content.encode()).decode()
287
 
288
  data = {
289
- "message": f"Update logs - {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}",
290
  "content": encoded_content,
291
  "branch": "main"
292
  }
@@ -308,7 +328,7 @@ def load_uptime_from_file():
308
  timestamp = f.read().strip()
309
  if timestamp:
310
  server_start_time = float(timestamp)
311
- print(f"[UPTIME] Loaded start time: {datetime.fromtimestamp(server_start_time)}", flush=True)
312
  except Exception as e:
313
  print(f"[UPTIME] Error loading uptime: {e}", flush=True)
314
  server_start_time = None
@@ -325,7 +345,7 @@ def save_uptime_to_file():
325
  def add_log_line(line):
326
  """Add a log line to history and save"""
327
  global logs_history
328
- timestamp = datetime.now().strftime('%H:%M:%S')
329
  log_entry = f"[{timestamp}] {line}"
330
  logs_history.append(log_entry)
331
  if len(logs_history) > 1000:
@@ -1120,6 +1140,10 @@ HTML_TEMPLATE = """
1120
  <span class="status-label-modal">Server Address</span>
1121
  <span class="status-value-modal" id="modalAddress">--</span>
1122
  </div>
 
 
 
 
1123
  </div>
1124
  </div>
1125
 
@@ -1631,7 +1655,9 @@ def index():
1631
  def health():
1632
  return {
1633
  'status': 'running',
1634
- 'minecraft': mc_process is not None and mc_process.poll() is None
 
 
1635
  }
1636
 
1637
  @sock.route('/ws')
@@ -1731,7 +1757,7 @@ if __name__ == '__main__':
1731
  load_logs_from_file()
1732
  load_uptime_from_file()
1733
 
1734
- print("[MAIN] Starting web server...", flush=True)
1735
 
1736
  mc_thread = threading.Thread(target=start_minecraft, daemon=True)
1737
  mc_thread.start()
@@ -1772,6 +1798,7 @@ echo "πŸ“Š Status modal with heartbeat icon added"
1772
  echo "☁️ GitHub Auto-backup every 5 minutes"
1773
  echo "πŸ”§ Manual backup button added to sidebar"
1774
  echo "πŸ”„ Pull-before-push conflict resolution"
 
1775
  echo "=========================================="
1776
 
1777
  # Keep container alive
 
8
  git \
9
  procps \
10
  psmisc \
11
+ tzdata \
12
  && rm -rf /var/lib/apt/lists/*
13
 
14
+ # Set Sri Lankan Timezone (Asia/Colombo, UTC+5:30)
15
+ ENV TZ=Asia/Colombo
16
+ RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
17
+
18
  # Install Python dependencies
19
  RUN pip3 install flask flask-sock psutil requests --break-system-packages
20
 
 
30
  echo "=========================================="
31
  echo "πŸš€ Starting Minecraft Server with Web Terminal"
32
  echo "⏰ $(date)"
33
+ echo "🌍 Timezone: $(cat /etc/timezone) | $(date +%Z)"
34
  echo "=========================================="
35
 
36
  # Kill any existing processes on port 7860
 
223
  from flask import Flask, render_template_string
224
  from flask_sock import Sock
225
  import psutil
226
+ from datetime import datetime, timezone, timedelta
227
+ import pytz
228
 
229
  app = Flask(__name__)
230
  sock = Sock(app)
 
242
  GITHUB_TOKEN = os.environ.get('GITHUB_TOKEN', '')
243
  GITHUB_REPO = "Walukapah/mcserver"
244
 
245
+ # Sri Lankan Timezone
246
+ SL_TZ = pytz.timezone('Asia/Colombo')
247
+
248
+ def get_sl_time():
249
+ """Get current time in Sri Lankan timezone"""
250
+ return datetime.now(SL_TZ)
251
+
252
+ def format_sl_time(dt=None, fmt='%Y-%m-%d %H:%M:%S'):
253
+ """Format datetime in Sri Lankan timezone"""
254
+ if dt is None:
255
+ dt = get_sl_time()
256
+ return dt.strftime(fmt)
257
+
258
  def load_logs_from_file():
259
  """Load previous logs from local file"""
260
  global logs_history
 
306
  encoded_content = base64.b64encode(content.encode()).decode()
307
 
308
  data = {
309
+ "message": f"Update logs - {format_sl_time()}",
310
  "content": encoded_content,
311
  "branch": "main"
312
  }
 
328
  timestamp = f.read().strip()
329
  if timestamp:
330
  server_start_time = float(timestamp)
331
+ print(f"[UPTIME] Loaded start time: {datetime.fromtimestamp(server_start_time, SL_TZ)}", flush=True)
332
  except Exception as e:
333
  print(f"[UPTIME] Error loading uptime: {e}", flush=True)
334
  server_start_time = None
 
345
  def add_log_line(line):
346
  """Add a log line to history and save"""
347
  global logs_history
348
+ timestamp = format_sl_time(fmt='%H:%M:%S')
349
  log_entry = f"[{timestamp}] {line}"
350
  logs_history.append(log_entry)
351
  if len(logs_history) > 1000:
 
1140
  <span class="status-label-modal">Server Address</span>
1141
  <span class="status-value-modal" id="modalAddress">--</span>
1142
  </div>
1143
+ <div class="status-item">
1144
+ <span class="status-label-modal">Timezone</span>
1145
+ <span class="status-value-modal" id="modalTimezone">Asia/Colombo (UTC+5:30)</span>
1146
+ </div>
1147
  </div>
1148
  </div>
1149
 
 
1655
  def health():
1656
  return {
1657
  'status': 'running',
1658
+ 'minecraft': mc_process is not None and mc_process.poll() is None,
1659
+ 'timezone': 'Asia/Colombo',
1660
+ 'time': format_sl_time()
1661
  }
1662
 
1663
  @sock.route('/ws')
 
1757
  load_logs_from_file()
1758
  load_uptime_from_file()
1759
 
1760
+ print(f"[MAIN] Starting web server... Timezone: {SL_TZ}", flush=True)
1761
 
1762
  mc_thread = threading.Thread(target=start_minecraft, daemon=True)
1763
  mc_thread.start()
 
1798
  echo "☁️ GitHub Auto-backup every 5 minutes"
1799
  echo "πŸ”§ Manual backup button added to sidebar"
1800
  echo "πŸ”„ Pull-before-push conflict resolution"
1801
+ echo "🌍 Timezone: Asia/Colombo (UTC+5:30) - Sri Lankan Time"
1802
  echo "=========================================="
1803
 
1804
  # Keep container alive