diff --git a/Makefile b/Makefile index e457db4..4d052d3 100644 --- a/Makefile +++ b/Makefile @@ -2,9 +2,9 @@ OS := $(shell uname -s) PG_DSN ?= postgres://user:password@127.0.0.1:5432/postgres .PHONY: install install-openresty install-redis install-postgresql install-pgvector init-db \ - build build-server build-homepage build-panel \ - start start-server start-homepage start-panel \ - stop stop-server stop-homepage stop-panel restart + build build-server build-homepage build-panel \ + start start-openresty start-server start-homepage start-panel \ + stop stop-server stop-homepage stop-panel stop-openresty restart # ----------------------------------------------------------------------------- # Dependency installation @@ -24,41 +24,45 @@ ifeq ($(OS),Darwin) cd .. && rm -rf GeoIP-1.6.12 GeoIP-1.6.12.tar.gz @echo "Trying Homebrew build of OpenResty with GeoIP..." - env CPPFLAGS="-I/opt/homebrew/geoip/include" \ - LDFLAGS="-L/opt/homebrew/geoip/lib" \ - brew install --build-from-source openresty/brew/openresty || \ - (echo "Homebrew failed, falling back to manual source build..." && \ - curl -LO https://openresty.org/download/openresty-1.27.1.2.tar.gz && \ - tar zxvf openresty-1.27.1.2.tar.gz && \ - cd openresty-1.27.1.2 && \ - ./configure \ - --prefix=/opt/homebrew/openresty \ - --with-http_geoip_module \ - --with-cc-opt="-I/opt/homebrew/geoip/include" \ - --with-ld-opt="-L/opt/homebrew/geoip/lib" && \ - make -j$(CORES) && \ - sudo make install && \ - cd .. && rm -rf openresty-1.27.1.2 openresty-1.27.1.2.tar.gz) + env CPPFLAGS="-I/opt/homebrew/geoip/include" \ + LDFLAGS="-L/opt/homebrew/geoip/lib" \ + brew install --build-from-source openresty/brew/openresty || \ + (echo "Homebrew failed, falling back to manual source build..." && \ + curl -LO https://openresty.org/download/openresty-1.27.1.2.tar.gz && \ + tar zxvf openresty-1.27.1.2.tar.gz && \ + cd openresty-1.27.1.2 && \ + ./configure \ + --prefix=/opt/homebrew/openresty \ + --with-http_geoip_module \ + --with-cc-opt="-I/opt/homebrew/geoip/include" \ + --with-ld-opt="-L/opt/homebrew/geoip/lib" && \ + make -j$(CORES) && \ + sudo make install && \ + cd .. && rm -rf openresty-1.27.1.2 openresty-1.27.1.2.tar.gz) + @$(MAKE) start-openresty else - @echo "Detected Linux. Installing via apt..." - sudo apt-get update && \ - sudo apt-get install -y openresty || echo "Please install OpenResty manually." + @echo "Detected Linux. Installing via apt..." + sudo apt-get update && \ + sudo apt-get install -y openresty || echo "Please install OpenResty manually." + @$(MAKE) start-openresty endif install-redis: ifeq ($(OS),Darwin) - brew install redis + brew install redis && brew services start redis else - sudo apt-get update && \ - sudo apt-get install -y redis-server + sudo apt-get update && \ + sudo apt-get install -y redis-server && \ + sudo systemctl enable --now redis-server endif install-postgresql: ifeq ($(OS),Darwin) - brew install postgresql + brew install postgresql && brew services start postgresql else - sudo apt-get update && \ - sudo apt-get install -y postgresql postgresql-contrib + sudo apt-get update && \ + sudo apt-get install -y postgresql postgresql-contrib && \ + sudo systemctl enable --now postgresql endif install-pgvector: @@ -96,7 +100,7 @@ build-panel: # Run targets # ----------------------------------------------------------------------------- -start: start-server start-homepage start-panel +start: start-openresty start-server start-homepage start-panel start-server: $(MAKE) -C server start @@ -107,7 +111,7 @@ start-homepage: start-panel: $(MAKE) -C ui/panel start -stop: stop-server stop-homepage stop-panel +stop: stop-server stop-homepage stop-panel stop-openresty stop-server: $(MAKE) -C server stop @@ -116,7 +120,37 @@ stop-homepage: $(MAKE) -C ui/homepage stop stop-panel: - $(MAKE) -C ui/panel stop + $(MAKE) -C ui/panel stop + +start-openresty: +ifeq ($(OS),Darwin) + @brew services start openresty >/dev/null 2>&1 || \ + (echo "Creating LaunchAgent for OpenResty..." && \ + mkdir -p ~/Library/LaunchAgents && \ + printf '%s\n' '' \ + '' \ + '' \ + ' Labelhomebrew.mxcl.openresty' \ + ' ProgramArguments' \ + ' ' \ + ' /opt/homebrew/openresty/nginx/sbin/nginx' \ + ' -g' \ + ' daemon off;' \ + ' ' \ + ' RunAtLoad' \ + '' \ + > ~/Library/LaunchAgents/homebrew.mxcl.openresty.plist && \ + brew services start ~/Library/LaunchAgents/homebrew.mxcl.openresty.plist) +else + sudo systemctl enable --now openresty +endif + +stop-openresty: +ifeq ($(OS),Darwin) + -brew services stop openresty >/dev/null 2>&1 +else + -sudo systemctl stop openresty >/dev/null 2>&1 +endif restart: stop start