-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlaunch.sh
More file actions
executable file
·57 lines (45 loc) · 1.23 KB
/
launch.sh
File metadata and controls
executable file
·57 lines (45 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/zsh
wait_for_file() {
local file=$1
local timeout=${2:-60}
local start_time=$(date +%s)
while [ ! -f "$file" ]; do
if [ $(($(date +%s) - start_time)) -ge $timeout ]; then
echo "Timeout waiting for $file"
exit 1
fi
sleep 1
done
# Add a small delay to ensure file is fully written
sleep 1
}
cleanup() {
if [ -f "$path_config" ]; then
echo -e "\nStopping daemon..."
fi
if [ -f "$PID_FILE_PATH" ]; then
DAEMON_PID=$(cat "$PID_FILE_PATH")
sudo kill -TERM $DAEMON_PID
rm -f "$PID_FILE_PATH"
fi
rm -f "path_config.txt"
exit 0
}
trap cleanup SIGINT
# Kill any existing tail processes at startup
pkill -f "tail -f /var/log/syslog"
# Compile and run the daemon
g++ -o ./mydaemon main.cpp utils.cpp
sudo ./mydaemon
local path_config="path_config.txt"
# Wait for the configuration file
wait_for_file $path_config
# Read the path from the configuration file
PID_FILE_PATH=$(cat $path_config)
if [ -z "$PID_FILE_PATH" ]; then
echo "Error: Path configuration is empty"
exit 1
fi
echo "Using PID file path: $PID_FILE_PATH"
# Start new tail process
tail -f /var/log/syslog | grep --line-buffered mydaemon