-
-
Save oskapt/055d474d7bfef32c49469c1b53e8225f to your computer and use it in GitHub Desktop.
#!/bin/bash | |
# 1. Install this as `/usr/local/etc/rc.d/rc.netdata` | |
# 2. Create the directory `/volume1/netdata` | |
# 3. Symlink `/opt/netdata` to `/volume1/netdata` | |
# 4. Create a triggered task with Task Scheduler to call `/usr/local/etc/rc.d/rc.netdata start` at boot. | |
# - (You may have to turn on Advanced Mode in the Control Panel to see Task Scheduler) | |
# 5. Either reboot or run `sudo /usr/local/etc/rc.d/rc.netdata start` | |
# If you get an error about "Connection Failed," then you've already run Netdata and filled `/`. | |
# Stop netdata and move `/opt/netdata` to `/volume1/netdata` before continuing with step 3 above. | |
NETDATA_DIR=/opt/netdata | |
DAEMON=$NETDATA_DIR/bin/srv/netdata | |
TIMEOUT=30 # seconds to wait for netdata to exit | |
[ -x $DAEMON ] || exit 0 | |
function get_pid() { | |
pid=$( ps ax | grep -v grep | grep -m 1 $DAEMON | awk '{ print $1 }' ) | |
} | |
function check_netdata() { | |
count=1 | |
while [ $count -lt $TIMEOUT ]; do | |
get_pid | |
if [ -z $pid ]; then | |
break | |
else | |
sleep 1 | |
count=$(( $count + 1)) | |
fi | |
done | |
if [ $count -eq $TIMEOUT ]; then | |
echo "Timeout exceeded waiting for netdata to exit." | |
echo "Use '$0 kill' to force netdata to exit." | |
exit 1 | |
fi | |
} | |
function stop_netdata() { | |
get_pid | |
if [ "x$pid" != "x" ]; then | |
if [ "x$1" = "xforce" ]; then | |
kill -9 $pid | |
else | |
kill $pid | |
fi | |
else | |
echo "No running netdata found." | |
fi | |
} | |
function start_netdata() { | |
get_pid | |
if [ "x$pid" = "x" ]; then | |
echo "Starting Netdata." | |
$DAEMON | |
else | |
echo "Netdata already running with pid $pid" | |
fi | |
} | |
case "$1" in | |
start) | |
start_netdata | |
;; | |
stop) | |
echo "Shutting down Netdata." | |
stop_netdata | |
;; | |
restart) | |
echo "Shutting down Netdata." | |
stop_netdata | |
if [ "x$pid" != "x" ]; then | |
echo "Waiting maximum of $TIMEOUT seconds for netdata to exit." | |
fi | |
check_netdata | |
start_netdata | |
;; | |
kill) | |
echo "Killing netdata." | |
stop_netdata force | |
;; | |
status) | |
get_pid | |
if [ "x$pid" != "x" ]; then | |
echo "Netdata running with PID $pid" | |
else | |
echo "No running netdata found." | |
fi | |
;; | |
*) | |
echo "Usage: $0 {start|stop|kill|restart|status}" | |
exit 1 | |
esac | |
exit 0 |
Synology DSM >= 6.1 no longer calls
rc.local
, so I've updated the script with new instructions.First, don't let Netdata write to
/opt/netdata
because the DSM root partition is only ~2GB in size. Symlink/opt/netdata
to/volume1/netdata
.Second, use Task Scheduler to create a Triggered Task that fires at boot and calls
/usr/local/etc/rc.d/rc.netdata start
. I'm not sure if/etc
gets overwritten during DSM updates, but allegedly/usr/local/etc/rc.d
is safe. I haven't tried an upgrade yet. Alternatively you can put it in/volume1/netdata
and call it from there.
Hi, does auto update of netdata works using this solution for you?
I tried and after updating using kickstart script, netdata doesn't start anymore. Kickstart script creates a systemd service which seems to be having some issues due to symlink i think.
No idea. I don't use netdata anymore.
Synology DSM >= 6.1 no longer calls
rc.local
, so I've updated the script with new instructions.First, don't let Netdata write to
/opt/netdata
because the DSM root partition is only ~2GB in size. Symlink/opt/netdata
to/volume1/netdata
.Second, use Task Scheduler to create a Triggered Task that fires at boot and calls
/usr/local/etc/rc.d/rc.netdata start
. I'm not sure if/etc
gets overwritten during DSM updates, but allegedly/usr/local/etc/rc.d
is safe. I haven't tried an upgrade yet. Alternatively you can put it in/volume1/netdata
and call it from there.