m-shell-scripts/services/zabbix_agent.service
2025-03-19 17:38:46 +08:00

59 lines
1.1 KiB
Desktop File

#!/bin/bash
function read_variable() {
readonly home_path="/usr/local/zabbix-7.0.1"
}
function build_variable() {
read_variable
readonly pid_file=${home_path}/zabbix_agentd.pid
readonly log_file=${home_path}/zabbix_agentd.log
readonly conf_path=${home_path}/etc/zabbix_agentd.conf
readonly sbin_path=${home_path}/sbin/zabbix_agentd
[ ! -d $home_path ] && echo "path not found" && exit
[ ! -f $conf_path ] && echo "conf not found" && exit
[ ! -f $sbin_path ] && echo "sbin not found" && exit
cd $home_path
}
function edit_server() {
build_variable
vim $conf_path
}
function start_server() {
build_variable
echo "" >$log_file
$sbin_path -c $conf_path
tail -f $log_file
}
function stop_server() {
build_variable
echo $pid_file
[ ! -f $pid_file ] && echo "pid not found" && exit
cat $pid_file | xargs kill
}
function restart_server() {
stop_server
start_server 2> /dev/null
}
case $1 in
"start")
start_server
;;
"stop")
stop_server
;;
"restart")
restart_server
;;
"edit")
edit_server
;;
*)
echo "start|stop|restart"
;;
esac