When this runs, log output gets sent to regular syslog and can be handled by whatever syslog mechanisms you have in place.
jb@syncer:~$ sudo tail -f /var/log/syslog
May 21 14:06:15 syncer syncthing: [LGFPD] 14:06:15 INFO: syncthing v0.8.7-18-ge9eacfa (go1.2.2 linux-amd64) jb@jborg-mbp 2014-05-19 22:59:19 UTC
May 21 14:06:15 syncer syncthing: [LGFPD] 14:06:15 INFO: My ID: LGFPDIT7SKNNJVJZA4FC7QNCRKCE753K72BW5QD2FOZ7FRFEP57Q
May 21 14:06:15 syncer syncthing: [LGFPD] 14:06:15 INFO: Starting web GUI on http://0.0.0.0:8080/
May 21 14:06:15 syncer syncthing: [LGFPD] 14:06:15 INFO: Populating repository index
May 21 14:06:21 syncer syncthing: [LGFPD] 14:06:21 INFO: No UPnP IGD device found, no port mapping created (read udp4 0.0.0.0:46581: i/o timeout)
May 21 14:06:21 syncer syncthing: [LGFPD] 14:06:21 INFO: Sending local discovery announcements
We get a double timestamp, one from syncthing and one from syslog. Could have a flag to disable that in case the log data is timestamped externally but I haven’t been sufficiently annoyed by it yet.
Is there a way to pipe to “logger -t syncthing” in a init.d deamon script, that will work correctly both when used with “service start/stop” as well as when syncthing is restarting due to configuration change? I’m on debian (raspberry) and Ubuntu 14.4. Havent been able to make it work so far.
Thanks,
I updated the script to my raspberry pi raspian setup, and inserted a missing function (daemon_status), please see below, this has now been tested both with service start/stop/status, syncthing restart from GUI after config update, syncthing version auto update and rebooting. Hope it will help someone:
/etc/init.d script (named “syncthing”):
#!/bin/sh
### BEGIN INIT INFO
# Provides: syncthing
# Required-Start: $local_fs $remote_fs
# Required-Stop: $local_fs $remote_fs
# Should-Start: $network
# Should-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: daemonized version of syncthing.
# Description: Starts the syncthing daemon for user root
### END INIT INFO
# Package
PACKAGE="syncthing"
DNAME="Syncthing"
# Others
INSTALL_DIR="/usr/local/bin"
PATH="${INSTALL_DIR}:${PATH}"
USER="root"
SYNCTHING="${INSTALL_DIR}/syncthing.sh"
SYNCTHINGAPP="${INSTALL_DIR}/syncthing"
daemon_status ()
{
start-stop-daemon --start --test --exec ${SYNCTHINGAPP} >/dev/null 2>&1
if [ $? -eq 0 ]; then
return 1
else
return 0
fi
}
start_daemon ()
{
start-stop-daemon -b -o -c ${USER} -S -u ${USER} -x ${SYNCTHING}
}
stop_daemon ()
{
start-stop-daemon -o -c ${USER} -K -u ${USER} -x ${SYNCTHINGAPP}
}
case $1 in
start)
if daemon_status; then
echo ${DNAME} is already running
else
echo Starting ${DNAME} ...
start_daemon
fi
;;
stop)
if daemon_status; then
echo Stopping ${DNAME} ...
stop_daemon
else
echo ${DNAME} is not running
fi
;;
status)
if daemon_status; then
echo ${DNAME} is running
exit 0
else
echo ${DNAME} is not running
exit 1
fi
;;
log)
exit 1
;;
*)
exit 1
;;
esac
I have then created the following helping script to start syncthing and pipe output the the syslog daemon using the “logger” command. Script called “syncthing.sh” placed with syncthing binary: