mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-05-21 20:32:32 +08:00
feat: Optimize openim scripts and standard output logs (#1866)
* feat: add component check func * fix: fix the outpu error * fix: fix the stderr outpu * fix: fix the component check func * fix: fix the error * fix: fix the output error * fix: del the disruptions code * fix the log output format * fix: fix the tools version * fix: fix the cycle detection * fix: fix the error * fix: fix the flag * fix: add mongo ping detection * fix: fix the tools pkg version * fix: del the err * feat: support openim readme docs Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com> * feat: support openim readme docs Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com> * feat: support openim readme docs Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com> * fix: fix the minio nil error * fix: del the repeated wrap and add err print * fix: fix this bug scripts * Revert "Check" --------- Signed-off-by: Xinwei Xiong (cubxxw) <3293172751nss@gmail.com> Co-authored-by: luhaoling <2198702716@qq.com>
This commit is contained in:
parent
af878a96cf
commit
854f8dbd2f
@ -43,7 +43,8 @@ func main() {
|
||||
apiCmd.AddPortFlag()
|
||||
apiCmd.AddApi(run)
|
||||
if err := apiCmd.Execute(); err != nil {
|
||||
panic(err.Error())
|
||||
fmt.Fprintf(os.Stderr, "\n\nexit -1: \n%+v\n\n", err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/cmd"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -54,6 +56,7 @@ func main() {
|
||||
// openIM clear msg --clearAll
|
||||
msgUtilsCmd.AddCommand(&getCmd.Command, &fixCmd.Command, &clearCmd.Command)
|
||||
if err := msgUtilsCmd.Execute(); err != nil {
|
||||
panic(err)
|
||||
fmt.Fprintf(os.Stderr, "\n\nexit -1: \n%+v\n\n", err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
}
|
||||
|
@ -15,13 +15,16 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/openimsdk/open-im-server/v3/internal/tools"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/cmd"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cronTaskCmd := cmd.NewCronTaskCmd()
|
||||
if err := cronTaskCmd.Exec(tools.StartTask); err != nil {
|
||||
panic(err.Error())
|
||||
fmt.Fprintf(os.Stderr, "\n\nexit -1: \n%+v\n\n", err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/cmd"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -25,6 +27,7 @@ func main() {
|
||||
msgGatewayCmd.AddPrometheusPortFlag()
|
||||
|
||||
if err := msgGatewayCmd.Exec(); err != nil {
|
||||
panic(err.Error())
|
||||
fmt.Fprintf(os.Stderr, "\n\nexit -1: \n%+v\n\n", err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/cmd"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -23,6 +25,7 @@ func main() {
|
||||
msgTransferCmd.AddPrometheusPortFlag()
|
||||
msgTransferCmd.AddTransferProgressFlag()
|
||||
if err := msgTransferCmd.Exec(); err != nil {
|
||||
panic(err.Error())
|
||||
fmt.Fprintf(os.Stderr, "\n\nexit -1: \n%+v\n\n", err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
}
|
||||
|
@ -15,9 +15,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/openimsdk/open-im-server/v3/internal/push"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/cmd"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -28,6 +30,7 @@ func main() {
|
||||
panic(err.Error())
|
||||
}
|
||||
if err := pushCmd.StartSvr(config.Config.RpcRegisterName.OpenImPushName, push.Start); err != nil {
|
||||
panic(err.Error())
|
||||
fmt.Fprintf(os.Stderr, "\n\nexit -1: \n%+v\n\n", err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
}
|
||||
|
@ -15,9 +15,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/openimsdk/open-im-server/v3/internal/rpc/auth"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/cmd"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -28,6 +30,7 @@ func main() {
|
||||
panic(err.Error())
|
||||
}
|
||||
if err := authCmd.StartSvr(config.Config.RpcRegisterName.OpenImAuthName, auth.Start); err != nil {
|
||||
panic(err.Error())
|
||||
fmt.Fprintf(os.Stderr, "\n\nexit -1: \n%+v\n\n", err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
}
|
||||
|
@ -15,9 +15,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/openimsdk/open-im-server/v3/internal/rpc/conversation"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/cmd"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -28,6 +30,7 @@ func main() {
|
||||
panic(err.Error())
|
||||
}
|
||||
if err := rpcCmd.StartSvr(config.Config.RpcRegisterName.OpenImConversationName, conversation.Start); err != nil {
|
||||
panic(err.Error())
|
||||
fmt.Fprintf(os.Stderr, "\n\nexit -1: \n%+v\n\n", err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
}
|
||||
|
@ -15,9 +15,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/openimsdk/open-im-server/v3/internal/rpc/friend"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/cmd"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -28,6 +30,7 @@ func main() {
|
||||
panic(err.Error())
|
||||
}
|
||||
if err := rpcCmd.StartSvr(config.Config.RpcRegisterName.OpenImFriendName, friend.Start); err != nil {
|
||||
panic(err.Error())
|
||||
fmt.Fprintf(os.Stderr, "\n\nexit -1: \n%+v\n\n", err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
}
|
||||
|
@ -15,9 +15,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/openimsdk/open-im-server/v3/internal/rpc/group"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/cmd"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -28,6 +30,7 @@ func main() {
|
||||
panic(err.Error())
|
||||
}
|
||||
if err := rpcCmd.StartSvr(config.Config.RpcRegisterName.OpenImGroupName, group.Start); err != nil {
|
||||
panic(err.Error())
|
||||
fmt.Fprintf(os.Stderr, "\n\nexit -1: \n%+v\n\n", err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
}
|
||||
|
@ -15,9 +15,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/openimsdk/open-im-server/v3/internal/rpc/msg"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/cmd"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -28,6 +30,7 @@ func main() {
|
||||
panic(err.Error())
|
||||
}
|
||||
if err := rpcCmd.StartSvr(config.Config.RpcRegisterName.OpenImMsgName, msg.Start); err != nil {
|
||||
panic(err.Error())
|
||||
fmt.Fprintf(os.Stderr, "\n\nexit -1: \n%+v\n\n", err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
}
|
||||
|
@ -15,9 +15,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/openimsdk/open-im-server/v3/internal/rpc/third"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/cmd"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -28,6 +30,7 @@ func main() {
|
||||
panic(err.Error())
|
||||
}
|
||||
if err := rpcCmd.StartSvr(config.Config.RpcRegisterName.OpenImThirdName, third.Start); err != nil {
|
||||
panic(err.Error())
|
||||
fmt.Fprintf(os.Stderr, "\n\nexit -1: \n%+v\n\n", err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
}
|
||||
|
@ -15,9 +15,11 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/openimsdk/open-im-server/v3/internal/rpc/user"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/cmd"
|
||||
"github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
@ -28,6 +30,7 @@ func main() {
|
||||
panic(err.Error())
|
||||
}
|
||||
if err := rpcCmd.StartSvr(config.Config.RpcRegisterName.OpenImUserName, user.Start); err != nil {
|
||||
panic(err.Error())
|
||||
fmt.Fprintf(os.Stderr, "\n\nexit -1: \n%+v\n\n", err)
|
||||
os.Exit(-1)
|
||||
}
|
||||
}
|
||||
|
2
go.mod
2
go.mod
@ -5,7 +5,7 @@ go 1.19
|
||||
require (
|
||||
firebase.google.com/go v3.13.0+incompatible
|
||||
github.com/OpenIMSDK/protocol v0.0.48
|
||||
github.com/OpenIMSDK/tools v0.0.32
|
||||
github.com/OpenIMSDK/tools v0.0.33
|
||||
github.com/bwmarrin/snowflake v0.3.0 // indirect
|
||||
github.com/dtm-labs/rockscache v0.1.1
|
||||
github.com/gin-gonic/gin v1.9.1
|
||||
|
4
go.sum
4
go.sum
@ -20,8 +20,8 @@ github.com/IBM/sarama v1.41.3 h1:MWBEJ12vHC8coMjdEXFq/6ftO6DUZnQlFYcxtOJFa7c=
|
||||
github.com/IBM/sarama v1.41.3/go.mod h1:Xxho9HkHd4K/MDUo/T/sOqwtX/17D33++E9Wib6hUdQ=
|
||||
github.com/OpenIMSDK/protocol v0.0.48 h1:8MIMjyzJRsruYhVv2ZKArFiOveroaofDOb3dlAdgjsw=
|
||||
github.com/OpenIMSDK/protocol v0.0.48/go.mod h1:F25dFrwrIx3lkNoiuf6FkCfxuwf8L4Z8UIsdTHP/r0Y=
|
||||
github.com/OpenIMSDK/tools v0.0.32 h1:b8KwtxXKZTsyyHUcZ4OtSo6s/vVXx4HjMuPxH7Kb7Gg=
|
||||
github.com/OpenIMSDK/tools v0.0.32/go.mod h1:wBfR5CYmEyvxl03QJbTkhz1CluK6J4/lX0lviu8JAjE=
|
||||
github.com/OpenIMSDK/tools v0.0.33 h1:rvFCxXaXxLv1MJFC4qcoWRGwKBnV+hR68UN2N0/zZhE=
|
||||
github.com/OpenIMSDK/tools v0.0.33/go.mod h1:wBfR5CYmEyvxl03QJbTkhz1CluK6J4/lX0lviu8JAjE=
|
||||
github.com/QcloudApi/qcloud_sign_golang v0.0.0-20141224014652-e4130a326409/go.mod h1:1pk82RBxDY/JZnPQrtqHlUFfCctgdorsd9M06fMynOM=
|
||||
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7 h1:uSoVVbwJiQipAclBbw+8quDsfcvFjOpI5iCf4p/cqCs=
|
||||
github.com/alcortesm/tgz v0.0.0-20161220082320-9c5fe88206d7/go.mod h1:6zEj6s6u/ghQa61ZWa/C2Aw3RkjiTBOix7dkqa1VLIs=
|
||||
|
@ -20,7 +20,6 @@ import (
|
||||
config2 "github.com/openimsdk/open-im-server/v3/pkg/common/config"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
_ "go.uber.org/automaxprocs"
|
||||
|
||||
"github.com/OpenIMSDK/protocol/constant"
|
||||
"github.com/OpenIMSDK/tools/log"
|
||||
|
@ -54,14 +54,15 @@ func NewMongo() (*Mongo, error) {
|
||||
defer cancel()
|
||||
mongoClient, err = mongo.Connect(ctx, options.Client().ApplyURI(uri))
|
||||
if err == nil {
|
||||
if err = mongoClient.Ping(ctx, nil); err != nil {
|
||||
return nil, errs.Wrap(err, uri)
|
||||
}
|
||||
return &Mongo{db: mongoClient}, nil
|
||||
}
|
||||
if shouldRetry(err) {
|
||||
fmt.Printf("Failed to connect to MongoDB, retrying: %s\n", err)
|
||||
time.Sleep(time.Second) // exponential backoff could be implemented here
|
||||
continue
|
||||
}
|
||||
return nil, errs.Wrap(err, uri)
|
||||
}
|
||||
return nil, errs.Wrap(err, uri)
|
||||
}
|
||||
|
@ -45,7 +45,7 @@ func NewZookeeperDiscoveryRegister() (discoveryregistry.SvcDiscoveryRegistry, er
|
||||
openkeeper.WithLogger(log.NewZkLogger()),
|
||||
)
|
||||
if err != nil {
|
||||
uriFormat := "address:%s, username :%s, password :%s, schema:%s."
|
||||
uriFormat := "address:%s, username:%s, password:%s, schema:%s."
|
||||
errInfo := fmt.Sprintf(uriFormat,
|
||||
config.Config.Zookeeper.ZkAddr,
|
||||
config.Config.Zookeeper.Username,
|
||||
|
@ -17,7 +17,6 @@ package startrpc
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/OpenIMSDK/tools/errs"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
@ -28,6 +27,8 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/OpenIMSDK/tools/errs"
|
||||
|
||||
"github.com/prometheus/client_golang/prometheus"
|
||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||
"golang.org/x/sync/errgroup"
|
||||
@ -96,7 +97,7 @@ func Start(
|
||||
|
||||
err = rpcFn(client, srv)
|
||||
if err != nil {
|
||||
return errs.Wrap(err)
|
||||
return err
|
||||
}
|
||||
err = client.Register(
|
||||
rpcRegisterName,
|
||||
@ -116,7 +117,7 @@ func Start(
|
||||
// Create a HTTP server for prometheus.
|
||||
httpServer := &http.Server{Handler: promhttp.HandlerFor(reg, promhttp.HandlerOpts{}), Addr: fmt.Sprintf("0.0.0.0:%d", prometheusPort)}
|
||||
if err := httpServer.ListenAndServe(); err != nil {
|
||||
log.Fatal("Unable to start a http server.")
|
||||
log.Fatal("Unable to start a http server. ", err.Error(), "PrometheusPort:", prometheusPort)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@ -49,6 +49,14 @@ print_services_and_ports() {
|
||||
echo "+-------------------------+----------+"
|
||||
}
|
||||
|
||||
handle_error() {
|
||||
echo "An error occurred. Printing ${STDERR_LOG_FILE} contents:"
|
||||
cat "${STDERR_LOG_FILE}"
|
||||
exit 1
|
||||
}
|
||||
|
||||
trap handle_error ERR
|
||||
|
||||
# Assuming OPENIM_SERVER_NAME_TARGETS and OPENIM_SERVER_PORT_TARGETS are defined
|
||||
# Similarly for OPENIM_DEPENDENCY_TARGETS and OPENIM_DEPENDENCY_PORT_TARGETS
|
||||
|
||||
@ -94,3 +102,5 @@ else
|
||||
fi
|
||||
|
||||
set -e
|
||||
|
||||
trap - ERR
|
@ -34,12 +34,15 @@ readonly OPENIM_API_SERVICE_TARGETS=(
|
||||
readonly OPENIM_API_SERVICE_LISTARIES=("${OPENIM_API_SERVICE_TARGETS[@]##*/}")
|
||||
|
||||
function openim::api::start() {
|
||||
|
||||
rm -rf "$TMP_LOG_FILE"
|
||||
|
||||
echo "++ OPENIM_API_SERVICE_LISTARIES: ${OPENIM_API_SERVICE_LISTARIES[@]}"
|
||||
echo "++ OPENIM_API_PORT_LISTARIES: ${OPENIM_API_PORT_LISTARIES[@]}"
|
||||
echo "++ OpenIM API config path: ${OPENIM_API_CONFIG}"
|
||||
|
||||
|
||||
openim::log::info "Starting ${SERVER_NAME} ..."
|
||||
|
||||
|
||||
printf "+------------------------+--------------+\n"
|
||||
printf "| Service Name | Port |\n"
|
||||
printf "+------------------------+--------------+\n"
|
||||
@ -80,8 +83,7 @@ function openim::api::start_service() {
|
||||
local prometheus_port="$3"
|
||||
|
||||
local cmd="${OPENIM_OUTPUT_HOSTBIN}/${binary_name} --port ${service_port} -c ${OPENIM_API_CONFIG}"
|
||||
|
||||
nohup ${cmd} >> "${LOG_FILE}" 2>&1 &
|
||||
nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE") &
|
||||
|
||||
if [ $? -ne 0 ]; then
|
||||
openim::log::error_exit "Failed to start ${binary_name} on port ${service_port}."
|
||||
|
@ -44,14 +44,19 @@ OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
|
||||
SERVER_NAME="openim-crontask"
|
||||
|
||||
function openim::crontask::start() {
|
||||
|
||||
rm -rf "$TMP_LOG_FILE"
|
||||
|
||||
openim::log::info "Start OpenIM Cron, binary root: ${SERVER_NAME}"
|
||||
openim::log::status "Start OpenIM Cron, path: ${OPENIM_CRONTASK_BINARY}"
|
||||
|
||||
openim::util::stop_services_with_name ${OPENIM_CRONTASK_BINARY}
|
||||
|
||||
openim::log::status "start cron_task process, path: ${OPENIM_CRONTASK_BINARY}"
|
||||
nohup ${OPENIM_CRONTASK_BINARY} -c ${OPENIM_PUSH_CONFIG} >> ${LOG_FILE} 2>&1 &
|
||||
|
||||
nohup ${OPENIM_CRONTASK_BINARY} -c ${OPENIM_PUSH_CONFIG} >> ${LOG_FILE} 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE") &
|
||||
openim::util::check_process_names ${SERVER_NAME}
|
||||
|
||||
}
|
||||
|
||||
###################################### Linux Systemd ######################################
|
||||
|
@ -26,6 +26,9 @@ openim::util::set_max_fd 200000
|
||||
SERVER_NAME="openim-msggateway"
|
||||
|
||||
function openim::msggateway::start() {
|
||||
|
||||
rm -rf "$TMP_LOG_FILE"
|
||||
|
||||
openim::log::info "Start OpenIM Msggateway, binary root: ${SERVER_NAME}"
|
||||
openim::log::status "Start OpenIM Msggateway, path: ${OPENIM_MSGGATEWAY_BINARY}"
|
||||
|
||||
@ -61,7 +64,7 @@ function openim::msggateway::start() {
|
||||
PROMETHEUS_PORT_OPTION="--prometheus_port ${MSG_GATEWAY_PROM_PORTS_ARRAY[$i]}"
|
||||
fi
|
||||
|
||||
nohup ${OPENIM_MSGGATEWAY_BINARY} --port ${OPENIM_MSGGATEWAY_PORTS_ARRAY[$i]} --ws_port ${OPENIM_WS_PORTS_ARRAY[$i]} $PROMETHEUS_PORT_OPTION -c ${OPENIM_MSGGATEWAY_CONFIG} >> ${LOG_FILE} 2>&1 &
|
||||
nohup ${OPENIM_MSGGATEWAY_BINARY} --port ${OPENIM_MSGGATEWAY_PORTS_ARRAY[$i]} --ws_port ${OPENIM_WS_PORTS_ARRAY[$i]} $PROMETHEUS_PORT_OPTION -c ${OPENIM_MSGGATEWAY_CONFIG} >> ${LOG_FILE} 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE") &
|
||||
done
|
||||
|
||||
openim::util::check_process_names ${SERVER_NAME}
|
||||
|
@ -28,6 +28,9 @@ openim::util::set_max_fd 200000
|
||||
SERVER_NAME="openim-msgtransfer"
|
||||
|
||||
function openim::msgtransfer::start() {
|
||||
|
||||
rm -rf "$TMP_LOG_FILE"
|
||||
|
||||
openim::log::info "Start OpenIM Msggateway, binary root: ${SERVER_NAME}"
|
||||
openim::log::status "Start OpenIM Msggateway, path: ${OPENIM_MSGTRANSFER_BINARY}"
|
||||
|
||||
@ -56,7 +59,7 @@ function openim::msgtransfer::start() {
|
||||
if [[ -n "${OPENIM_PROMETHEUS_PORTS[$i]}" ]]; then
|
||||
PROMETHEUS_PORT_OPTION="--prometheus_port ${OPENIM_PROMETHEUS_PORTS[$i]}"
|
||||
fi
|
||||
nohup ${OPENIM_MSGTRANSFER_BINARY} ${PROMETHEUS_PORT_OPTION} -c ${OPENIM_MSGTRANSFER_CONFIG} -n ${i}>> ${LOG_FILE} 2>&1 &
|
||||
nohup ${OPENIM_MSGTRANSFER_BINARY} ${PROMETHEUS_PORT_OPTION} -c ${OPENIM_MSGTRANSFER_CONFIG} -n ${i} >> ${LOG_FILE} 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE") &
|
||||
done
|
||||
|
||||
openim::util::check_process_names "${OPENIM_OUTPUT_HOSTBIN}/${SERVER_NAME}"
|
||||
|
@ -50,6 +50,9 @@ OPENIM_ROOT=$(cd "$(dirname "${BASH_SOURCE[0]}")"/../.. && pwd -P)
|
||||
SERVER_NAME="openim-push"
|
||||
|
||||
function openim::push::start() {
|
||||
|
||||
rm -rf "$TMP_LOG_FILE"
|
||||
|
||||
openim::log::status "Start OpenIM Push, binary root: ${SERVER_NAME}"
|
||||
openim::log::info "Start OpenIM Push, path: ${OPENIM_PUSH_BINARY}"
|
||||
|
||||
@ -70,9 +73,9 @@ function openim::push::start() {
|
||||
|
||||
for (( i=0; i<${#OPENIM_PUSH_PORTS_ARRAY[@]}; i++ )); do
|
||||
openim::log::info "start push process, port: ${OPENIM_PUSH_PORTS_ARRAY[$i]}, prometheus port: ${PUSH_PROM_PORTS_ARRAY[$i]}"
|
||||
nohup ${OPENIM_PUSH_BINARY} --port ${OPENIM_PUSH_PORTS_ARRAY[$i]} -c ${OPENIM_PUSH_CONFIG} --prometheus_port ${PUSH_PROM_PORTS_ARRAY[$i]} >> ${LOG_FILE} 2>&1 &
|
||||
nohup ${OPENIM_PUSH_BINARY} --port ${OPENIM_PUSH_PORTS_ARRAY[$i]} -c ${OPENIM_PUSH_CONFIG} --prometheus_port ${PUSH_PROM_PORTS_ARRAY[$i]} >${LOG_FILE} 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE") &
|
||||
done
|
||||
|
||||
|
||||
openim::util::check_process_names ${SERVER_NAME}
|
||||
}
|
||||
|
||||
|
@ -102,6 +102,8 @@ readonly OPENIM_RPC_PROM_PORT_TARGETS
|
||||
readonly OPENIM_RPC_PROM_PORT_LISTARIES=("${OPENIM_RPC_PROM_PORT_TARGETS[@]##*/}")
|
||||
|
||||
function openim::rpc::start() {
|
||||
rm -rf "$TMP_LOG_FILE"
|
||||
|
||||
echo "OPENIM_RPC_SERVICE_LISTARIES: ${OPENIM_RPC_SERVICE_LISTARIES[@]}"
|
||||
echo "OPENIM_RPC_PROM_PORT_LISTARIES: ${OPENIM_RPC_PROM_PORT_LISTARIES[@]}"
|
||||
echo "OPENIM_RPC_PORT_LISTARIES: ${OPENIM_RPC_PORT_LISTARIES[@]}"
|
||||
@ -123,6 +125,7 @@ function openim::rpc::start() {
|
||||
for ((i = 0; i < ${#OPENIM_RPC_SERVICE_LISTARIES[*]}; i++)); do
|
||||
# openim::util::stop_services_with_name ${OPENIM_RPC_SERVICE_LISTARIES
|
||||
openim::util::stop_services_on_ports ${OPENIM_RPC_PORT_LISTARIES[$i]}
|
||||
openim::util::stop_services_on_ports ${OPENIM_RPC_PROM_PORT_LISTARIES[$i]}
|
||||
|
||||
openim::log::info "OpenIM ${OPENIM_RPC_SERVICE_LISTARIES[$i]} config path: ${OPENIM_RPC_CONFIG}"
|
||||
|
||||
@ -157,7 +160,7 @@ function openim::rpc::start_service() {
|
||||
printf "Specifying prometheus port: %s\n" "${prometheus_port}"
|
||||
cmd="${cmd} --prometheus_port ${prometheus_port}"
|
||||
fi
|
||||
nohup ${cmd} >> "${LOG_FILE}" 2>&1 &
|
||||
nohup ${cmd} >> "${LOG_FILE}" 2> >(tee -a "${STDERR_LOG_FILE}" "$TMP_LOG_FILE") &
|
||||
}
|
||||
|
||||
###################################### Linux Systemd ######################################
|
||||
|
@ -26,10 +26,14 @@ fi
|
||||
|
||||
# Set the log file path
|
||||
LOG_FILE="${OPENIM_OUTPUT}/logs/openim_$(date '+%Y%m%d').log"
|
||||
STDERR_LOG_FILE="${OPENIM_OUTPUT}/logs/openim_error_$(date '+%Y%m%d').log"
|
||||
TMP_LOG_FILE="${OPENIM_OUTPUT}/logs/openim_tmp_$(date '+%Y%m%d').log"
|
||||
|
||||
if [[ ! -d "${OPENIM_OUTPUT}/logs" ]]; then
|
||||
mkdir -p "${OPENIM_OUTPUT}/logs"
|
||||
touch "$LOG_FILE"
|
||||
touch "$STDERR_LOG_FILE"
|
||||
touch "$TMP_LOG_FILE"
|
||||
fi
|
||||
|
||||
# Define the logging function
|
||||
|
@ -360,7 +360,9 @@ openim::util::check_ports() {
|
||||
|
||||
# If any of the processes is not running, return a status of 1.
|
||||
if [[ ${#not_started[@]} -ne 0 ]]; then
|
||||
echo "++++ OpenIM Log >> cat ${LOG_FILE}"
|
||||
openim::color::echo $COLOR_RED " OpenIM Stdout Log >> cat ${LOG_FILE}"
|
||||
openim::color::echo $COLOR_RED " OpenIM Stderr Log >> cat ${STDERR_LOG_FILE}"
|
||||
cat "$TMP_LOG_FILE" | awk '{print "\033[31m" $0 "\033[0m"}'
|
||||
return 1
|
||||
else
|
||||
openim::log::success "All specified processes are running."
|
||||
@ -444,9 +446,12 @@ openim::util::check_process_names() {
|
||||
|
||||
# Return status
|
||||
if [[ ${#not_started[@]} -ne 0 ]]; then
|
||||
echo "++++ OpenIM Log >> cat ${LOG_FILE}"
|
||||
openim::color::echo $COLOR_RED " OpenIM Stdout Log >> cat ${LOG_FILE}"
|
||||
openim::color::echo $COLOR_RED " OpenIM Stderr Log >> cat ${STDERR_LOG_FILE}"
|
||||
cat "$TMP_LOG_FILE" | awk '{print "\033[31m" $0 "\033[0m"}'
|
||||
return 1
|
||||
else
|
||||
echo ""
|
||||
openim::log::success "All processes are running."
|
||||
return 0
|
||||
fi
|
||||
@ -1536,12 +1541,12 @@ openim::util::check_ports() {
|
||||
if [[ "$OSTYPE" == "linux-gnu"* ]]; then
|
||||
if command -v ss > /dev/null 2>&1; then
|
||||
info=$(ss -ltnp | grep ":$port" || true)
|
||||
echo "!!!!!!!!!!! port=$port"
|
||||
echo "!!!!!!!!!!! info=$info"
|
||||
openim::color::echo $COLOR_RED "!!!!!!!! port=$port"
|
||||
openim::color::echo $COLOR_RED "!!!!!!!! info=$info"
|
||||
else
|
||||
info=$(netstat -ltnp | grep ":$port" || true)
|
||||
echo "!!!!!!!!!!! port=$port"
|
||||
echo "!!!!!!!!!!! info=$info"
|
||||
openim::color::echo $COLOR_RED "!!!!!!!! port=$port"
|
||||
openim::color::echo $COLOR_RED "!!!!!!!! info=$info"
|
||||
fi
|
||||
elif [[ "$OSTYPE" == "darwin"* ]]; then
|
||||
# For macOS, use lsof
|
||||
@ -1594,7 +1599,10 @@ openim::util::check_ports() {
|
||||
|
||||
# If any of the processes is not running, return a status of 1.
|
||||
if [[ ${#not_started[@]} -ne 0 ]]; then
|
||||
echo "++++ OpenIM Log >> cat ${LOG_FILE}"
|
||||
openim::color::echo $COLOR_RED " OpenIM Stdout Log >> cat ${LOG_FILE}"
|
||||
openim::color::echo $COLOR_RED " OpenIM Stderr Log >> cat ${STDERR_LOG_FILE}"
|
||||
echo ""
|
||||
cat "$TMP_LOG_FILE" | awk '{print "\033[31m" $0 "\033[0m"}'
|
||||
return 1
|
||||
else
|
||||
openim::log::success "All specified processes are running."
|
||||
@ -1678,9 +1686,12 @@ openim::util::check_process_names() {
|
||||
|
||||
# Return status
|
||||
if [[ ${#not_started[@]} -ne 0 ]]; then
|
||||
echo "++++ OpenIM Log >> cat ${LOG_FILE}"
|
||||
openim::color::echo $COLOR_RED " OpenIM Stdout Log >> cat ${LOG_FILE}"
|
||||
openim::color::echo $COLOR_RED " OpenIM Stderr Log >> cat ${STDERR_LOG_FILE}"
|
||||
cat "$TMP_LOG_FILE" | awk '{print "\033[31m" $0 "\033[0m"}'
|
||||
return 1
|
||||
else
|
||||
echo ""
|
||||
openim::log::success "All processes are running."
|
||||
return 0
|
||||
fi
|
||||
|
@ -15,6 +15,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/IBM/sarama"
|
||||
@ -56,6 +57,7 @@ func initCfg() error {
|
||||
type checkFunc struct {
|
||||
name string
|
||||
function func() error
|
||||
flag bool
|
||||
}
|
||||
|
||||
func main() {
|
||||
@ -86,13 +88,17 @@ func main() {
|
||||
|
||||
var err error
|
||||
allSuccess := true
|
||||
for _, check := range checks {
|
||||
err = check.function()
|
||||
if err != nil {
|
||||
component.ErrorPrint(fmt.Sprintf("Starting %s failed:%v.", check.name, err))
|
||||
allSuccess = false
|
||||
} else {
|
||||
component.SuccessPrint(fmt.Sprintf("%s connected successfully", check.name))
|
||||
for index, check := range checks {
|
||||
if !check.flag {
|
||||
err = check.function()
|
||||
if err != nil {
|
||||
component.ErrorPrint(fmt.Sprintf("Starting %s failed:%v.", check.name, err))
|
||||
allSuccess = false
|
||||
|
||||
} else {
|
||||
checks[index].flag = true
|
||||
component.SuccessPrint(fmt.Sprintf("%s connected successfully", check.name))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -120,7 +126,7 @@ func checkMinio() error {
|
||||
|
||||
// Check if MinIO is enabled
|
||||
if config.Config.Object.Enable != "minio" {
|
||||
return nil
|
||||
return errs.Wrap(errors.New("minio.Enable is empty"))
|
||||
}
|
||||
minio := &component.Minio{
|
||||
ApiURL: config.Config.Object.ApiURL,
|
||||
@ -130,7 +136,7 @@ func checkMinio() error {
|
||||
SignEndpoint: config.Config.Object.Minio.SignEndpoint,
|
||||
UseSSL: getEnv("MINIO_USE_SSL", "false"),
|
||||
}
|
||||
_, err := component.CheckMinio(minio)
|
||||
err := component.CheckMinio(minio)
|
||||
return err
|
||||
}
|
||||
|
||||
@ -149,7 +155,7 @@ func checkKafka() error {
|
||||
Addr: config.Config.Kafka.Addr,
|
||||
}
|
||||
|
||||
_, kafkaClient, err := component.CheckKafka(kafkaStu)
|
||||
kafkaClient, err := component.CheckKafka(kafkaStu)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -1,17 +1,3 @@
|
||||
// Copyright © 2023 OpenIM. All rights reserved.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
@ -22,6 +8,11 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
maxprocs.Set()
|
||||
fmt.Print(runtime.GOMAXPROCS(0))
|
||||
// Set maxprocs with a custom logger that does nothing to ignore logs.
|
||||
maxprocs.Set(maxprocs.Logger(func(string, ...interface{}) {
|
||||
// Intentionally left blank to suppress all log output from automaxprocs.
|
||||
}))
|
||||
|
||||
// Now this will print the GOMAXPROCS value without printing the automaxprocs log message.
|
||||
fmt.Println(runtime.GOMAXPROCS(0))
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user