Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
A
Application
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AdvancedWeb
Application
Commits
53082c0a
Commit
53082c0a
authored
3 months ago
by
Davison, Ben J (UG - Comp Sci & Elec Eng)
Browse files
Options
Downloads
Patches
Plain Diff
Delete run_application.py
parent
cc414cbe
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
run_application.py
+0
-123
0 additions, 123 deletions
run_application.py
with
0 additions
and
123 deletions
run_application.py
deleted
100644 → 0
+
0
−
123
View file @
cc414cbe
#!/usr/bin/env python
# run_all_services.py - Script to run all microservices simultaneously
import
subprocess
import
threading
import
time
import
os
import
sys
import
webbrowser
import
signal
import
atexit
# Store processes to terminate them properly on exit
processes
=
[]
def
run_service
(
command
,
service_name
):
"""
Run a service with the given command and track its process
"""
print
(
f
"
Starting
{
service_name
}
...
"
)
try
:
# Using shell=True for Windows compatibility
process
=
subprocess
.
Popen
(
command
,
shell
=
True
)
processes
.
append
((
process
,
service_name
))
# Wait for process to complete (should not happen unless killed)
process
.
wait
()
except
Exception
as
e
:
print
(
f
"
Error running
{
service_name
}
:
{
e
}
"
)
def
clean_up
():
"""
Terminate all running processes and stop Docker services.
"""
print
(
"
\n
Shutting down all services...
"
)
# Stop Docker Compose services
docker_services
=
[
(
"
Users Service
"
,
"
microservice-users
"
),
(
"
Events Service
"
,
"
microservice-events
"
),
(
"
Reviews Service
"
,
"
microservice-reviews
"
),
(
"
Recommendation Service
"
,
"
microservice-recommendation
"
),
(
"
API Gateway
"
,
"
api-gateway
"
),
(
"
Frontend
"
,
"
frontend
"
)
]
for
service_name
,
service_dir
in
docker_services
:
print
(
f
"
Stopping
{
service_name
}
...
"
)
try
:
subprocess
.
run
(
f
"
cd
{
service_dir
}
&& docker-compose down
"
,
shell
=
True
,
check
=
True
)
except
Exception
as
e
:
print
(
f
"
Error stopping
{
service_name
}
:
{
e
}
"
)
# Terminate Python-based services
for
process
,
service_name
in
processes
:
print
(
f
"
Terminating
{
service_name
}
...
"
)
try
:
process
.
terminate
()
process
.
wait
(
timeout
=
5
)
# Ensure process is stopped
except
Exception
as
e
:
print
(
f
"
Error terminating
{
service_name
}
:
{
e
}
"
)
print
(
"
All services shut down.
"
)
def
open_browser
():
"""
Open browser to the frontend after a short delay
"""
time
.
sleep
(
5
)
# Give services a moment to start (increased from 3 to 5)
print
(
"
Opening browser to frontend...
"
)
webbrowser
.
open
(
"
http://localhost:5173/
"
)
def
get_python_command
():
"""
Get the appropriate python command for the current system
"""
# On some systems, 'python' points to Python 2 and 'python3' to Python 3
if
sys
.
version_info
[
0
]
>=
3
:
return
'
python
'
if
sys
.
platform
.
startswith
(
'
win
'
)
else
'
python3
'
return
'
python
'
if
__name__
==
"
__main__
"
:
# Register cleanup function to run on exit
atexit
.
register
(
clean_up
)
signal
.
signal
(
signal
.
SIGINT
,
lambda
sig
,
frame
:
sys
.
exit
(
0
))
python_cmd
=
get_python_command
()
# Define the directory structure - adjust these paths to match your setup
base_dir
=
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
users_dir
=
os
.
path
.
join
(
base_dir
,
"
microservice-users
"
)
events_dir
=
os
.
path
.
join
(
base_dir
,
"
microservice-events
"
)
gateway_dir
=
os
.
path
.
join
(
base_dir
,
"
api-gateway
"
)
frontend_dir
=
os
.
path
.
join
(
base_dir
,
"
frontend
"
)
reviews_dir
=
os
.
path
.
join
(
base_dir
,
"
microservice-reviews
"
)
recommendation_dir
=
os
.
path
.
join
(
base_dir
,
"
microservice-recommendation
"
)
# Define commands for each service
commands
=
[
(
f
"
cd
{
users_dir
}
&& docker-compose up -d
"
,
"
Users Service
"
),
(
f
"
cd
{
events_dir
}
&& docker compose up -d
"
,
"
Events Service
"
),
# (f"cd {gateway_dir} && {python_cmd} -m uvicorn main:app --reload --port 8000", "API Gateway"),
(
f
"
cd
{
gateway_dir
}
&& docker compose up -d
"
,
"
API Gateway
"
),
(
f
"
cd
{
reviews_dir
}
&& docker-compose up -d
"
,
"
Reviews Service
"
),
(
f
"
cd
{
recommendation_dir
}
&& docker-compose up -d
"
,
"
Recommendation Service
"
),
(
f
"
cd
{
frontend_dir
}
&& docker compose up -d
"
,
"
Frontend
"
)
]
# Create and start threads for each service
threads
=
[]
for
command
,
service_name
in
commands
:
thread
=
threading
.
Thread
(
target
=
run_service
,
args
=
(
command
,
service_name
))
thread
.
daemon
=
True
# Allow the program to exit even if threads are running
threads
.
append
(
thread
)
thread
.
start
()
time
.
sleep
(
7
)
# Increased to give each service more time to start
# Open browser after a short delay
browser_thread
=
threading
.
Thread
(
target
=
open_browser
)
browser_thread
.
daemon
=
True
browser_thread
.
start
()
print
(
"
All services started. Press Ctrl+C to stop all services.
"
)
try
:
# Keep the main thread alive to receive keyboard interrupts
while
True
:
time
.
sleep
(
1
)
except
KeyboardInterrupt
:
print
(
"
\n
Received keyboard interrupt
"
)
# The atexit handler will clean up processes
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment