O daemon Syncthing inicia manualmente usando o script, mas não na inicialização

1

Instalei o syncthing em uma máquina Linux Mint Debian Edition e estou tentando inicializá-lo no momento da inicialização usando um script de inicialização em /etc/init.d . Eu segui este tutorial . Os links simbólicos em /etc/rc.* existem e eu posso iniciar e parar o daemon bem quando eu executar o script manualmente (como root). No entanto, o script não é iniciado no momento da inicialização.

Este é o script:

#!/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: Multi-user daemonized version of syncthing.
# Description: Starts the syncthing daemon for all registered users.
### END INIT INFO

# Replace with users you want to run syncthing clients for
syncthing_USERS="XXXXXX"
DAEMON=/opt/syncthing-linux-amd64-v0.10.8/syncthing

echo "This is /etc/init.d/syncthing" > /tmp/syncthing.txt

startd() {
  echo "Trying to start daemons..." >> /tmp/syncthing.txt
  for stuser in $syncthing_USERS; do
    echo "Trying $stuser"  >> /tmp/syncthing.txt
    HOMEDIR=$(getent passwd $stuser | awk -F: '{print $6}')
    echo "HOMEDIR = $HOMEDIR"  >> /tmp/syncthing.txt
    echo "config = $config"  >> /tmp/syncthing.txt
    if [ -f $config ]; then
      echo "Starting syncthiing for $stuser"
      start-stop-daemon -b -o -c $stuser -S -u $stuser -x $DAEMON
    else
      echo "Couldn't start syncthing for $stuser (no $config found)"
    fi
  done
}

stopd() {
  for stuser in $syncthing_USERS; do
    dbpid=$(pgrep -fu $stuser $DAEMON)
    if [ ! -z "$dbpid" ]; then
      echo "Stopping syncthing for $stuser"
      start-stop-daemon -o -c $stuser -K -u $stuser -x $DAEMON
    fi
  done
}

status() {
  for stuser in $syncthing_USERS; do
    dbpid=$(pgrep -fu $stuser $DAEMON)
    if [ -z "$dbpid" ]; then
      echo "syncthing for USER $stuser: not running."
    else
      echo "syncthing for USER $stuser: running (pid $dbpid)"
    fi
  done
}

case "$1" in
  start) startd
    ;;
  stop) stopd
    ;;
  restart|reload|force-reload) stopd && startd
    ;;
  status) status
    ;;
  *) echo "Usage: /etc/init.d/syncthing {start|stop|reload|force-reload|restart|status}"
     exit 1
   ;;
esac

exit 0

Aqui estão os links simbólicos:

$find /etc/rc* -name "*syncthing*"
/etc/rc0.d/K01syncthing
/etc/rc1.d/K01syncthing
/etc/rc2.d/S01syncthing
/etc/rc3.d/S01syncthing
/etc/rc4.d/S01syncthing
/etc/rc5.d/S01syncthing
/etc/rc6.d/K01syncthing

e meu nível de execução atual é

$/sbin/runlevel
N 2

Note que eu inseri várias instruções echo no topo, que são canalizadas em um arquivo em / tmp para depuração. Surpreendentemente, o script é executado no momento da inicialização, mas o daemon não é iniciado e o arquivo é lido

This is /etc/init.d/syncthing
Trying to start daemons...
Trying XXXXXX
HOMEDIR = /home/XXXXXX
config = 

Quando iniciado manualmente, executando o script como raiz após a inicialização, a saída também é criada e a saída é idêntica. O que está acontecendo?

Outra coisa que não entendo é que o script testa um arquivo $ config, mas essa variável nunca é definida e, portanto, o arquivo nunca existe. Mas às vezes esse teste parece ser verdadeiro e às vezes falso?

O que estou perdendo?

    
por mcenno 26.11.2014 / 13:52

1 resposta

2

Ok, eu acertei. Meu homedir é criptografado usando o ecryptfs, e ele é descriptografado somente quando eu efetuo login. Portanto, durante o tempo de inicialização, o binário não tem acesso ao ~ / .config / syncthing / *, que precisa ser iniciado corretamente. Quando eu inicio o script manualmente, estou logado, é claro, então tudo funciona.

Me estupe.

Btw, a opção --no-close de start-stop-daemon forneceu a sugestão e permitiu canalizar a saída do daemon para um arquivo. Muito obrigado pelos seus comentários, enfim!

Enno

    
por 27.11.2014 / 09:09