# buddhad **Repository Path**: jretty-org/buddhad ## Basic Information - **Project Name**: buddhad - **Description**: Buddhad®(如来®)运维多功能服务器Agent(使用Golang编写) - **Primary Language**: Go - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2022-06-13 - **Last Updated**: 2023-02-22 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Building the buddhad Before compiling the buddhad, make sure the go-lang 1.15+ is installed in your environment. To compile buddhad for **linux**, run following commands: 1. yum install glibc-static 2. 设置cn代理:go env -w GOPROXY=https://goproxy.cn 3. CGO_ENABLED=0 go build -a -ldflags "-linkmode external -extldflags -static" -o buddhad 3. 备用:o generate 4. 备用:GOOS=linux go build -tags release -a -ldflags "-linkmode external -extldflags -static" -o buddhad 建议使用docker build来构建linux版本,参见:**README-dev.md**文档。 # Run the buddhad After a buddhad binary has been generated, create a buddhad configuration file and start the buddhad like this: ```Shell $ cat buddha.yml programs: start_cmd: '/your/program args' $ buddhad -c buddha.yml ``` # Run base on source code ```Shell go run . -c /your-project-path/buddha.yml ``` # Run as daemon with web-ui Add the inet interface in your configuration: ```yml inet_http_server: port: 127.0.0.1:9001 buddhad_ctl_config: serverurl: unix:///tmp/buddhad.sock unix_http_server: file: /tmp/buddhad.sock ``` then run ```shell $ buddhad -c buddha.yml -d ``` In order to manage the daemon, you can use `buddhad ctl` subcommand, available subcommands are: `status`, `start`, `stop`, `shutdown`, `reload`. ```shell $ buddhad ctl status $ buddhad ctl status program-1 program-2... $ buddhad ctl status group:* $ buddhad ctl stop program-1 program-2... $ buddhad ctl stop group:* $ buddhad ctl stop all $ buddhad ctl start program-1 program-2... $ buddhad ctl start group:* $ buddhad ctl start all $ buddhad ctl shutdown $ buddhad ctl reload ``` # Supported features ## buddhad daemon settings Following parameters configured in "buddhad" section: - **logfile**. Where to put log of buddhad itself. - **logfile_maxbytes**. Rotate log-file after it exceeds this length. - **logfile_backups**. Number of rotated log-files to preserve. - **loglevel**. Logging verbosity, can be trace, debug, info, warning, error, fatal and panic (according to documentation of module used for this feature). Defaults to info. - **pidfile**. Full path to file containing process id of current buddhad instance. - **identifier**. Identifier of this buddhad instance. Required if there is more than one buddhad run on one machine in same namespace. ## program settings program settings configured in "programs" section and include these options: - **start_cmd**. Command to supervise. It can be given as full path to executable or can be calculated via PATH variable. Command line parameters also should be supplied in this string. - **process_name**. the process name - **autostart**. Should be command run on buddhad start? Defaults to **true**. - **startsecs**. The total number of seconds which the program needs to stay running after a startup to consider the start successful (moving the process from the STARTING state to the RUNNING state). Set to 0 to indicate that the program needn’t stay running for any particular amount of time. - **startretries**. The number of serial failure attempts that buddhad will allow when attempting to start the program before giving up and putting the process into an FATAL state. See Process States for explanation of the FATAL state. - **autorestart**. Automatically re-run command if it dies. - **exitcodes**. The list of “expected” exit codes for this program used with autorestart. If the autorestart parameter is set to unexpected, and the process exits in any other way than as a result of a buddha stop request, buddhad will restart the process if it exits with an exit code that is not defined in this list. - **stopsignal**. Signal to send to command to gracefully stop it. If more than one stopsignal is configured, when stoping the program, the buddha will send the signals to the program one by one with interval "stopwaitsecs". If the program does not exit after all the signals sent to the program, buddhad will kill the program. - **stopwaitsecs**. Amount of time to wait before sending SIGKILL to command to make it stop ungracefully. - **stdout_logfile**. Where STDOUT of command should be redirected. (Particular values described lower in this file). - **stdout_logfile_maxbytes**. Log size after exceed which log will be rotated. - **stdout_logfile_backups**. Number of rotated log-files to preserve. - **redirect_stderr**. Should STDERR be redirected to STDOUT. - **stderr_logfile**. Where STDERR of command should be redirected. (Particular values described lower in this file). - **stderr_logfile_maxbytes**. Log size after exceed which log will be rotated. - **stderr_logfile_backups**. Number of rotated log-files to preserve. - **environment**. List of VARIABLE=value to be passed to program. - **order**. The relative priority of the program in the start and shutdown ordering - **user**. Sudo to this USER or USER:GROUP right before exec command. - **directory**. Jump to this path and exec command there. - **restartpause**. Wait (at least) this amount of seconds after stpping suprevised program before strt it again. - **depends_on**. Define command start dependency. If program A depends on program B, C, the program B, C will be started before program A. ## Set default parameters for all programs All common parameters that are identical for all programs can be defined once in program with name "default" section and omited in all other program sections. ## Group Section "group" is supported and you can set "programs" item ## Logs buddhad can redirect stdout and stderr ( fields stdout_logfile, stderr_logfile ) of programs to: - **/dev/null**. Ignore the log - send it to /dev/null. - **/dev/stdout**. Write log to STDOUT. - **/dev/stderr**. Write log to STDERR. - **syslog**. Send the log to local syslog service. - **syslog @[protocol:]host[:port]**. Send log events to remote syslog server. Protocol must be "tcp" or "udp", if missing, "udp" assumed. If port is missing, for "udp" protocol, it's defaults to 514 and for "tcp" protocol, it's value is 6514. - **file name**. Write log to specified file. Multiple log files can be configured for the stdout_logfile and stderr_logfile with ',' as delimiter. For example: ```ini stdout_logfile = test.log, /dev/stdout ``` # Register service Autostart buddhad after os started. ```Shell # install sudo buddhad service install -c full_path_to_conf_file # uninstall sudo buddhad service uninstall # start buddhad service start # stop buddhad service stop ```