-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathbuild
More file actions
executable file
·83 lines (70 loc) · 2.44 KB
/
build
File metadata and controls
executable file
·83 lines (70 loc) · 2.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
# DISCLAIMER - this script was mostly written by *AI* because it's only for
# my local dev use...but it does the job.
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Configuration
BUILD_DIR="$HOME/dev/skystats/build"
PID_FILE="${BUILD_DIR}/skystats.pid"
LOG_FILE="${BUILD_DIR}/skystats.log"
BINARY_NAME="skystats-daemon"
echo -e "${GREEN}Starting development build process...${NC}"
# Create build directory if it doesn't exist
if [ ! -d "$BUILD_DIR" ]; then
echo -e "${YELLOW}Creating build directory...${NC}"
mkdir -p "$BUILD_DIR"
fi
# Kill existing daemon if running
if [ -f "$PID_FILE" ]; then
PID=$(cat "$PID_FILE" 2>/dev/null)
if [ ! -z "$PID" ] && kill -0 "$PID" 2>/dev/null; then
echo -e "${YELLOW}Killing existing daemon (PID: $PID)...${NC}"
kill "$PID"
# Give it a moment to shut down gracefully
sleep 1
# Force kill if still running
if kill -0 "$PID" 2>/dev/null; then
echo -e "${YELLOW}Force killing daemon...${NC}"
kill -9 "$PID" 2>/dev/null
fi
else
echo -e "${YELLOW}PID file exists but process not running${NC}"
fi
else
echo -e "${YELLOW}No existing daemon found${NC}"
fi
# Remove existing log file
if [ -f "$LOG_FILE" ]; then
echo -e "${YELLOW}Removing existing log file...${NC}"
rm "$LOG_FILE"
fi
# Get build information
VERSION="dev"
BRANCH=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "unknown")
SHORT_SHA=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown")
COMMIT="${BRANCH}-${SHORT_SHA}"
DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
echo -e "${GREEN}Building with:${NC}"
echo " Version: ${VERSION}"
echo " Commit: ${COMMIT}"
echo " Date: ${DATE}"
# Build the daemon with ldflags
echo -e "${GREEN}Building ${BINARY_NAME}...${NC}"
cd $HOME/dev/skystats && go build -ldflags "-s -w -X main.version=${VERSION} -X main.commit=${COMMIT} -X main.date=${DATE}" -o "${BUILD_DIR}/${BINARY_NAME}" ./core
if [ $? -ne 0 ]; then
echo -e "${RED}Build failed!${NC}"
return 1 2>/dev/null || exit 1
fi
echo -e "${GREEN}Build successful!${NC}"
# Run the daemon from build directory (it will daemonize itself)
echo -e "${GREEN}Starting ${BINARY_NAME}...${NC}"
cd "${BUILD_DIR}" && ./"${BINARY_NAME}"
if [ $? -eq 0 ]; then
echo -e "${GREEN}Daemon started successfully${NC}"
else
echo -e "${RED}Failed to start daemon${NC}"
return 1 2>/dev/null || exit 1
fi