| 1 | #!/sbin/openrc-run |
| 2 | # SPDX-License-Identifier: GPL-3.0-or-later |
| 3 | |
| 4 | NETDATA_OWNER="@netdata_user_POST@:@netdata_user_POST@" |
| 5 | NETDATA_PIDFILE="@localstatedir_POST@/run/netdata/netdata.pid" |
| 6 | |
| 7 | description="Run the Netdata system monitoring agent." |
| 8 | |
| 9 | extra_started_commands="reload rotate" |
| 10 | description_reload="Reload health configuration." |
| 11 | description_rotate="Reopen log files." |
| 12 | |
| 13 | command_prefix="@sbindir_POST@" |
| 14 | command="${command_prefix}/netdata" |
| 15 | command_args="-P ${NETDATA_PIDFILE} ${NETDATA_EXTRA_ARGS}" |
| 16 | command_args_foreground="-D" |
| 17 | |
| 18 | depend() { |
| 19 | # Gentoo and its derivatives still use systemd-tmpfiles even with OpenRC, Alpine does not. |
| 20 | if rc-service --exists systemd-tmpfiles-setup; then |
| 21 | need net systemd-tmpfiles-setup |
| 22 | else |
| 23 | need net |
| 24 | fi |
| 25 | use logger |
| 26 | after apache2 squid nginx mysql named opensips upsd hostapd postfix lm_sensors |
| 27 | } |
| 28 | |
| 29 | start_pre() { |
| 30 | checkpath -o ${NETDATA_OWNER} -d @localstatedir_POST@/run/netdata |
| 31 | |
| 32 | if [ -z "${supervisor}" ]; then |
| 33 | pidfile="${NETDATA_PIDFILE}" |
| 34 | fi |
| 35 | } |
| 36 | |
| 37 | stop_pre() { |
| 38 | if [ "0${NETDATA_FORCE_EXIT}" -eq 1 ]; then |
| 39 | retry="TERM/${NETDATA_WAIT_EXIT_TIMEOUT:-60}/KILL/1" |
| 40 | else |
| 41 | retry="TERM/${NETDATA_WAIT_EXIT_TIMEOUT:-60}" |
| 42 | fi |
| 43 | } |
| 44 | |
| 45 | run_cmd() { |
| 46 | cmd="${1}" |
| 47 | msg="${2}" |
| 48 | failmsg="${3}" |
| 49 | signal="${4}" |
| 50 | |
| 51 | ebegin "${msg}" |
| 52 | if [ "${NETDATA_USE_NETDATACLI}" = 1 ]; then |
| 53 | "${command_prefix}/netdatacli" "${cmd}" >/dev/null |
| 54 | eend $? "${failmsg}" |
| 55 | elif [ "${supervisor}" = "supervise-daemon" ]; then |
| 56 | supervise-daemon "${RC_SVCNAME}" --signal "${signal}" |
| 57 | eend $? "${failmsg}" |
| 58 | else |
| 59 | start-stop-daemon --signal "${signal}" --pidfile "${pidfile}" |
| 60 | eend $? "${failmsg}" |
| 61 | fi |
| 62 | } |
| 63 | |
| 64 | reload() { |
| 65 | run_cmd reload-health \ |
| 66 | "Reloading Netdata health configuration" \ |
| 67 | "Failed to reload Netdata health configuration" \ |
| 68 | SIGUSR2 |
| 69 | } |
| 70 | |
| 71 | rotate() { |
| 72 | run_cmd reopen-logs \ |
| 73 | "Reopening Netdata log files" \ |
| 74 | "Failed to reopen Netdata log files" \ |
| 75 | SIGHUP |
| 76 | } |