-
Notifications
You must be signed in to change notification settings - Fork 2
added gotty #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
FloSch62
wants to merge
2
commits into
main
Choose a base branch
from
gotty
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
added gotty #7
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
#!/bin/bash | ||
|
||
# GoTTY service management script | ||
# Usage: gotty-service {start|stop|status|restart} [PORT] [USERNAME] [PASSWORD] [SHELL] | ||
|
||
# Default configuration | ||
PORT=${2:-8080} | ||
USERNAME=${3:-admin} | ||
PASSWORD=${4:-admin} | ||
SHELL=${5:-bash} | ||
TITLE="Network Multitool Terminal" | ||
|
||
# Paths | ||
PID_FILE="/var/run/gotty/gotty-${PORT}.pid" | ||
LOG_FILE="/var/log/gotty/gotty-${PORT}.log" | ||
|
||
# Ensure directories exist | ||
mkdir -p /var/run/gotty /var/log/gotty | ||
|
||
check_port() { | ||
if netstat -tuln | grep -q ":$PORT "; then | ||
if [ -f "$PID_FILE" ]; then | ||
PID=$(cat "$PID_FILE") | ||
if ps -p "$PID" > /dev/null; then | ||
# Our GoTTY service is using this port | ||
return 0 | ||
fi | ||
fi | ||
# Another service is using this port | ||
echo "Error: Port $PORT is already in use by another service." | ||
return 1 | ||
fi | ||
return 0 | ||
} | ||
|
||
start_gotty() { | ||
if [ -f "$PID_FILE" ]; then | ||
PID=$(cat "$PID_FILE") | ||
if ps -p "$PID" > /dev/null; then | ||
echo "GoTTY is already running on port $PORT (PID: $PID)" | ||
return 0 | ||
else | ||
# Stale PID file | ||
rm "$PID_FILE" | ||
fi | ||
fi | ||
|
||
check_port || return 1 | ||
|
||
echo "Starting GoTTY service on port $PORT..." | ||
gotty -w -p "$PORT" -c "$USERNAME:$PASSWORD" --title-format "$TITLE" "$SHELL" > "$LOG_FILE" 2>&1 & | ||
|
||
PID=$! | ||
echo $PID > "$PID_FILE" | ||
|
||
# Check if process is still running after a short delay | ||
sleep 1 | ||
if ps -p "$PID" > /dev/null; then | ||
echo "GoTTY service started successfully (PID: $PID)" | ||
echo "Access web terminal at: http://<host-ip>:$PORT" | ||
echo "Username: $USERNAME" | ||
echo "Password: $PASSWORD" | ||
return 0 | ||
else | ||
echo "Failed to start GoTTY service. Check logs at $LOG_FILE" | ||
rm -f "$PID_FILE" | ||
return 1 | ||
fi | ||
} | ||
|
||
stop_gotty() { | ||
if [ -f "$PID_FILE" ]; then | ||
PID=$(cat "$PID_FILE") | ||
if ps -p "$PID" > /dev/null; then | ||
echo "Stopping GoTTY service on port $PORT (PID: $PID)..." | ||
kill "$PID" | ||
|
||
# Wait for process to terminate | ||
for i in {1..5}; do | ||
if ! ps -p "$PID" > /dev/null; then | ||
break | ||
fi | ||
sleep 1 | ||
done | ||
|
||
# Check if process is still running | ||
if ps -p "$PID" > /dev/null; then | ||
echo "GoTTY service did not stop gracefully, forcing termination..." | ||
kill -9 "$PID" | ||
fi | ||
|
||
rm -f "$PID_FILE" | ||
echo "GoTTY service stopped" | ||
else | ||
echo "GoTTY service is not running on port $PORT (stale PID file)" | ||
rm -f "$PID_FILE" | ||
fi | ||
else | ||
echo "GoTTY service is not running on port $PORT" | ||
fi | ||
} | ||
|
||
check_status() { | ||
if [ -f "$PID_FILE" ]; then | ||
PID=$(cat "$PID_FILE") | ||
if ps -p "$PID" > /dev/null; then | ||
echo "GoTTY service is running on port $PORT (PID: $PID)" | ||
echo "Access web terminal at: http://<host-ip>:$PORT" | ||
echo "Username: $USERNAME" | ||
echo "Password: $PASSWORD" | ||
return 0 | ||
else | ||
echo "GoTTY service is not running on port $PORT (stale PID file)" | ||
rm -f "$PID_FILE" | ||
return 1 | ||
fi | ||
else | ||
echo "GoTTY service is not running on port $PORT" | ||
return 1 | ||
fi | ||
} | ||
|
||
restart_gotty() { | ||
stop_gotty | ||
sleep 2 | ||
start_gotty | ||
} | ||
|
||
# Main logic | ||
case "$1" in | ||
start) | ||
start_gotty | ||
;; | ||
stop) | ||
stop_gotty | ||
;; | ||
status) | ||
check_status | ||
;; | ||
restart) | ||
restart_gotty | ||
;; | ||
*) | ||
echo "Usage: $0 {start|stop|status|restart} [PORT] [USERNAME] [PASSWORD] [SHELL]" | ||
echo "Default: PORT=8080, USERNAME=admin, PASSWORD=admin, SHELL=bash" | ||
exit 1 | ||
;; | ||
esac | ||
|
||
exit 0 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's make it multi arch friendly by introducing a build image for gotty that uses
go install
way of installing gottythen you just copy the binary from this build step to the target system
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I changed it so its installed during a build stage and copied from it