Skip to content

Commit

Permalink
fix: stop server as user on install
Browse files Browse the repository at this point in the history
Signed-off-by: Toma Puljak <[email protected]>
  • Loading branch information
Tpuljak committed Oct 1, 2024
1 parent 381118a commit c2d1730
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions hack/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,25 @@ err() {
exit 1
}

# Get the user that is running the Daytona server
get_daytona_server_user() {
local user
user=$(ps aux | grep 'daytona serve' | grep -v 'grep' | awk '{print $1}' | head -n 1)

if [ -z "$user" ]; then
echo "Error: daytona serve process not found" >&2
return 1
fi

echo "$user"
}

# Stop the Daytona server if it is running
stop_daytona_server() {
if pgrep -f "daytona serve" >/dev/null; then
local pid
pid=$(pgrep -f "daytona serve" | head -n 1)

if [ ! -z "$pid" ]; then
if [ "$CONFIRM_FLAG" = false ]; then
read -p "Daytona server is running. Do you want to stop it? (yes/no): " user_input </dev/tty
case $user_input in
Expand All @@ -51,12 +67,18 @@ stop_daytona_server() {

if [ "$CONFIRM_FLAG" = true ]; then
echo "Attempting to stop the Daytona server..."
if daytona server stop; then
echo -e "Stopping the Daytona server"
user=$(get_daytona_server_user)
if sudo -H -E -u $user bash -c 'daytona server stop'; then
echo "Daytona server stopped successfully."
else
pkill -f "daytona serve"
echo "Failed to stop Daytona server gracefully. Attempting force stop..."
if kill -9 $pid; then
echo "Daytona server forcefully stopped."
else
echo "Failed to stop Daytona server. Please stop it manually and rerun the script."
exit 1
fi
fi
echo -e "Daytona server stopped.\n"
fi
fi
}
Expand Down

0 comments on commit c2d1730

Please sign in to comment.