From 3ea20a09bbd5e1fc76e0194a2b44cabad5ac13ee Mon Sep 17 00:00:00 2001 From: User Date: Sat, 26 Oct 2019 08:39:45 +0300 Subject: [PATCH] add unit file --- syncthing | 102 +++++++++++++++++++++++++++++++++++++++++++++ syncthing@.service | 12 ++++++ 2 files changed, 114 insertions(+) create mode 100755 syncthing create mode 100644 syncthing@.service diff --git a/syncthing b/syncthing new file mode 100755 index 0000000..c2762d5 --- /dev/null +++ b/syncthing @@ -0,0 +1,102 @@ +#!/bin/bash +# +# /etc/rc.d/init.d/syncthing +## +# chkconfig: 345 89 14 +# description: Starts and stops the syncthing server daemon +# processname: syncthing +# config: /etc/syncthing.conf +# pidfile: /var/run/syncthing/syncthing.pid +# + +# Source function library. +. /etc/init.d/functions + +PROG_NAME=syncthing +PID_FILE=${PID_FILE-/var/run/syncthing/syncthing.pid} +FS_USER=${FS_USER-root} +FS_FILE=${FS_FILE-/usr/bin/syncthing} +FS_HOME=${FS_HOME-/var/run/syncthing} +LOCK_FILE=/var/lock/subsys/syncthing +RETVAL=0 + +# Source usr/localions file +if [ -f /etc/sysconfig/syncthing ]; then + . /etc/sysconfig/syncthing +fi + +syncthing_ARGS="-gui-address='$GUI_ADDRESS'" + +# + +start() { + echo -n "Starting $PROG_NAME: " + if [ -e $LOCK_FILE ]; then + if [ -e $PID_FILE ] && [ -e /proc/`cat $PID_FILE` ]; then + echo + echo -n $"$PROG_NAME is already running."; + failure $"$PROG_NAME is already running."; + echo + return 1 + fi + fi + cd $FS_HOME + daemon --user $FS_USER --pidfile $PID_FILE "$FS_FILE $syncthing_ARGS $syncthing_PARAMS >/dev/null 2>&1" & + RETVAL=$? + echo + [ $RETVAL -eq 0 ] && touch $LOCK_FILE; + echo + return $RETVAL +} + +stop() { + echo -n "Shutting down $PROG_NAME: " + if [ ! -e $LOCK_FILE ]; then + echo + echo -n $"cannot stop $PROG_NAME: $PROG_NAME is not running." + failure $"cannot stop $PROG_NAME: $PROG_NAME is not running." + echo + return 1; + fi + cd $FS_HOME + $FS_FILE -stop > /dev/null 2>&1 + killproc $PROG_NAME + RETVAL=$? + echo + [ $RETVAL -eq 0 ] && rm -f $LOCK_FILE; + return $RETVAL +} + +rhstatus() { + status $PROG_NAME; +} + +case "$1" in + start) + start + ;; + stop) + stop + ;; + status) + status $PROG_NAME + RETVAL=$? + ;; + restart) + stop + start + ;; + reload) +# + ;; + condrestart) + [ -f $PID_FILE ] && restart || : + ;; + *) + echo "Usage: $PROG_NAME {start|stop|status|reload|restart}" + exit 1 + ;; +esac +exit $RETVAL diff --git a/syncthing@.service b/syncthing@.service new file mode 100644 index 0000000..d0405fe --- /dev/null +++ b/syncthing@.service @@ -0,0 +1,12 @@ +[Unit] +Description=Syncthing + +[Service] +Type=simple +User=%I +Environment=STNORESTART=yes +ExecStart=/usr/bin/syncthing +Restart=on-failure + +[Install] +WantedBy=multi-user.target