{"id":347,"date":"2014-06-17T00:31:35","date_gmt":"2014-06-16T15:31:35","guid":{"rendered":"http:\/\/blog.ymyzk.com\/?p=347"},"modified":"2015-02-05T00:42:59","modified_gmt":"2015-02-04T15:42:59","slug":"raspberry-pi-mackerel-agent","status":"publish","type":"post","link":"https:\/\/blog.ymyzk.com\/2014\/06\/raspberry-pi-mackerel-agent\/","title":{"rendered":"Raspberry Pi \u306b mackerel-agent \u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3059\u308b\u65b9\u6cd5 (2015\u5e742\u6708\u66f4\u65b0)"},"content":{"rendered":"
Raspberry Pi \u306e armhf \u30a2\u30fc\u30ad\u30c6\u30af\u30c1\u30e3\u3092\u30b5\u30dd\u30fc\u30c8\u3057\u305f mackerel-agent \u306e\u30d0\u30a4\u30ca\u30ea\u304c\u63d0\u4f9b\u3055\u308c\u3066\u3044\u306a\u3044\u306e\u3067, \u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u304b\u3089\u30d3\u30eb\u30c9\u3059\u308b\u3053\u3068\u3067\u5229\u7528\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u307e\u3057\u305f. \u30c6\u30b9\u30c8\u3067\u3044\u304f\u3064\u304b\u306e\u30a8\u30e9\u30fc\u304c\u51fa\u307e\u3057\u305f\u304c, \u57fa\u672c\u7684\u306a\u6a5f\u80fd\u306f\u5229\u7528\u3067\u304d\u3066\u3044\u307e\u3059.<\/p>\n
\u307e\u305f, \u3053\u306e\u8a18\u4e8b\u306f Go \u8a00\u8a9e\u306e\u5229\u7528\u7d4c\u9a13\u306e\u5c11\u306a\u3044\u8005\u304c\u66f8\u3044\u3066\u3044\u308b\u305f\u3081\u3044\u304f\u3064\u304b\u306e\u8aa4\u308a\u3092\u542b\u3080\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059.<\/p>\n
<\/p>\n
make \u7b49\u3092\u5229\u7528\u3059\u308b\u305f\u3081\u306b build-essential \u3092, go \u3092\u5229\u7528\u3059\u308b\u305f\u3081\u306b golang \u30d1\u30c3\u30b1\u30fc\u30b8\u3092, \u30b3\u30fc\u30c9\u3092\u53d6\u5f97\u3059\u308b\u305f\u3081\u306b git \u3068 mercurial \u3092\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3057\u307e\u3059.<\/p>\n
$ sudo apt-get install build-essential golang git mercurial\r\n<\/pre>\nDebian 7 wheezy \u4ee5\u964d\u3067 golang \u30d1\u30c3\u30b1\u30fc\u30b8\u304c\u63d0\u4f9b\u3055\u308c\u3066\u3044\u307e\u3059\u304c, wheezy \u306e go \u306f\u53e4\u3044\u305f\u3081 mackerel-agent \u306e\u30d3\u30eb\u30c9\u306b\u5931\u6557\u3059\u308b\u3088\u3046\u3067\u3059.<\/p>\n
\u30b3\u30fc\u30c9\u306e\u53d6\u5f97<\/h2>\n
mackerel-agent \u306e\u30b3\u30fc\u30c9\u3092 GitHub \u304b\u3089\u53d6\u5f97\u3057\u307e\u3059.<\/p>\n
$ git clone https:\/\/github.com\/mackerelio\/mackerel-agent.git\r\n<\/pre>\n\u30d3\u30eb\u30c9<\/h2>\n
Go \u306e\u30b3\u30fc\u30c9\u3092\u30d3\u30eb\u30c9\u3059\u308b\u969b\u306b\u74b0\u5883\u5909\u6570 GOPATH \u3092\u8a2d\u5b9a\u3057\u3066\u304a\u304b\u306a\u3044\u3068\u30a8\u30e9\u30fc\u304c\u767a\u751f\u3059\u308b\u306e\u3067,
\n\u9069\u5f53\u306a\u30c7\u30a3\u30ec\u30af\u30c8\u30ea\u3092\u4f5c\u6210\u3057\u3066 GOPATH \u306b\u8a2d\u5b9a\u3057\u3066\u304a\u304d\u307e\u3059.<\/p>\n$ mkdir go\r\n$ export GOPATH=\/home\/pi\/go\r\n$ cd mackerel-agent\/\r\n$ make clean build\r\n<\/pre>\nbuild\/mackerel-agent \u306b\u30d0\u30a4\u30ca\u30ea\u304c\u51fa\u529b\u3055\u308c\u307e\u3059.<\/p>\n
\u30a4\u30f3\u30b9\u30c8\u30fc\u30eb\u3068\u8a2d\u5b9a<\/h2>\n
\u30d0\u30a4\u30ca\u30ea\u3092\u914d\u7f6e\u3057\u307e\u3059.<\/p>\n
$ sudo cp build\/mackerel-agent \/usr\/local\/bin\/\r\n<\/pre>\n\/etc\/init.d\/mackerel-agent \u306b init \u30b9\u30af\u30ea\u30d7\u30c8\u3092\u914d\u7f6e\u3057\u307e\u3059.
\n\u3053\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u306f deb \u5f62\u5f0f\u306e\u30d0\u30a4\u30ca\u30ea\u304b\u3089\u53d6\u5f97\u3057\u307e\u3057\u305f.<\/p>\n#!\/bin\/sh\r\n### BEGIN INIT INFO\r\n# Provides: mackerel-agent\r\n# Short-Description: 'mackerel.io agent beta'\r\n# Description: 'mackerel.io agent beta'\r\n# Author: Hatena\r\n# Required-Start: $syslog $network $remote_fs\r\n# Required-Stop: $syslog $network $remote_fs\r\n# Default-Start: 2 3 4 5\r\n# Default-Stop: 0 1 6\r\n### END INIT INFO\r\n\r\nNAME=mackerel-agent # Introduce the short server's name here\r\n\r\n[ -r \/etc\/default\/$NAME ] && . \/etc\/default\/$NAME\r\n\r\nPATH=\/sbin:\/usr\/sbin:\/bin:\/usr\/bin\r\nDAEMON=${DAEMON:=\"\/usr\/local\/bin\/$NAME\"}\r\nSCRIPTNAME=\/etc\/init.d\/$NAME\r\nLOGFILE=${LOGILE:=\"\/var\/log\/$NAME.log\"}\r\nPIDFILE=${PIDFILE:=\"\/var\/run\/$NAME.pid\"}\r\nROOT=${ROOT:=\"\/var\/lib\/$NAME\"}\r\n\r\n# Exit if the package is not installed\r\n[ -x $DAEMON ] || exit 0\r\n\r\n# Define LSB log_* functions.\r\n# Depend on lsb-base (>= 3.0-6) to ensure that this file is present.\r\n. \/lib\/lsb\/init-functions\r\n\r\n#\r\n# Function that starts the daemon\/service\r\n#\r\ndo_start()\r\n{\r\n $DAEMON ${APIBASE:+--apibase=$APIBASE} ${APIKEY:+--apikey=$APIKEY} --pidfile=$PIDFILE --root=$ROOT $OTHER_OPTS >>$LOGFILE 2>&1 &\r\n sleep 3\r\n kill -0 $(cat $PIDFILE 2>\/dev\/null) >\/dev\/null 2>&1\r\n return $?\r\n}\r\n\r\n#\r\n# Function that stops the daemon\/service\r\n#\r\ndo_stop()\r\n{\r\n start-stop-daemon --stop --quiet --retry=TERM\/30\/KILL\/5 --pidfile $PIDFILE --name $NAME\r\n RETVAL=\"$?\"\r\n [ \"$RETVAL\" = 2 ] && return 2\r\n start-stop-daemon --stop --quiet --oknodo --retry=0\/30\/KILL\/5 --exec $DAEMON\r\n [ \"$?\" = 2 ] && return 2\r\n # Many daemons don't delete their pidfiles when they exit.\r\n rm -f $PIDFILE\r\n return \"$RETVAL\"\r\n}\r\n\r\ncase \"$1\" in\r\n start)\r\n log_daemon_msg \"Starting $NAME\"\r\n do_start\r\n case \"$?\" in\r\n 0) log_end_msg 0 ;;\r\n *) log_end_msg 1 ;;\r\n esac\r\n ;;\r\n stop)\r\n log_daemon_msg \"Stopping $DESC\" \"$NAME\"\r\n do_stop\r\n case \"$?\" in\r\n 0|1) log_end_msg 0 ;;\r\n *) log_end_msg 1 ;;\r\n esac\r\n ;;\r\n status)\r\n status_of_proc \"$DAEMON\" \"$NAME\" && exit 0 || exit $?\r\n ;;\r\n restart)\r\n log_daemon_msg \"Restarting $DESC\" \"$NAME\"\r\n do_stop\r\n case \"$?\" in\r\n 0|1)\r\n do_start\r\n case \"$?\" in\r\n 0) log_end_msg 0 ;;\r\n *) log_end_msg 1 ;; # Failed to start\r\n esac\r\n ;;\r\n *)\r\n # Failed to stop\r\n log_end_msg 1\r\n ;;\r\n esac\r\n ;;\r\n *)\r\n echo \"Usage: $SCRIPTNAME {start|stop|status|restart}\" >&2\r\n exit 3\r\n ;;\r\nesac\r\n\r\n:\r\n<\/pre>\n\u81ea\u52d5\u8d77\u52d5\u3092\u6709\u52b9\u5316\u3057\u307e\u3059.<\/p>\n
$ sudo update-rc.d mackerel-agent defaults\r\n<\/pre>\n