Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

duanjigang1983 #40

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions examples/tskeeper/index.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
default:
name: tskeeper
version: '1.0.0'
release: '2'
packager: 'duanjigang'
summary: 'adding tskeeper as an example of multipkg'
group: 'cmesoft'
license: 'cmesoft'
description: 'cmd:cat source/desc.txt;hostname'
arch: 'x86_64'
requires: ## tskeeper requires 'procps' and daemontools to be installed firstly
- procps
- daemontools
provides: ### The package 'tskeeper' will provide something named as 'tskeeper-examples' and 'cmesoft-tskeeper'
- tskeeper-examples
- cmesoft-tskeeper
conflicts: ### sorry, i am conflicted with some rpms such as 'other-task-keeper' and 'all-task-keeper',
- other-task-keeper
- all-task-keeper
obsoletes: ## when u want to install old-tskeeper with 'yum install old-tskeeper', you will get me -'tkeeper' ^_^
- old-tskeeper
- taskeeper
files:
- "/etc/test_conf1.conf": ##just set attributes of this file, but not a configfile
group: "root"
perm: "0666"
owner: "root"
- "/etc/test_conf2.conf":
group: "root"
perm: "0777"
owner: "nobody"
config: "no" ## no matter what this value will be, 'config' tells multipkg 'please set me as a config file'
- "/etc/proclist.ini":
group: "root"
perm: "0666"
owner: "root"
config: "yes" ## no matter what this value will be, 'config' tells multipkg 'please set me as a config file'
- "/var/doc/tskeeper":
group: "root"
perm: "0444"
owner: "root"
doc: "xxoo" ## yes, 'doc' is still not supported by multipkg, but you may add your own codes or clone my branch

14 changes: 14 additions & 0 deletions examples/tskeeper/readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#by duanjigang <[email protected]> 2013-11-30 12:49
example to help understand:

1 source
2 scripts
3 root
4 .keep
5 requires
6 provides
7 conflicts
8 obsoletes
9 files
10 config

8 changes: 8 additions & 0 deletions examples/tskeeper/root/etc/proclist.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# author duanjigang @ 20070318 <[email protected]>
# updated by duanjigang @2013-11-30 <[email protected], [email protected] > for example of multipkg
# des: processess list to monitor in a linux system
# name------------------------path-----------------------------parameter------------------
#just a test program
<name="a.out"; path="/tmp/test/a.out"; param="p12 p12 p13",waittime="10",runtime="3">
#<name="test2"; path="/home/duanjigang/bin/test2"; param="p21 p22 p23 p24 p25",waittime="10", runtime="60">
#<name="test5"; path="/home/duanjigang/bin/test5"; param="p51 p52 p53",waittime="20",runtime="10">
58 changes: 58 additions & 0 deletions examples/tskeeper/root/etc/test_conf1.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#This is a test config file added by duanjigang @2013-11-30 11:40
#
#
[general]
rule_id = 17
rule_name = CME1124管理规则
rule_number = 4
time = 1291218105

[rule_1]
template_id = 21
template_name = TencentQQ
exename = QQ.exe
md5 = 8c568a9ecffc832187923b4515ed3ba4
type = 2
time_type = 2
start = 1-8-29
finish = 5-12-0
level = 3
pol = 5

[rule_2]
template_id = 22
template_name = 迅雷
exename = 迅雷
md5 = ede5a6a5726472f8d8ab86e349d8a72a
type = 2
time_type = 2
start = 1-13-0
finish = 5-17-29
level = 3
pol = 6

[rule_3]
template_id = 23
template_name = cmeAgent
exename = cmeAgent.exe
md5 = fec1d9f5ff19112efaf8acb7fe9689c2
type = 1
time_type = 1
start = 8-12-0
finish = 8-13-0
level = 1
pol = 6

[rule_4]
template_id = 24
template_name = ttplayer
exename = ttplayer.exe
md5 = aaebdd66e1e06dc5fbbdcfd5545f7b4e
type = 3
time_type = 3
start = 1288711125
finish = 1290784725
level = 2
pol = 5


76 changes: 76 additions & 0 deletions examples/tskeeper/root/etc/test_conf2.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#This is another test config file added by duanjigang @2013-11-30 11:40
#
#

[general]
rule_id = 17
rule_name = CME1124管理规则
rule_number = 5
time = 1291218105

[rule_1]
template_id = 1
template_name = ssh连接
proto = 1
type = 1
start_port = 22
end_port = 25
time_type = 1
start = 8-12-0
finish = 8-13-0
level = 1
pol = 7

[rule_2]
template_id = 2
template_name = mysql数据库
proto = 1
type = 2
start_port = 3306
end_port = 3306
time_type = 1
start = 8-12-0
finish = 8-13-0
level = 1
pol = 7

[rule_3]
template_id = 3
template_name = cme windows 客户端
proto = 1
type = 1
start_port = 1982
end_port = 1983
time_type = 1
start = 8-12-0
finish = 8-13-0
level = 1
pol = 7

