Skip to content

Commit

Permalink
mac
Browse files Browse the repository at this point in the history
  • Loading branch information
laoshanxi committed Nov 28, 2024
1 parent d69a544 commit 8c7b4df
Show file tree
Hide file tree
Showing 4 changed files with 200 additions and 20 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,13 @@ link_directories(
/usr/local/lib
)

##########################################################################
# include dir
##########################################################################
include_directories(
/usr/local/include
)

##########################################################################
# sub dir
##########################################################################
Expand Down
6 changes: 3 additions & 3 deletions autogen.sh
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ if [ true ]; then
tar zxvf boost_1_${BOOST_VER}_0.tar.gz >/dev/null
cd ./boost_1_${BOOST_VER}_0
./bootstrap.sh --without-libraries=atomic,context,coroutine,exception,locale,log,math,python,random,serialization,mpi,test,wave,container,graph,graph_parallel,chrono,contract,json,nowide,stacktrace,type_erasure
./b2 -j4
./b2 -j"$(nproc)"
./b2 install >/dev/null
ls -al /usr/local/lib/libboost_system.so.1.${BOOST_VER}.0 /usr/local/include/boost/thread.hpp
fi
Expand Down Expand Up @@ -190,10 +190,10 @@ if [ true ]; then
cp ace/config-linux.h ace/config.h
cp include/makeinclude/platform_linux.GNU include/makeinclude/platform_macros.GNU
cd ${ACE_ROOT}/ace
make ssl=1 -j6
make ssl=1 -j"$(nproc)"
make install ssl=1 INSTALL_PREFIX=/usr/local
# cd ${ACE_ROOT}/protocols/ace
# make ssl=1 -j6
# make ssl=1 -j"$(nproc)"
# make install ssl=1 INSTALL_PREFIX=/usr/local
ls -al /usr/local/lib*/libACE.so
fi
Expand Down
168 changes: 168 additions & 0 deletions autogen.sh.mac.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
#!/usr/bin/env bash
################################################################################
## This script is used to install all 3rd-party dependency libraries for macOS
################################################################################
set -x
set -e
WGET_A="wget --continue --quiet --backups=1 --tries=30 --no-check-certificate"

# Detect architecture
architecture="arm64"
case $(uname -m) in
x86_64) architecture="amd64" ;;
arm64) architecture="arm64" ;;
esac

SRC_DIR=$(dirname $(readlink -f "$0"))
export ROOTDIR=$(pwd)/appmesh.tmp
mkdir -p ${ROOTDIR}
cd ${ROOTDIR}

# Install Xcode Command Line Tools if not installed
if ! command -v xcode-select &>/dev/null; then
xcode-select --install
fi

# Install Homebrew if not installed
if ! command -v brew &>/dev/null; then
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# brew config
# cd "$(brew --repo)" && git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
# brew update
# brew config
fi

# Install wget for consistency with other scripts
brew install wget

# Install basic build tools
brew install cmake
# brew install git

# Install core libraries
brew install openssl@3
brew install boost
brew install curl
brew install log4cpp

# Install security-related libraries
brew install openldap
brew install cryptopp
brew install oath-toolkit

# Install go-lang
brew install go
go version

# Install additional libraries
brew install curlpp
brew install yaml-cpp
brew install nlohmann-json
brew install msgpack-cxx

# Set up environment variables
export OPENSSL_ROOT_DIR=$(brew --prefix openssl@3)
export OPENSSL_INCLUDE_DIR=$OPENSSL_ROOT_DIR/include
export OPENSSL_LIB_DIR=$OPENSSL_ROOT_DIR/lib

# build ACE
if [ true ]; then
$WGET_A https://github.com/DOCGroup/ACE_TAO/releases/download/ACE%2BTAO-7_1_2/ACE-7.1.2.tar.gz
tar zxvf ACE-7.1.2.tar.gz >/dev/null
cd ACE_wrappers
export ACE_ROOT=$(pwd)
export SSL_ROOT=$OPENSSL_ROOT_DIR
echo '#include "ace/config-macosx.h"' >$ACE_ROOT/ace/config.h
echo 'include $(ACE_ROOT)/include/makeinclude/platform_macosx.GNU' >$ACE_ROOT/include/makeinclude/platform_macros.GNU
cd $ACE_ROOT/ace
make ssl=1 -j"$(nproc)"
make install ssl=1 INSTALL_PREFIX=/usr/local
# cd $ACE_ROOT/protocols/ace
# make ssl=1 -j"$(nproc)"
# make install ssl=1 INSTALL_PREFIX=/usr/local
ls -al /usr/local/lib*/libACE.dylib
fi

