Code Monkey home page Code Monkey logo

supervise's People

Contributors

meetbill avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

lipeibin

supervise's Issues

【记录】守护的进程标准输出和标准错误到日志文件

场景

执行文件会输出信息到 stdout & stderr,如

test.sh

while :
do
    date
    sleep 1
done

直接执行如下命令

  ./supervise -p "status/test" -f "./test.sh 1>>__stdout 2>&1"

发现并没有产生 __stdout 文件

执行 lsof -p ${pid} 输出如下

COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF     NODE NAME
...
test.sh 22878 work    0u   CHR    1,3      0t0     1028 /dev/null
test.sh 22878 work    1u   CHR    1,3      0t0     1028 /dev/null
test.sh 22878 work    2u   CHR    1,3      0t0     1028 /dev/null

实现

如果不想改动原进程,可以在 supervise 上进行改动

diff --git a/supervise/supervise.c b/supervise/supervise.c
--- a/supervise/supervise.c
+++ b/supervise/supervise.c
@@ -463,6 +463,8 @@ static void trystart()
                case 0:
                        sig_uncatch(sig_child);
                        sig_unblock(sig_child);
+                       freopen("_stdout.log", "a+", stdout);
+                       freopen("_stderr.log", "a+", stderr);
                        execvp(cmd[0], cmdp);
                        write_log(fdlogwf, FATAL, "unable to start ", cmd[0], "\n");
                        _exit(1);

如果想可配置,可以将配置项配置到 supervise.conf 中

svc 获取信息时,子进程 pid 超过 65535 时会获取出错 bug

如果用 od -d status 或 od -t u2 status 读取 2 字节,无符号短整型,最大值是 65535。

-d  此参数的效果和同时指定"-tu2"参数相同

如果 cat /proc/sys/kernel/pid_max 大于这个数。od -d status 读出来的 pid 就有可能是错的。

static void pidchange()
{
	struct taia now;
	unsigned long u;

	taia_now(&now);
	taia_pack(status, &now);

	u = (unsigned long) pid;
	status[16] = u; u >>= 8;
	status[17] = u; u >>= 8;
	status[18] = u; u >>= 8;
	status[19] = u;
}

需要修改为

旧:
pid=$(od -d status | head -n 2 | tail -n 1 | awk '{print $2}')

需要改为:
od -An -j16 -N4 -tu4 status

编译失败

现象

make

make --directory=supervise
make[1]: Entering directory '/home/meetbill/supervise/supervise'
sh find-systype.sh > systype
rm -f compile
sh print-cc.sh > compile
chmod 555 compile
./compile byte_chr.c
./compile byte_copy.c
./compile byte_cr.c
./compile byte_diff.c
./compile byte_rchr.c
./compile fmt_uint.c
./compile fmt_uint0.c
./compile fmt_ulong.c
rm -f makelib
sh print-ar.sh > makelib
chmod 555 makelib
./compile scan_ulong.c
./compile str_chr.c
./compile str_diff.c
./compile str_len.c
./compile str_start.c
./makelib byte.a byte_chr.o byte_copy.o byte_cr.o byte_diff.o \
byte_rchr.o fmt_uint.o fmt_uint0.o fmt_ulong.o scan_ulong.o str_chr.o \
str_diff.o str_len.o str_start.o
make[1]: *** No rule to make target 'home', needed by 'choose'.  Stop.
make[1]: Leaving directory '/home/meetbill/supervise/supervise'
make: *** [Makefile:6: supervise] Error 2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.