Skip to content

Instantly share code, notes, and snippets.

@bydmm
Last active January 16, 2017 07:34
Show Gist options
  • Save bydmm/9ea9f4e241ed8866012fed4ab122958d to your computer and use it in GitHub Desktop.
Save bydmm/9ea9f4e241ed8866012fed4ab122958d to your computer and use it in GitHub Desktop.
这行配置价值700元, 使用monit实现断电自动关机

带自动关机提醒的UPS要比纯电池版本的贵上700元所以决定自行配置。

sudo apt-get install monit #功能强大的检查程序
sudo vim /etc/monit/monitrc

以下配置在1234端口启动了http服务用来方便检查状态。两分钟一次,连续5次就关机。

###############################################################################
## Global section
###############################################################################
##
## Start Monit in the background (run as a daemon):

set daemon 120            # check services at 2-minute intervals

set logfile /var/log/monit.log

set idfile /var/lib/monit/id

set statefile /var/lib/monit/state

set eventqueue
    basedir /var/lib/monit/events # set the base directory where events will be stored
    slots 100                     # optionally limit the queue size

## Monit has an embedded HTTP interface which can be used to view status of
## services monitored and manage services from a web interface. The HTTP
## interface is also required if you want to issue Monit commands from the
## command line, such as 'monit status' or 'monit restart service' The reason
## for this is that the Monit client uses the HTTP interface to send these
## commands to a running Monit daemon. See the Monit Wiki if you want to
## enable SSL for the HTTP interface.

# 这个服务还自带一个web界面
set httpd port 3737 and
    use address 0.0.0.0
    allow admin:"admin"

###############################################################################
## Services
###############################################################################

## Check a remote host availability by issuing a ping test and check the
## content of a response from a web server. Up to three pings are sent and
## connection to a port and an application level network check is performed.
#

# 五次就关机。 路由器地址别忘了改
check host thisConfigWorth700  with address 192.168.0.1
  if failed
    ping
    for 5 cycles
  then exec "/sbin/shutdown -h now"

###############################################################################
## Includes
###############################################################################
##
## It is possible to include additional configuration parts from other files or
## directories.
#
   include /etc/monit/conf.d/*
   include /etc/monit/conf-enabled/*
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment