mirror of
https://gitee.com/acl-dev/acl.git
synced 2024-11-29 18:37:41 +08:00
wizard can create service conf for other service which can be managed by acl_master.
This commit is contained in:
parent
c64040e154
commit
6db130c534
@ -1,7 +1,6 @@
|
||||
#include "stdafx.h"
|
||||
#include "file_tmpl.h"
|
||||
|
||||
|
||||
file_tmpl::file_tmpl(void)
|
||||
{
|
||||
}
|
||||
@ -159,6 +158,17 @@ bool file_tmpl::create_common()
|
||||
return files_copy(name, tab);
|
||||
}
|
||||
|
||||
bool file_tmpl::create_other()
|
||||
{
|
||||
if (!copy_and_replace("setup-other.sh", "setup.sh", true)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
acl::string path(project_name_);
|
||||
path += ".cf";
|
||||
return copy_and_replace("master_other.cf", path);
|
||||
}
|
||||
|
||||
bool file_tmpl::file_copy(const char* from, const char* to_in)
|
||||
{
|
||||
string to_buf;
|
||||
|
@ -23,6 +23,7 @@ public:
|
||||
bool copy_and_replace(const char* from,
|
||||
const char* to, bool exec = false);
|
||||
bool create_common();
|
||||
bool create_other();
|
||||
|
||||
bool file_copy(const char* from, const char* to);
|
||||
bool files_copy(const char* name, const FILE_FROM_TO* tab);
|
||||
|
@ -175,6 +175,7 @@ void master_creator()
|
||||
" r: for master_rpc\r\n"
|
||||
" u: for master_udp\r\n"
|
||||
" f: for master_fiber\r\n"
|
||||
" o: for other service\r\n"
|
||||
" s: skip choose, try again\r\n");
|
||||
printf(">");
|
||||
fflush(stdout);
|
||||
@ -210,14 +211,16 @@ void master_creator()
|
||||
tmpl.create_common();
|
||||
create_master_fiber(tmpl);
|
||||
break;
|
||||
} else if (strcasecmp(buf, "o") == 0) {
|
||||
tmpl.create_other();
|
||||
break;
|
||||
} else if (strcasecmp(buf, "s") == 0) {
|
||||
goto END;
|
||||
break;
|
||||
} else {
|
||||
printf("unknown ch: %s\r\n", buf);
|
||||
}
|
||||
}
|
||||
|
||||
END:
|
||||
for (int i = 0; i < 78; i++) {
|
||||
putchar('-');
|
||||
}
|
||||
|
50
app/wizard/tmpl/master/master_other.cf
Normal file
50
app/wizard/tmpl/master/master_other.cf
Normal file
@ -0,0 +1,50 @@
|
||||
service $<PROGRAM> {
|
||||
# 进程是否禁止运行
|
||||
master_disable = no
|
||||
|
||||
# 服务类型, 当为 none 时, 则表示由子进程自行监听服务地址
|
||||
master_type = none
|
||||
|
||||
# 当子进程异常退出时,如果该值非空,则将子进程异常退出的消息通知该服务
|
||||
# master_notify_addr = /opt/soft/acl-master/var/public/monitor.sock
|
||||
|
||||
# 程序异常时的邮件通知接收者
|
||||
# master_notify_recipients = xxx@xxx.com
|
||||
|
||||
# 是否需要 chroot: n -- no, y -- yes
|
||||
master_chroot = n
|
||||
|
||||
# 最大进程数
|
||||
master_maxproc = 1
|
||||
|
||||
# 预启动进程数,该值不得大于 master_maxproc
|
||||
master_prefork = 1
|
||||
|
||||
# 进程程序名
|
||||
master_command = {install_path}/sbin/redis-server
|
||||
|
||||
# 指定程序版本, 方便管理模块获取
|
||||
master_version = 1.0.0-0
|
||||
|
||||
# 进程日志记录文件
|
||||
master_log = {install_path}/var/log/$<PROGRAM>.log
|
||||
|
||||
# 子进程标准输出信息转存日志文件
|
||||
master_stdout = {install_path}/var/log/$<PROGRAM>.stdout
|
||||
|
||||
# 子进程标准错误输出信息转存日志文件
|
||||
master_stderr = {install_path}/var/log/$<PROGRAM>.stderr
|
||||
|
||||
# 进程启动参数, acl_master 会以此配置项做为参数来启动子进程
|
||||
master_args =
|
||||
|
||||
# 如果该项非空, 则程序启动后将被切换至该目录
|
||||
master_home = {install_path}
|
||||
|
||||
# 针对由 Golang 编写的服务, 可以帮助其切换用户运行身份
|
||||
# master_owner = nobody
|
||||
|
||||
# 传递给服务子进程的环境变量, 可以通过 getenv("SERVICE_ENV") 获得此值
|
||||
# master_env = logme:FALSE, priority:E_LOG_INFO, action:E_LOG_PER_DAY, flush:sync_flush, imit_size:512,\
|
||||
# sync_action:E_LOG_SEM, sem_name:/tmp/ioctl_echo.sem
|
||||
}
|
190
app/wizard/tmpl/master/setup-other.sh
Executable file
190
app/wizard/tmpl/master/setup-other.sh
Executable file
@ -0,0 +1,190 @@
|
||||
#!/bin/sh
|
||||
|
||||
###############################################################################
|
||||
PATH=/bin:/usr/bin:/usr/sbin:/usr/etc:/sbin:/etc
|
||||
tempdir="/tmp"
|
||||
|
||||
umask 022
|
||||
|
||||
function censored_ls() {
|
||||
ls "$@" | egrep -v '^\.|/\.|CVS|RCS|SCCS|linux\.d|solaris\.d|hp_ux\.d|example'
|
||||
}
|
||||
|
||||
function compare_or_replace() {
|
||||
(cmp $2 $3 >/dev/null 2>&1 && echo Skipping $3...) || {
|
||||
echo Updating $3...
|
||||
rm -f $tempdir/junk || exit 1
|
||||
cp $2 $tempdir/junk || exit 1
|
||||
chmod $1 $tempdir/junk || exit 1
|
||||
mv -f $tempdir/junk $3 || exit 1
|
||||
chmod $1 $3 || exit 1
|
||||
}
|
||||
}
|
||||
###############################################################################
|
||||
RPATH=
|
||||
function guess_os() {
|
||||
os_name=`uname -s`
|
||||
os_type=`uname -p`
|
||||
case $os_name in
|
||||
Linux)
|
||||
case $os_type in
|
||||
x86_64)
|
||||
RPATH="linux64"
|
||||
;;
|
||||
i686)
|
||||
RPATH="linux32"
|
||||
;;
|
||||
aarch64)
|
||||
RPATH="aarch64"
|
||||
;;
|
||||
*)
|
||||
echo "unknown OS - $os_name $os_type"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
SunOS)
|
||||
case $os_type in
|
||||
i386)
|
||||
RPATH="sunos_x86"
|
||||
;;
|
||||
*)
|
||||
echo "unknown OS - $os_name $os_type"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
FreeBSD)
|
||||
RPATH="freebsd"
|
||||
;;
|
||||
Darwin)
|
||||
RPATH="macos"
|
||||
;;
|
||||
*)
|
||||
echo "unknown OS - $os_name $os_type"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
function create_path() {
|
||||
test -d $1 || mkdir -p $1 || {
|
||||
echo "can't mkdir $1"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
function copy_file() {
|
||||
test -f $2 && {
|
||||
compare_or_replace $1 $2 $3 || {
|
||||
echo "copy file: $2 error"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function install_file() {
|
||||
rm -f $tempdir/junk2 || {
|
||||
echo "can't remove file: $tempdir/junk2"
|
||||
exit 1
|
||||
}
|
||||
test -f $2 && {
|
||||
cat $2 | sed -e 's;{install_path};'$INSTALL_PATH';;' >$tempdir/junk2 || {
|
||||
echo "can't create file: $tempdir/junk2"
|
||||
exit 1
|
||||
}
|
||||
compare_or_replace $1 $tempdir/junk2 $3 || {
|
||||
echo "can't move to file: $3"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
rm -f $tempdir/junk2 || {
|
||||
echo "can't remove file: $tempdir/junk2"
|
||||
exit 1
|
||||
}
|
||||
}
|
||||
|
||||
###############################################################################
|
||||
INSTALL_PATH=
|
||||
|
||||
if [ $# -lt 1 ]
|
||||
then
|
||||
# echo "parameter not enougth($#)"
|
||||
echo "usage:$0 install_path"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ $# -eq 2 ]
|
||||
then
|
||||
PREFIX_PATH=$1
|
||||
INSTALL_PATH=$2
|
||||
else
|
||||
INSTALL_PATH=$1
|
||||
PREFIX_PATH=
|
||||
fi
|
||||
|
||||
case $INSTALL_PATH in
|
||||
/*) ;;
|
||||
no) ;;
|
||||
*) echo Error: $INSTALL_PATH should be an absolute path name. 1>&2; exit 1;;
|
||||
esac
|
||||
|
||||
echo Installing to $INSTALL_PATH...
|
||||
|
||||
CONF_PATH=$PREFIX_PATH$INSTALL_PATH/conf
|
||||
VAR_PATH=$PREFIX_PATH$INSTALL_PATH/var
|
||||
|
||||
SERVICE_NAME=$<PROGRAM>
|
||||
SERVICE_CONF=$CONF_PATH/$SERVICE_NAME.cf
|
||||
|
||||
###############################################################################
|
||||
|
||||
function create_all_path() {
|
||||
create_path $INSTALL_PATH
|
||||
create_path $CONF_PATH
|
||||
create_path $VAR_PATH
|
||||
create_path $VAR_PATH/log
|
||||
create_path $VAR_PATH/pid
|
||||
chmod 1777 $VAR_PATH/log
|
||||
}
|
||||
|
||||
function copy_all_file() {
|
||||
install_file a+x,go-wrx $SERVICE_NAME.cf $SERVICE_CONF
|
||||
}
|
||||
|
||||
MASTER_PATH=/opt/soft/acl-master
|
||||
MASTER_CONF=$MASTER_PATH/conf
|
||||
MASTER_SERVICES=$MASTER_CONF/services.cf
|
||||
MASTER_CTL=$MASTER_PATH/bin/master_ctl
|
||||
|
||||
function add_master_service() {
|
||||
echo ""
|
||||
|
||||
if [ ! -d $MASTER_CONF ]; then
|
||||
echo "$MASTER_CONF not exist!"
|
||||
return
|
||||
fi
|
||||
|
||||
if [ -f $MASTER_SERVICES ]; then
|
||||
has=`cat $MASTER_SERVICES | grep $SERVICE_CONF | wc -l`
|
||||
if [ $has != 0 ]; then
|
||||
echo "Service for $SERVICE_CONF already in $MASTER_SERVICES!"
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "$SERVICE_CONF" >> $MASTER_SERVICES
|
||||
echo "Service added for $SERVICE_CONF"
|
||||
|
||||
if [ -f $MASTER_CTL ]; then
|
||||
echo "Start your service by running:"
|
||||
echo "$MASTER_CTL -f $SERVICE_CONF -a start"
|
||||
fi
|
||||
}
|
||||
|
||||
guess_os
|
||||
create_all_path
|
||||
copy_all_file
|
||||
add_master_service
|
||||
|
||||
###############################################################################
|
Loading…
Reference in New Issue
Block a user