# Install Python packages
if ! command -v python3 &>/dev/null; then
brew install python3
fi
python3 -m pip install --upgrade pip
python3 -m pip install msgpack requests requests_toolbelt aniso8601 twine wheel

# Go environment setup
export GO111MODULE=on
export GOBIN=/usr/local/bin

# Install Go tools
go install github.com/cloudflare/cfssl/cmd/cfssl@latest
go install github.com/cloudflare/cfssl/cmd/cfssljson@latest
go install github.com/goreleaser/nfpm/v2/cmd/nfpm@latest

cd ${ROOTDIR}

# Install header-only and source libraries
# hashidsxx
git clone --depth=1 https://github.com/schoentoon/hashidsxx.git
sudo cp -rf hashidsxx /usr/local/include/hashidsxx

# croncpp
git clone --depth=1 https://github.com/mariusbancila/croncpp.git
sudo cp croncpp/include/croncpp.h /usr/local/include/

# wildcards
git clone --depth=1 https://github.com/laoshanxi/wildcards.git
sudo cp -rf wildcards/single_include/ /usr/local/include/wildcards

# prometheus-cpp
sudo mkdir -p /usr/local/src/
git clone --depth=1 https://github.com/jupp0r/prometheus-cpp.git
sudo cp -rf prometheus-cpp/core/src /usr/local/src/prometheus
sudo cp -rf prometheus-cpp/core/include/prometheus /usr/local/include/
sudo tee /usr/local/include/prometheus/detail/core_export.h <<EOF
#ifndef PROMETHEUS_CPP_CORE_EXPORT
#define PROMETHEUS_CPP_CORE_EXPORT
#endif
EOF

# jwt-cpp
git clone --depth=1 https://github.com/Thalhammer/jwt-cpp.git
sudo cp -rf jwt-cpp/include/jwt-cpp /usr/local/include/

# ldap-cpp
git clone --depth=1 https://github.com/AndreyBarmaley/ldap-cpp.git
cd ldap-cpp
mkdir build
cd build
cmake -DBUILD_SHARED_LIBS=OFF ..
make
sudo make install
cd ${ROOTDIR}

# QR-Code-generator
git clone --depth=1 https://github.com/nayuki/QR-Code-generator.git
cd QR-Code-generator/cpp
sudo cp qrcodegen.* /usr/local/include/
make
sudo cp libqrcodegencpp.a /usr/local/lib/
cd ${ROOTDIR}

# Catch2
git clone --depth=1 -b v2.x https://github.com/catchorg/Catch2.git
sudo cp Catch2/single_include/catch2/catch.hpp /usr/local/include/

# Clean up
go clean -cache
go clean -fuzzcache
go clean --modcache
pip3 cache purge

# Return to source directory and build
cd $SRC_DIR
mkdir -p b
cd b
cmake ..
make agent

# Clean up temporary directory
rm -rf ${ROOTDIR}
39 changes: 22 additions & 17 deletions src/sdk/agent/cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"errors"
"os"
"syscall"
"time"
Expand All @@ -18,25 +19,27 @@ const (

var logger = utils.GetLogger()

func monitorParentExit(parentPID int) {
if err := setPDeathSignal(); err != nil {
logger.Errorf("Failed to set parent death signal: %v", err)
func monitorParentExit() {
parentPID := os.Getppid()
if parentPID <= 1 {
// No valid parent process to monitor (e.g., init/systemd is the parent).
return
}

for {
if os.Getppid() != parentPID {
logger.Fatal("Parent process exited, shutting down")
}
time.Sleep(parentCheckInterval)
}
}
ticker := time.NewTicker(parentCheckInterval)
defer ticker.Stop()

func setPDeathSignal() error {
_, _, errno := syscall.RawSyscall(uintptr(syscall.SYS_PRCTL), uintptr(syscall.PR_SET_PDEATHSIG), uintptr(syscall.SIGKILL), 0)
if errno != 0 {
return errno
for range ticker.C {
// Use kill with signal 0 to check parent existence.
if err := syscall.Kill(parentPID, 0); err != nil {
if errors.Is(err, syscall.ESRCH) {
// Parent process does not exist.
logger.Fatal("Parent process exited, shutting down")
}
// Log unexpected errors and continue checking.
logger.Errorf("Unexpected error checking parent process: %v", err)
}
}
return nil
}

func startServices() {
Expand Down Expand Up @@ -83,6 +86,8 @@ func main() {
startServices()

// Start parent process monitoring
parentPID := os.Getppid()
monitorParentExit(parentPID)
go monitorParentExit()

// Block the program indefinitely.
select {}
}

0 comments on commit 8c7b4df

Please sign in to comment.