[rule_4]
template_id = 4
template_name = FTP
proto = 1
type = 3
start_port = 21
end_port = 21
time_type = 1
start = 8-12-0
finish = 8-13-0
level = 1
pol = 7

[rule_5]
template_id = 5
template_name = TFTP
proto = 2
type = 3
start_port = 21
end_port = 21
time_type = 1
start = 8-12-0
finish = 8-13-0
level = 1
pol = 7


4 changes: 4 additions & 0 deletions examples/tskeeper/root/usr/bin/test_bin
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/bash
#added by duanjigang@2013-11-30 <[email protected],[email protected]>
echo "This is a test shell program by duanjigang <[email protected]> at 2013-11-30"

6 changes: 6 additions & 0 deletions examples/tskeeper/root/usr/bin/test_py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/python
# coding=utf-8

import sys

print "This is a test python program by duanjigang <[email protected]> at 2013-11-30 11:45"
Empty file.
1 change: 1 addition & 0 deletions examples/tskeeper/root/var/doc/tskeeper
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is an empty document just for test
1 change: 1 addition & 0 deletions examples/tskeeper/root/var/tskeeper/.keep
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hi,I was created by duanjigang at 2013-11-30 12:47 just to keep this dir in the rpm {China-hangzhou-jiangcun}
4 changes: 4 additions & 0 deletions examples/tskeeper/scripts/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh
make || exit 1
mkdir -p $DESTDIR/usr/bin/
install tskeeper $DESTDIR/usr/bin/
6 changes: 6 additions & 0 deletions examples/tskeeper/scripts/post.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

PATH=/usr/local/sbin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/local/bin
rm -f $DSTDIR/service/tskeeper
ln -s $DESTDIR/etc/service/tskeeper $DESTDIR/service/tskeeper
#chown -R nobody $DESTDIR/service/tskeeper/log/main
7 changes: 7 additions & 0 deletions examples/tskeeper/scripts/preun.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

if [ $1 = 0 ] ; then
/usr/local/bin/svc -dx /service/tskeeper
rm -f /service/tskeeper
fi

12 changes: 12 additions & 0 deletions examples/tskeeper/scripts/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
### by duanjigang at 2013-11-30
EXE="/usr/bin/tskeeper"
while true
do
echo "`date`: starting tskeeper now..."
if [ -f "$EXE" ]
then
$EXE
fi
sleep 5
done
13 changes: 13 additions & 0 deletions examples/tskeeper/source/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#author:duanjigang@20070318<[email protected]>
#add runtime to shut down illegal task @ 2008-07-29 by duanjigang
#updated to added it as an example for multipkg @ 2013-11-30 by duanjigang
#!/bin/sh
tskeeper:procKeeper.o process.o
gcc -o tskeeper procKeeper.o process.o
procKeeper.o:procKeeper.c
gcc -c procKeeper.c
process.o:process.c
gcc -c process.c
clean:
rm -fr *.o tskeeper

5 changes: 5 additions & 0 deletions examples/tskeeper/source/desc.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
this is a desc information for tskeeper

this is line 3

this is line 5 by duanjigang@2017-01-01
71 changes: 71 additions & 0 deletions examples/tskeeper/source/procKeeper.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
//procKeeper.c
#include "process.h"
#include <stdio.h>
const char * conf = "/etc/proclist.ini";

int main(int argc, char * argv[])
{
struct proc_struct current_proc_list[1024], config_proc_list[1024];
int current_run_size, config_run_size;
int i = 0;
config_run_size = get_proc_list_from_file(config_proc_list, 1024, conf);

if(config_run_size <= 0)
{
return 0;
}
//printf("%d\n", must_run_size);
//for(i = 0; i < must_run_size; i++)
//print_proc(&(must_run_proc_list[i]), 1);
printf ("%s:running now...\n", argv[0]);
while(1)
{
int i = 0;
int size = get_proc_list(current_proc_list, 1024);

for(i = 0; i < config_run_size; i++)
{
//do not find config task in current task list
if(proc_find(&(config_proc_list[i]), current_proc_list, size) < 0)
{
// it was runnig last time
if(config_proc_list[i].new_status == 1)
{
config_proc_list[i].new_status = 0;
config_proc_list[i].dead_time = 0;
}
//it was not running last time
if(config_proc_list[i].dead_counter >= 0)
{
config_proc_list[i].dead_time += 1;
if(config_proc_list[i].dead_time >= config_proc_list[i].dead_counter)
{
//restart process
startProc(&(config_proc_list[i]));
config_proc_list[i].dead_time = 0;
}
}

//print_proc(&(config_proc_list[i]), 1);
}
else
{
//print_proc(&(config_proc_list[i]), 1);
config_proc_list[i].new_status = 1;
config_proc_list[i].dead_time = 0;
if(config_proc_list[i].live_counter >= 0)
{
config_proc_list[i].live_time += 1;
if(config_proc_list[i].live_time > config_proc_list[i].live_counter)
{
killProc(&(config_proc_list[i]));
config_proc_list[i].live_time = 0;
}
}
}
}

sleep(1);
}
}

Loading