mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-12-17 03:27:02 +08:00
feat: save all file
Signed-off-by: Xinwei Xiong(cubxxw-openim) <3293172751nss@gmail.com>
This commit is contained in:
parent
12e0afb4e3
commit
92d8c65aa0
141
deployments/templates/init/README.md
Normal file
141
deployments/templates/init/README.md
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
# Systemd 配置、安装和启动
|
||||||
|
|
||||||
|
- [Systemd 配置、安装和启动](#systemd-配置安装和启动)
|
||||||
|
- [0. 介绍](#0-介绍)
|
||||||
|
- [1. 前置操作(需要 root 权限)](#1-前置操作需要-root-权限)
|
||||||
|
- [2. 创建 openim-api systemd unit 模板文件](#2-创建-openim-api-systemd-unit-模板文件)
|
||||||
|
- [3. 创建 openim-crontask systemd unit 模板文件](#3-创建-openim-crontask-systemd-unit-模板文件)
|
||||||
|
- [6. 复制 systemd unit 模板文件到 sysmted 配置目录(需要有root权限)](#6-复制-systemd-unit-模板文件到-sysmted-配置目录需要有root权限)
|
||||||
|
- [7. 启动 systemd 服务](#7-启动-systemd-服务)
|
||||||
|
|
||||||
|
## 0. 介绍
|
||||||
|
|
||||||
|
systemd是最新linux发行版管理后台的服务的默认形式,用以取代原有的init。
|
||||||
|
|
||||||
|
格式介绍:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
[Unit] :服务单元
|
||||||
|
|
||||||
|
Description:对该服务进行简单的描述
|
||||||
|
|
||||||
|
[Service]:服务运行时行为配置
|
||||||
|
|
||||||
|
ExecStart:程序的完整路径
|
||||||
|
|
||||||
|
Restart:重启配置,no、always、on-success、on-failure、on-abnormal、on-abort、on-watchdog
|
||||||
|
|
||||||
|
[Install]:安装配置
|
||||||
|
|
||||||
|
WantedBy:多用户等
|
||||||
|
```
|
||||||
|
|
||||||
|
更多介绍阅读:https://www.freedesktop.org/software/systemd/man/systemd.service.html
|
||||||
|
|
||||||
|
启动命令:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
systemctl daemon-reload && systemctl enable openim-api && systemctl restart openim-api
|
||||||
|
```
|
||||||
|
|
||||||
|
服务状态:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
systemctl status openim-api
|
||||||
|
```
|
||||||
|
|
||||||
|
停止命令:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
systemctl stop openim-api
|
||||||
|
```
|
||||||
|
|
||||||
|
**为什么选择 systemd?**
|
||||||
|
|
||||||
|
**高级需求:**
|
||||||
|
|
||||||
|
+ 方便分析问题的服务运行日志记录
|
||||||
|
|
||||||
|
+ 服务管理的日志
|
||||||
|
|
||||||
|
+ 异常退出时可以根据需要重新启动
|
||||||
|
|
||||||
|
daemon不能实现上面的高级需求。
|
||||||
|
|
||||||
|
nohup 只能记录服务运行时的输出和出错日志。
|
||||||
|
|
||||||
|
只有systemd能够实现上述所有需求。
|
||||||
|
|
||||||
|
> 默认的日志中增加了时间、用户名、服务名称、PID等,非常人性化。还能看到服务运行异常退出的日志。还能通过/lib/systemd/system/下的配置文件定制各种需求。
|
||||||
|
|
||||||
|
总而言之,systemd是目前linux管理后台服务的主流方式,所以我新版本的 bash 抛弃 nohup,改用 systemd 来管理服务。
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
## 1. 前置操作(需要 root 权限)
|
||||||
|
|
||||||
|
1. 根据注释配置 `environment.sh`
|
||||||
|
|
||||||
|
2. 创建 data 目录
|
||||||
|
|
||||||
|
```
|
||||||
|
mkdir -p ${OPENIM_DATA_DIR}/{openim-api,openim-crontask}
|
||||||
|
```
|
||||||
|
|
||||||
|
3. 创建 bin 目录,并将 `openim-api` 和 `openim-crontask` 可执行文件复制过去
|
||||||
|
|
||||||
|
```bash
|
||||||
|
source ./environment.sh
|
||||||
|
mkdir -p ${OPENIM_INSTALL_DIR}/bin
|
||||||
|
cp openim-api openim-crontask ${OPENIM_INSTALL_DIR}/bin
|
||||||
|
```
|
||||||
|
|
||||||
|
4. 将 `openim-api` 和 `openim-crontask` 配置文件拷贝到 `${OPENIM_CONFIG_DIR}` 目录下
|
||||||
|
|
||||||
|
```bash
|
||||||
|
mkdir -p ${OPENIM_CONFIG_DIR}
|
||||||
|
cp openim-api.yaml openim-crontask.yaml ${OPENIM_CONFIG_DIR}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 2. 创建 openim-api systemd unit 模板文件
|
||||||
|
|
||||||
|
执行如下 shell 脚本生成 `openim-api.service.template`
|
||||||
|
|
||||||
|
```bash
|
||||||
|
source ./environment.sh
|
||||||
|
cat > openim-api.service.template <<EOF
|
||||||
|
[Unit]
|
||||||
|
Description=OpenIM Server API
|
||||||
|
Documentation=https://github.com/marmotedu/iam/blob/master/init/README.md
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
WorkingDirectory=${OPENIM_DATA_DIR}/openim-api
|
||||||
|
ExecStart=${OPENIM_INSTALL_DIR}/bin/openim-api --apiconfig=${OPENIM_CONFIG_DIR}/openim-api.yaml
|
||||||
|
Restart=always
|
||||||
|
RestartSec=5
|
||||||
|
StartLimitInterval=0
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
EOF
|
||||||
|
```
|
||||||
|
|
||||||
|
## 3. 创建 openim-crontask systemd unit 模板文件
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
|
## 6. 复制 systemd unit 模板文件到 sysmted 配置目录(需要有root权限)
|
||||||
|
|
||||||
|
```bash
|
||||||
|
cp openim-api.service.template /etc/systemd/system/openim-api.service
|
||||||
|
cp openim-crontask.service.template /etc/systemd/system/openim-crontask.service
|
||||||
|
...
|
||||||
|
```
|
||||||
|
|
||||||
|
## 7. 启动 systemd 服务
|
||||||
|
|
||||||
|
```bash
|
||||||
|
systemctl daemon-reload && systemctl enable openim-api && systemctl restart openim-api
|
||||||
|
systemctl daemon-reload && systemctl enable openim-crontask && systemctl restart openim-crontask
|
||||||
|
...
|
||||||
|
```
|
||||||
14
deployments/templates/init/openim-api.service
Normal file
14
deployments/templates/init/openim-api.service
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=OpenIM Server API
|
||||||
|
Documentation=https://github.com/marmotedu/iam/blob/master/init/README.md
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
WorkingDirectory=${OPENIM_DATA_DIR}/openim-api
|
||||||
|
ExecStart=${OPENIM_INSTALL_DIR}/bin/openim-api --apiconfig=${OPENIM_CONFIG_DIR}/openim-api.yaml
|
||||||
|
Restart=always
|
||||||
|
RestartSec=5
|
||||||
|
StartLimitInterval=0
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
|
EOF
|
||||||
15
deployments/templates/init/openim-crontask.service
Normal file
15
deployments/templates/init/openim-crontask.service
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
[Unit]
|
||||||
|
Description=OPENIM CRONTASK
|
||||||
|
Documentation=https://github.com/OpenIMSDK/Open-IM-Server/blob/main/deployment/init/README.md
|
||||||
|
|
||||||
|
[Service]
|
||||||
|
WorkingDirectory=${OPENIM_DATA_DIR}/openim-crontask
|
||||||
|
ExecStartPre=/usr/bin/mkdir -p ${OPENIM_DATA_DIR}/openim-crontask
|
||||||
|
ExecStartPre=/usr/bin/mkdir -p ${OPENIM_LOG_DIR}
|
||||||
|
ExecStart=${OPENIM_INSTALL_DIR}/bin/openim-crontask --config=${OPENIM_CONFIG_DIR}/openim-crontask.yaml
|
||||||
|
Restart=always
|
||||||
|
RestartSec=5
|
||||||
|
StartLimitInterval=0
|
||||||
|
|
||||||
|
[Install]
|
||||||
|
WantedBy=multi-user.target
|
||||||
1
deployments/templates/openim-crontask.yaml
Normal file
1
deployments/templates/openim-crontask.yaml
Normal file
@ -0,0 +1 @@
|
|||||||
|
# OpenIM Cronstask
|
||||||
@ -22,7 +22,7 @@ OPENIM_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)"
|
|||||||
|
|
||||||
# 生成文件存放目录
|
# 生成文件存放目录
|
||||||
LOCAL_OUTPUT_ROOT="${OPENIM_ROOT}/${OUT_DIR:-_output}"
|
LOCAL_OUTPUT_ROOT="${OPENIM_ROOT}/${OUT_DIR:-_output}"
|
||||||
source "${OPENIM_ROOT}/scripts/lib/util.sh"
|
source "${OPENIM_ROOT}/scripts/lib/init.sh"
|
||||||
|
|
||||||
IP=$(openim::util::get_server_ip)
|
IP=$(openim::util::get_server_ip)
|
||||||
|
|
||||||
@ -212,7 +212,8 @@ def "THIRD_PROM_PORT" "21301" # Third 服务的 Prometheus 端口
|
|||||||
readonly MSG_TRANSFER_PROM_PORTS=${MSG_TRANSFER_PROM_PORTS:-'21400, 21401, 21402, 21403'}
|
readonly MSG_TRANSFER_PROM_PORTS=${MSG_TRANSFER_PROM_PORTS:-'21400, 21401, 21402, 21403'}
|
||||||
|
|
||||||
###################### OpenIM openim-api ######################
|
###################### OpenIM openim-api ######################
|
||||||
def "OPENIM_API_BINARY" "${LOCAL_OUTPUT_ROOT}/bin/platforms/linux/amd64/openim-api" # OpenIM openim-api 二进制文件路径
|
def "OPENIM_API_HOST" "127.0.0.1"
|
||||||
|
def "OPENIM_API_BINARY" "${OPENIM_OUTPUT_HOSTBIN}/openim-api" # OpenIM openim-api 二进制文件路径
|
||||||
def "OPENIM_API_CONFIG" "${LOCAL_OUTPUT_ROOT}/bin/openim_config.yaml" # OpenIM openim-api 配置文件路径
|
def "OPENIM_API_CONFIG" "${LOCAL_OUTPUT_ROOT}/bin/openim_config.yaml" # OpenIM openim-api 配置文件路径
|
||||||
def "OPENIM_API_LOG_DIR" "${LOG_STORAGE_LOCATION}/openim-api" # OpenIM openim-api 日志存储路径
|
def "OPENIM_API_LOG_DIR" "${LOG_STORAGE_LOCATION}/openim-api" # OpenIM openim-api 日志存储路径
|
||||||
def "OPENIM_API_LOG_LEVEL" "info" # OpenIM openim-api 日志级别
|
def "OPENIM_API_LOG_LEVEL" "info" # OpenIM openim-api 日志级别
|
||||||
@ -223,7 +224,8 @@ def "OPENIM_API_LOG_COMPRESS" "false"
|
|||||||
def "OPENIM_API_LOG_WITH_STACK" "${LOG_WITH_STACK}" # OpenIM openim-api 日志是否带有堆栈信息
|
def "OPENIM_API_LOG_WITH_STACK" "${LOG_WITH_STACK}" # OpenIM openim-api 日志是否带有堆栈信息
|
||||||
|
|
||||||
###################### OpenIM openim-cmdutils ######################
|
###################### OpenIM openim-cmdutils ######################
|
||||||
def "OPENIM_CMDUTILS_BINARY" "${LOCAL_OUTPUT_ROOT}/bin/platforms/linux/amd64/openim-cmdutils" # OpenIM openim-cmdutils 二进制文件路径
|
def "OPENIM_CMDUTILS_HOST" "127.0.0.1"
|
||||||
|
def "OPENIM_CMDUTILS_BINARY" "${OPENIM_OUTPUT_HOSTBIN}/openim-cmdutils" # OpenIM openim-cmdutils 二进制文件路径
|
||||||
def "OPENIM_CMDUTILS_CONFIG" "${LOCAL_OUTPUT_ROOT}/bin/openim_config.yaml" # OpenIM openim-cmdutils 配置文件路径
|
def "OPENIM_CMDUTILS_CONFIG" "${LOCAL_OUTPUT_ROOT}/bin/openim_config.yaml" # OpenIM openim-cmdutils 配置文件路径
|
||||||
def "OPENIM_CMDUTILS_LOG_DIR" "${LOG_STORAGE_LOCATION}/openim-cmdutils" # OpenIM openim-cmdutils 日志存储路径
|
def "OPENIM_CMDUTILS_LOG_DIR" "${LOG_STORAGE_LOCATION}/openim-cmdutils" # OpenIM openim-cmdutils 日志存储路径
|
||||||
def "OPENIM_CMDUTILS_LOG_LEVEL" "info" # OpenIM openim-cmdutils 日志级别
|
def "OPENIM_CMDUTILS_LOG_LEVEL" "info" # OpenIM openim-cmdutils 日志级别
|
||||||
@ -234,7 +236,8 @@ def "OPENIM_CMDUTILS_LOG_COMPRESS" "false"
|
|||||||
def "OPENIM_CMDUTILS_LOG_WITH_STACK" "${LOG_WITH_STACK}" # OpenIM openim-cmdutils 日志是否带有堆栈信息
|
def "OPENIM_CMDUTILS_LOG_WITH_STACK" "${LOG_WITH_STACK}" # OpenIM openim-cmdutils 日志是否带有堆栈信息
|
||||||
|
|
||||||
###################### OpenIM openim-crontask ######################
|
###################### OpenIM openim-crontask ######################
|
||||||
def "OPENIM_CRONTASK_BINARY" "${LOCAL_OUTPUT_ROOT}/bin/platforms/linux/amd64/openim-crontask" # OpenIM openim-crontask 二进制文件路径
|
def "OPENIM_CRONTASK_HOST" "127.0.0.1"
|
||||||
|
def "OPENIM_CRONTASK_BINARY" "${OPENIM_OUTPUT_HOSTBIN}/openim-crontask" # OpenIM openim-crontask 二进制文件路径
|
||||||
def "OPENIM_CRONTASK_CONFIG" "${LOCAL_OUTPUT_ROOT}/bin/openim_config.yaml" # OpenIM openim-crontask 配置文件路径
|
def "OPENIM_CRONTASK_CONFIG" "${LOCAL_OUTPUT_ROOT}/bin/openim_config.yaml" # OpenIM openim-crontask 配置文件路径
|
||||||
def "OPENIM_CRONTASK_LOG_DIR" "${LOG_STORAGE_LOCATION}/openim-crontask" # OpenIM openim-crontask 日志存储路径
|
def "OPENIM_CRONTASK_LOG_DIR" "${LOG_STORAGE_LOCATION}/openim-crontask" # OpenIM openim-crontask 日志存储路径
|
||||||
def "OPENIM_CRONTASK_LOG_LEVEL" "info" # OpenIM openim-crontask 日志级别
|
def "OPENIM_CRONTASK_LOG_LEVEL" "info" # OpenIM openim-crontask 日志级别
|
||||||
@ -246,33 +249,43 @@ def "OPENIM_CRONTASK_LOG_WITH_STACK" "${LOG_WITH_STACK}"
|
|||||||
|
|
||||||
###################### OpenIM openim-msggateway ######################
|
###################### OpenIM openim-msggateway ######################
|
||||||
# 和上述相似,仅替换 openim-crontask 为 openim-msggateway
|
# 和上述相似,仅替换 openim-crontask 为 openim-msggateway
|
||||||
|
def "OPENIM_MSGGATEWAY_HOST" "127.0.0.1"
|
||||||
|
|
||||||
###################### OpenIM openim-msgtransfer ######################
|
###################### OpenIM openim-msgtransfer ######################
|
||||||
# 和上述相似,仅替换 openim-crontask 为 openim-msgtransfer
|
# 和上述相似,仅替换 openim-crontask 为 openim-msgtransfer
|
||||||
|
def "OPENIM_MSGTRANSFER_HOST" "127.0.0.1"
|
||||||
|
|
||||||
###################### OpenIM openim-push ######################
|
###################### OpenIM openim-push ######################
|
||||||
# 和上述相似,仅替换 openim-crontask 为 openim-push
|
# 和上述相似,仅替换 openim-crontask 为 openim-push
|
||||||
|
def "OPENIM_PUSH_HOST" "127.0.0.1"
|
||||||
|
|
||||||
###################### OpenIM openim-rpc-auth ######################
|
###################### OpenIM openim-rpc-auth ######################
|
||||||
# 和上述相似,仅替换 openim-crontask 为 openim-rpc-auth
|
# 和上述相似,仅替换 openim-crontask 为 openim-rpc-auth
|
||||||
|
def "OPENIM_RPC_AUTH_HOST" "127.0.0.1"
|
||||||
|
|
||||||
###################### OpenIM openim-rpc-conversation ######################
|
###################### OpenIM openim-rpc-conversation ######################
|
||||||
# 和上述相似,仅替换 openim-crontask 为 openim-rpc-conversation
|
# 和上述相似,仅替换 openim-crontask 为 openim-rpc-conversation
|
||||||
|
def "OPENIM_RPC_CONVERSATION_HOST" "127.0.0.1"
|
||||||
|
|
||||||
###################### OpenIM openim-rpc-friend ######################
|
###################### OpenIM openim-rpc-friend ######################
|
||||||
# 和上述相似,仅替换 openim-crontask 为 openim-rpc-friend
|
# 和上述相似,仅替换 openim-crontask 为 openim-rpc-friend
|
||||||
|
def "OPENIM_RPC_FRIEND_HOST" "127.0.0.1"
|
||||||
|
|
||||||
###################### OpenIM openim-rpc-group ######################
|
###################### OpenIM openim-rpc-group ######################
|
||||||
# 和上述相似,仅替换 openim-crontask 为 openim-rpc-group
|
# 和上述相似,仅替换 openim-crontask 为 openim-rpc-group
|
||||||
|
def "OPENIM_RPC_GROUP_HOST" "127.0.0.1"
|
||||||
|
|
||||||
###################### OpenIM openim-rpc-msg ######################
|
###################### OpenIM openim-rpc-msg ######################
|
||||||
# 和上述相似,仅替换 openim-crontask 为 openim-rpc-msg
|
# 和上述相似,仅替换 openim-crontask 为 openim-rpc-msg
|
||||||
|
def "OPENIM_RPC_MSG_HOST" "127.0.0.1"
|
||||||
|
|
||||||
###################### OpenIM openim-rpc-third ######################
|
###################### OpenIM openim-rpc-third ######################
|
||||||
# 和上述相似,仅替换 openim-crontask 为 openim-rpc-third
|
# 和上述相似,仅替换 openim-crontask 为 openim-rpc-third
|
||||||
|
def "OPENIM_RPC_THIRD_HOST" "127.0.0.1"
|
||||||
|
|
||||||
###################### OpenIM openim-rpc-user ######################
|
###################### OpenIM openim-rpc-user ######################
|
||||||
# 和上述相似,仅替换 openim-crontask 为 openim-rpc-user
|
# 和上述相似,仅替换 openim-crontask 为 openim-rpc-user
|
||||||
|
def "OPENIM_RPC_USER_HOST" "127.0.0.1"
|
||||||
|
|
||||||
###################### 设计中...暂时不需要######################################
|
###################### 设计中...暂时不需要######################################
|
||||||
# openim 配置
|
# openim 配置
|
||||||
|
|||||||
@ -21,99 +21,83 @@ set -o pipefail
|
|||||||
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
|
OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
|
||||||
[[ -z ${COMMON_SOURCED} ]] && source ${OPENIM_ROOT}/scripts/install/common.sh
|
[[ -z ${COMMON_SOURCED} ]] && source ${OPENIM_ROOT}/scripts/install/common.sh
|
||||||
|
|
||||||
readonly SERVER_NAME="openim-crontask"
|
SERVER_NAME="openim-crontask"
|
||||||
readonly SERVER_PATH="${OPENIM_OUTPUT_HOSTBIN}/openim-crontask"
|
|
||||||
|
|
||||||
openim::log::status "Start OpenIM Cron, binary root: ${SERVER_NAME}"
|
openim::log::status "Start OpenIM Cron, binary root: ${SERVER_NAME}"
|
||||||
openim::log::info "Start OpenIM Cron, path: ${SERVER_PATH}"
|
openim::log::info "Start OpenIM Cron, path: ${OPENIM_CRONTASK_BINARY}"
|
||||||
|
|
||||||
openim::util::stop_services_with_name ${SERVER_NAME}
|
# openim::util::stop_services_with_name ${SERVER_NAME}
|
||||||
|
|
||||||
sleep 1
|
# sleep 1
|
||||||
|
|
||||||
openim::log::status "start cron_task process"
|
# openim::log::status "start cron_task process, path: ${OPENIM_CRONTASK_BINARY}"
|
||||||
|
# nohup ${OPENIM_CRONTASK_BINARY} >>${LOG_FILE} 2>&1 &
|
||||||
|
# openim::util::check_process_names ${SERVER_NAME}
|
||||||
|
|
||||||
nohup ${SERVER_PATH} >>${log_file} 2>&1 &
|
# # Print the necessary information after installation
|
||||||
|
# function openim::crontask::info() {
|
||||||
|
# cat << EOF
|
||||||
|
# openim-crontask listen on: ${OPENIM_CRONTASK_HOST}
|
||||||
|
# EOF
|
||||||
|
# }
|
||||||
|
|
||||||
# Check launched service process
|
# install openim-crontask
|
||||||
check=`ps | grep -w ./${cron_task_name} | grep -v grep| wc -l`
|
function openim::crontask::install()
|
||||||
if [ $check -ge 1 ]
|
|
||||||
then
|
|
||||||
newPid=`ps | grep -w ./${cron_task_name} | grep -v grep|awk '{print $2}'`
|
|
||||||
allPorts=""
|
|
||||||
echo -e ${SKY_BLUE_PREFIX}"SERVICE START SUCCESS "${COLOR_SUFFIX}
|
|
||||||
echo -e ${SKY_BLUE_PREFIX}"SERVICE_NAME: "${COLOR_SUFFIX}${BACKGROUND_GREEN}${cron_task_name}${COLOR_SUFFIX}
|
|
||||||
echo -e ${SKY_BLUE_PREFIX}"PID: "${COLOR_SUFFIX}${BACKGROUND_GREEN}${newPid}${COLOR_SUFFIX}
|
|
||||||
echo -e ${SKY_BLUE_PREFIX}"LISTENING_PORT: "${COLOR_SUFFIX}${BACKGROUND_GREEN}${allPorts}${COLOR_SUFFIX}
|
|
||||||
else
|
|
||||||
echo -e ${BACKGROUND_GREEN}${cron_task_name}${COLOR_SUFFIX}${RED_PREFIX}"\n SERVICE START ERROR, PLEASE CHECK openIM.log"${COLOR_SUFFIX}
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
# Print the necessary information after installation
|
|
||||||
function iam::pump::info() {
|
|
||||||
cat << EOF
|
|
||||||
iam-pumpn listen on: ${IAM_PUMP_HOST}
|
|
||||||
EOF
|
|
||||||
}
|
|
||||||
|
|
||||||
# 安装
|
|
||||||
function iam::pump::install()
|
|
||||||
{
|
{
|
||||||
pushd ${IAM_ROOT}
|
pushd ${OPENIM_ROOT}
|
||||||
|
|
||||||
# 1. 构建 iam-pump
|
# 1. Build openim-crontask
|
||||||
make build BINS=iam-pump
|
make build BINS=${SERVER_NAME}
|
||||||
iam::common::sudo "cp ${LOCAL_OUTPUT_ROOT}/platforms/linux/amd64/iam-pump ${IAM_INSTALL_DIR}/bin"
|
openim::common::sudo "cp ${OPENIM_OUTPUT_HOSTBIN}/${SERVER_NAME} ${OPENIM_INSTALL_DIR}/bin"
|
||||||
|
|
||||||
# 2. 生成并安装 iam-pump 的配置文件(iam-pump.yaml)
|
# 2. Generate and install the openim-crontask configuration file (openim-crontask.yaml)
|
||||||
echo ${LINUX_PASSWORD} | sudo -S bash -c \
|
echo ${LINUX_PASSWORD} | sudo -S bash -c \
|
||||||
"./scripts/genconfig.sh ${ENV_FILE} configs/iam-pump.yaml > ${IAM_CONFIG_DIR}/iam-pump.yaml"
|
"./scripts/genconfig.sh ${ENV_FILE} deployments/templates/openim-crontask.yaml > ${OPENIM_CONFIG_DIR}/openim-crontask.yaml"
|
||||||
|
|
||||||
# 3. 创建并安装 iam-pump systemd unit 文件
|
# 3. Create and install the openim-crontask systemd unit file
|
||||||
echo ${LINUX_PASSWORD} | sudo -S bash -c \
|
echo ${LINUX_PASSWORD} | sudo -S bash -c \
|
||||||
"./scripts/genconfig.sh ${ENV_FILE} init/iam-pump.service > /etc/systemd/system/iam-pump.service"
|
"./scripts/genconfig.sh ${ENV_FILE} deployments/templates/init/openim-crontask.service > /etc/systemd/system/openim-crontask.service"
|
||||||
|
|
||||||
# 4. 启动 iam-pump 服务
|
# 4. Start the openim-crontask service
|
||||||
iam::common::sudo "systemctl daemon-reload"
|
openim::common::sudo "systemctl daemon-reload"
|
||||||
iam::common::sudo "systemctl restart iam-pump"
|
openim::common::sudo "systemctl restart openim-crontask"
|
||||||
iam::common::sudo "systemctl enable iam-pump"
|
openim::common::sudo "systemctl enable openim-crontask"
|
||||||
iam::pump::status || return 1
|
openim::crontask::status || return 1
|
||||||
iam::pump::info
|
openim::crontask::info
|
||||||
|
|
||||||
iam::log::info "install iam-pump successfully"
|
openim::log::info "install openim-crontask successfully"
|
||||||
popd
|
popd
|
||||||
}
|
}
|
||||||
|
|
||||||
# 卸载
|
# Unload
|
||||||
function iam::pump::uninstall()
|
function openim::crontask::uninstall()
|
||||||
{
|
{
|
||||||
set +o errexit
|
set +o errexit
|
||||||
iam::common::sudo "systemctl stop iam-pump"
|
openim::common::sudo "systemctl stop openim-crontask"
|
||||||
iam::common::sudo "systemctl disable iam-pump"
|
openim::common::sudo "systemctl disable openim-crontask"
|
||||||
iam::common::sudo "rm -f ${IAM_INSTALL_DIR}/bin/iam-pump"
|
openim::common::sudo "rm -f ${OPENIM_INSTALL_DIR}/bin/openim-crontask"
|
||||||
iam::common::sudo "rm -f ${IAM_CONFIG_DIR}/iam-pump.yaml"
|
openim::common::sudo "rm -f ${OPENIM_CONFIG_DIR}/openim-crontask.yaml"
|
||||||
iam::common::sudo "rm -f /etc/systemd/system/iam-pump.service"
|
openim::common::sudo "rm -f /etc/systemd/system/openim-crontask.service"
|
||||||
set -o errexit
|
set -o errexit
|
||||||
iam::log::info "uninstall iam-pump successfully"
|
openim::log::info "uninstall openim-crontask successfully"
|
||||||
}
|
}
|
||||||
|
|
||||||
# 状态检查
|
# Status Check
|
||||||
function iam::pump::status()
|
function openim::crontask::status()
|
||||||
{
|
{
|
||||||
# 查看 iam-pump 运行状态,如果输出中包含 active (running) 字样说明 iam-pump 成功启动。
|
# 查看 openim-crontask 运行状态,如果输出中包含 active (running) 字样说明 openim-crontask 成功启动。
|
||||||
systemctl status iam-pump|grep -q 'active' || {
|
systemctl status openim-crontask|grep -q 'active' || {
|
||||||
iam::log::error "iam-pump failed to start, maybe not installed properly"
|
openim::log::error "openim-crontask failed to start, maybe not installed properly"
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# 监听端口在配置文件中是 hardcode
|
# 监听端口在配置文件中是 hardcode
|
||||||
if echo | telnet 127.0.0.1 7070 2>&1|grep refused &>/dev/null;then
|
if echo | telnet 127.0.0.1 7070 2>&1|grep refused &>/dev/null;then
|
||||||
iam::log::error "cannot access health check port, iam-pump maybe not startup"
|
openim::log::error "cannot access health check port, openim-crontask maybe not startup"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
if [[ "$*" =~ iam::pump:: ]];then
|
if [[ "$*" =~ openim::crontask:: ]];then
|
||||||
eval $*
|
eval $*
|
||||||
fi
|
fi
|
||||||
|
|||||||
@ -94,7 +94,7 @@ readonly OPENIM_SERVER_BINARIES=("${OPENIM_SERVER_TARGETS[@]##*/}")
|
|||||||
START_SCRIPTS_PATH="${OPENIM_ROOT}/scripts/install/"
|
START_SCRIPTS_PATH="${OPENIM_ROOT}/scripts/install/"
|
||||||
openim::golang::start_script_list() {
|
openim::golang::start_script_list() {
|
||||||
local targets=(
|
local targets=(
|
||||||
start_rpc_service.sh
|
start-rpc_service.sh
|
||||||
push_start.sh
|
push_start.sh
|
||||||
msg_transfer_start.sh
|
msg_transfer_start.sh
|
||||||
msg_gateway_start.sh
|
msg_gateway_start.sh
|
||||||
|
|||||||
@ -25,17 +25,17 @@ if [[ ! -v OPENIM_OUTPUT ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# Set the log file path
|
# Set the log file path
|
||||||
log_file="${OPENIM_OUTPUT}/logs/openim_$(date '+%Y%m%d').log"
|
LOG_FILE="${OPENIM_OUTPUT}/logs/openim_$(date '+%Y%m%d').log"
|
||||||
|
|
||||||
if [[ ! -d "${OPENIM_OUTPUT}/logs" ]]; then
|
if [[ ! -d "${OPENIM_OUTPUT}/logs" ]]; then
|
||||||
mkdir -p "${OPENIM_OUTPUT}/logs"
|
mkdir -p "${OPENIM_OUTPUT}/logs"
|
||||||
touch "$log_file"
|
touch "$LOG_FILE"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Define the logging function
|
# Define the logging function
|
||||||
function echo_log() {
|
function echo_log() {
|
||||||
if $ENABLE_LOGGING; then
|
if $ENABLE_LOGGING; then
|
||||||
echo -e "$@" | tee -a "${log_file}"
|
echo -e "$@" | tee -a "${LOG_FILE}"
|
||||||
else
|
else
|
||||||
echo -e "$@"
|
echo -e "$@"
|
||||||
fi
|
fi
|
||||||
|
|||||||
@ -255,15 +255,15 @@ openim::util::host_arch() {
|
|||||||
# The function returns a status of 1 if any of the processes is not running.
|
# The function returns a status of 1 if any of the processes is not running.
|
||||||
openim::util::check_ports() {
|
openim::util::check_ports() {
|
||||||
# An array to collect ports of processes that are not running.
|
# An array to collect ports of processes that are not running.
|
||||||
not_started=()
|
local not_started=()
|
||||||
|
|
||||||
# An array to collect information about processes that are running.
|
# An array to collect information about processes that are running.
|
||||||
started=()
|
local started=()
|
||||||
|
|
||||||
# Iterate over each given port.
|
# Iterate over each given port.
|
||||||
for port in "$@"; do
|
for port in "$@"; do
|
||||||
# Use the `lsof` command to find process information related to the given port.
|
# Use the `lsof` command to find process information related to the given port.
|
||||||
info=$(lsof -i :$port -n -P | grep LISTEN || true)
|
local info=$(lsof -i :$port -n -P | grep LISTEN || true)
|
||||||
|
|
||||||
# If there's no process information, it means the process associated with the port is not running.
|
# If there's no process information, it means the process associated with the port is not running.
|
||||||
if [[ -z $info ]]; then
|
if [[ -z $info ]]; then
|
||||||
@ -271,9 +271,9 @@ openim::util::check_ports() {
|
|||||||
else
|
else
|
||||||
# If there's process information, extract relevant details:
|
# If there's process information, extract relevant details:
|
||||||
# Process ID, Command Name, and Start Time.
|
# Process ID, Command Name, and Start Time.
|
||||||
pid=$(echo $info | awk '{print $2}')
|
local pid=$(echo $info | awk '{print $2}')
|
||||||
command=$(echo $info | awk '{print $1}')
|
local command=$(echo $info | awk '{print $1}')
|
||||||
start_time=$(ps -o lstart= -p $pid)
|
local start_time=$(ps -o lstart= -p $pid)
|
||||||
started+=("Port $port - Command: $command, PID: $pid, Start time: $start_time")
|
started+=("Port $port - Command: $command, PID: $pid, Start time: $start_time")
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
@ -304,6 +304,66 @@ openim::util::check_ports() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# The `openim::util::check_process_names` function analyzes the state of processes based on given names.
|
||||||
|
# It accepts multiple process names as arguments and prints:
|
||||||
|
# 1. The state of the process (whether it's running or not).
|
||||||
|
# 2. The start time of the process if it's running.
|
||||||
|
# User:
|
||||||
|
# openim::util::check_process_names nginx mysql redis
|
||||||
|
# The function returns a status of 1 if any of the processes is not running.
|
||||||
|
openim::util::check_process_names() {
|
||||||
|
# An array to collect names of processes that are not running.
|
||||||
|
local not_started=()
|
||||||
|
|
||||||
|
# An array to collect information about processes that are running.
|
||||||
|
local started=()
|
||||||
|
|
||||||
|
# Iterate over each given process name.
|
||||||
|
for process_name in "$@"; do
|
||||||
|
# Use the `pgrep` command to find process information related to the given process name.
|
||||||
|
local pid=$(pgrep -f $process_name)
|
||||||
|
# If there's no process information, it means the process with the given name is not running.
|
||||||
|
if [[ -z $pid ]]; then
|
||||||
|
not_started+=($process_name)
|
||||||
|
else
|
||||||
|
# If there's process information, extract relevant details:
|
||||||
|
# Command Name, and Start Time.
|
||||||
|
# local pid=$(echo $info | awk '{print $2}')
|
||||||
|
local command=$(ps -p $pid -o cmd=)
|
||||||
|
local start_time=$(ps -p $pid -o lstart=)
|
||||||
|
started+=("Process $process_name - Command: $command, PID: $pid, Start time: $start_time")
|
||||||
|
echo "---------------command=$command"
|
||||||
|
echo "---------------pid=$pid"
|
||||||
|
echo "---------------start_time=$start_time"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
# Print information about processes which are not running.
|
||||||
|
if [[ ${#not_started[@]} -ne 0 ]]; then
|
||||||
|
openim::log::info "Not started processes:"
|
||||||
|
for process_name in "${not_started[@]}"; do
|
||||||
|
openim::log::error "Process $process_name is not started."
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Print information about processes which are running.
|
||||||
|
if [[ ${#started[@]} -ne 0 ]]; then
|
||||||
|
echo
|
||||||
|
openim::log::info "Started processes:"
|
||||||
|
for info in "${started[@]}"; do
|
||||||
|
openim::log::info "$info"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# If any of the processes is not running, return a status of 1.
|
||||||
|
if [[ ${#not_started[@]} -ne 0 ]]; then
|
||||||
|
return 1
|
||||||
|
else
|
||||||
|
openim::log::success "All processes are running."
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# The `openim::util::stop_services_on_ports` function stops services running on specified ports.
|
# The `openim::util::stop_services_on_ports` function stops services running on specified ports.
|
||||||
# It accepts multiple ports as arguments and performs the following:
|
# It accepts multiple ports as arguments and performs the following:
|
||||||
# 1. Attempts to stop any services running on the specified ports.
|
# 1. Attempts to stop any services running on the specified ports.
|
||||||
@ -313,10 +373,10 @@ openim::util::check_ports() {
|
|||||||
# The function returns a status of 1 if any service couldn't be stopped.
|
# The function returns a status of 1 if any service couldn't be stopped.
|
||||||
openim::util::stop_services_on_ports() {
|
openim::util::stop_services_on_ports() {
|
||||||
# An array to collect ports of processes that couldn't be stopped.
|
# An array to collect ports of processes that couldn't be stopped.
|
||||||
not_stopped=()
|
local not_stopped=()
|
||||||
|
|
||||||
# An array to collect information about processes that were stopped.
|
# An array to collect information about processes that were stopped.
|
||||||
stopped=()
|
local stopped=()
|
||||||
|
|
||||||
# Iterate over each given port.
|
# Iterate over each given port.
|
||||||
for port in "$@"; do
|
for port in "$@"; do
|
||||||
@ -326,7 +386,7 @@ openim::util::stop_services_on_ports() {
|
|||||||
# If there's process information, it means the process associated with the port is running.
|
# If there's process information, it means the process associated with the port is running.
|
||||||
if [[ -n $info ]]; then
|
if [[ -n $info ]]; then
|
||||||
# Extract the Process ID.
|
# Extract the Process ID.
|
||||||
pid=$(echo $info | awk '{print $2}')
|
local pid=$(echo $info | awk '{print $2}')
|
||||||
|
|
||||||
# Try to stop the service by killing its process.
|
# Try to stop the service by killing its process.
|
||||||
if kill -TERM $pid; then
|
if kill -TERM $pid; then
|
||||||
@ -363,6 +423,7 @@ openim::util::stop_services_on_ports() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# The `openim::util::stop_services_with_name` function stops services with specified names.
|
# The `openim::util::stop_services_with_name` function stops services with specified names.
|
||||||
# It accepts multiple service names as arguments and performs the following:
|
# It accepts multiple service names as arguments and performs the following:
|
||||||
# 1. Attempts to stop any services with the specified names.
|
# 1. Attempts to stop any services with the specified names.
|
||||||
@ -372,15 +433,15 @@ openim::util::stop_services_on_ports() {
|
|||||||
# The function returns a status of 1 if any service couldn't be stopped.
|
# The function returns a status of 1 if any service couldn't be stopped.
|
||||||
openim::util::stop_services_with_name() {
|
openim::util::stop_services_with_name() {
|
||||||
# An array to collect names of processes that couldn't be stopped.
|
# An array to collect names of processes that couldn't be stopped.
|
||||||
not_stopped=()
|
local not_stopped=()
|
||||||
|
|
||||||
# An array to collect information about processes that were stopped.
|
# An array to collect information about processes that were stopped.
|
||||||
stopped=()
|
local stopped=()
|
||||||
|
|
||||||
# Iterate over each given service name.
|
# Iterate over each given service name.
|
||||||
for server_name in "$@"; do
|
for server_name in "$@"; do
|
||||||
# Use the `pgrep` command to find process IDs related to the given service name.
|
# Use the `pgrep` command to find process IDs related to the given service name.
|
||||||
pids=$(ps aux | awk -v pattern="$server_name" '$0 ~ pattern {print $2}')
|
local pids=$(ps aux | awk -v pattern="$server_name" '$0 ~ pattern {print $2}')
|
||||||
|
|
||||||
for pid in $pids; do
|
for pid in $pids; do
|
||||||
# If there's a Process ID, it means the service with the name is running.
|
# If there's a Process ID, it means the service with the name is running.
|
||||||
@ -1117,8 +1178,20 @@ function openim::util::remove_space() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function openim::util::gencpu() {
|
function openim::util::gencpu() {
|
||||||
cpu=$(lscpu | grep -e '^CPU(s):' | awk '{print $2}')
|
# Check the system type
|
||||||
echo $cpu
|
system_type=$(uname)
|
||||||
|
|
||||||
|
if [[ "$system_type" == "Darwin" ]]; then
|
||||||
|
# macOS (using sysctl)
|
||||||
|
cpu_count=$(sysctl -n hw.ncpu)
|
||||||
|
elif [[ "$system_type" == "Linux" ]]; then
|
||||||
|
# Linux (using lscpu)
|
||||||
|
cpu_count=$(lscpu --parse | grep -E '^([^#].*,){3}[^#]' | sort -u | wc -l)
|
||||||
|
else
|
||||||
|
echo "Unsupported operating system: $system_type"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
echo $cpu_count
|
||||||
}
|
}
|
||||||
|
|
||||||
function openim::util::gen_os_arch() {
|
function openim::util::gen_os_arch() {
|
||||||
|
|||||||
@ -45,7 +45,7 @@ ifeq ($(origin GOBIN), undefined)
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
# COMMANDS is Specify all files under ${ROOT_DIR}/cmd/ and ${ROOT_DIR}/tools/ except those ending in.md
|
# COMMANDS is Specify all files under ${ROOT_DIR}/cmd/ and ${ROOT_DIR}/tools/ except those ending in.md
|
||||||
COMMANDS ?= $(filter-out %.md, $(wildcard ${ROOT_DIR}/cmd/* ${ROOT_DIR}/tools/*))
|
COMMANDS ?= $(filter-out %.md, $(wildcard ${ROOT_DIR}/cmd/* ${ROOT_DIR}/tools/* ${ROOT_DIR}/cmd/openim-rpc/*))
|
||||||
ifeq (${COMMANDS},)
|
ifeq (${COMMANDS},)
|
||||||
$(error Could not determine COMMANDS, set ROOT_DIR or run in source dir)
|
$(error Could not determine COMMANDS, set ROOT_DIR or run in source dir)
|
||||||
endif
|
endif
|
||||||
@ -134,16 +134,13 @@ go.build.%:
|
|||||||
$(eval ARCH := $(word 2,$(subst _, ,$(PLATFORM))))
|
$(eval ARCH := $(word 2,$(subst _, ,$(PLATFORM))))
|
||||||
@echo "=====> COMMAND=$(COMMAND)"
|
@echo "=====> COMMAND=$(COMMAND)"
|
||||||
@echo "=====> PLATFORM=$(PLATFORM)"
|
@echo "=====> PLATFORM=$(PLATFORM)"
|
||||||
@echo "=====> BIN_DIR=$(BIN_DIR)"
|
|
||||||
@echo "===========> Building binary $(COMMAND) $(VERSION) for $(OS)_$(ARCH)"
|
@echo "===========> Building binary $(COMMAND) $(VERSION) for $(OS)_$(ARCH)"
|
||||||
@mkdir -p $(BIN_DIR)/platforms/$(OS)/$(ARCH)
|
@mkdir -p $(BIN_DIR)/platforms/$(OS)/$(ARCH)
|
||||||
@if [ "$(COMMAND)" == "openim-sdk-core" ]; then \
|
@if [ "$(COMMAND)" == "openim-sdk-core" ]; then \
|
||||||
echo "===========> DEBUG: OpenIM-SDK-Core It is no longer supported for openim-server $(COMMAND)"; \
|
echo "===========> DEBUG: OpenIM-SDK-Core It is no longer supported for openim-server $(COMMAND)"; \
|
||||||
elif [ "$(COMMAND)" == "openim-rpc" ]; then \
|
elif [ -d $(ROOT_DIR)/cmd/openim-rpc/$(COMMAND) ]; then \
|
||||||
for d in $(wildcard $(ROOT_DIR)/cmd/openim-rpc/*); do \
|
CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) $(GO) build $(GO_BUILD_FLAGS) -o \
|
||||||
cd $${d} && CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) $(GO) build $(GO_BUILD_FLAGS) -o \
|
$(BIN_DIR)/platforms/$(OS)/$(ARCH)/$(COMMAND)$(GO_OUT_EXT) $(ROOT_DIR)/cmd/openim-rpc/$(COMMAND)/main.go; \
|
||||||
$(BIN_DIR)/platforms/$(OS)/$(ARCH)/$$(basename $${d})$(GO_OUT_EXT) $${d}/main.go; \
|
|
||||||
done; \
|
|
||||||
else \
|
else \
|
||||||
if [ -f $(ROOT_DIR)/cmd/$(COMMAND)/main.go ]; then \
|
if [ -f $(ROOT_DIR)/cmd/$(COMMAND)/main.go ]; then \
|
||||||
CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) $(GO) build $(GO_BUILD_FLAGS) -o \
|
CGO_ENABLED=0 GOOS=$(OS) GOARCH=$(ARCH) $(GO) build $(GO_BUILD_FLAGS) -o \
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user