Garbage collector won´t work

Hi,

i´m using seafile community edition 6.0.4 on a raspberry pi 3. I´ve written a shell script for a daily backup (scheduled via cron).

If i start the gc script manually (after the service was manually stopped) everything works fine. I´ve also tried to add a 10 second timeout in the script but the scheduled script version doesn´t work :frowning:

The resulting log says “seafile server is still running, stop it by “seafile.sh stop””
Here is the backup script I´m using which causes these problems.

github Script

The important lines are between line 31 and 45. Any ideas why the manual gc run works but the scheduled doesn´t?

So I think it is just as the log states – the seafile server is still running.

What will be the output if you add a status check before line 42
service seafile-server status

Which user executes the script? Does it have enough permission?

Hi,

thanks for your ideas. I added the status output to the script. For some reason there was no status line in the log file last night :confused:
I´ve just started the script manually and everything works fine.
Somehow the cron tirggered run won´t work properly but the manual start does.

For both starts i´ve used the root user (sudo ./backup for manual and sudo crontab -e for cron)

Here is the output of the manual start today:

seafile-server.service - LSB: Starts Seafile Server
Loaded: loaded (/etc/init.d/seafile-server)
Active: inactive (dead) since So 2017-02-12 12:39:58 CET; 66ms ago
Process: 3727 ExecStop=/etc/init.d/seafile-server stop (code=exited, status=0/SUCCESS)
Process: 27461 ExecStart=/etc/init.d/seafile-server start (code=exited, status=0/SUCCESS)

Feb 06 15:24:31 pi31 sudo[27466]: root : TTY=unknown ; PWD=/ ; USER=pi ; COMMAND=/mnt/pidrive/seafile/seafile-server-latest/seafile.sh start
Feb 06 15:24:31 pi31 sudo[27466]: pam_unix(sudo:session): session opened for user pi by (uid=0)
Feb 06 15:24:35 pi31 sudo[27466]: pam_unix(sudo:session): session closed for user pi
Feb 06 15:24:35 pi31 sudo[27557]: root : TTY=unknown ; PWD=/ ; USER=pi ; COMMAND=/mnt/pidrive/seafile/seafile-server-latest/seahub.sh start-fastcgi 8000
Feb 06 15:24:35 pi31 sudo[27557]: pam_unix(sudo:session): session opened for user pi by (uid=0)
Feb 06 15:24:35 pi31 seafile-server[27461]: /mnt/pidrive/seafile/seafile-server-latest/seahub.sh: Zeile 207: Warnung: setlocale: LC_ALL: Kann die Locale nicht ändern (en_US.UTF-8): Datei oder Verzeichnis nicht gefunden
Feb 06 15:24:51 pi31 sudo[27557]: pam_unix(sudo:session): session closed for user pi
Feb 06 15:24:51 pi31 systemd[1]: Started LSB: Starts Seafile Server.
Feb 12 12:39:57 pi31 systemd[1]: Stopping LSB: Starts Seafile Server…
Feb 12 12:39:58 pi31 sudo[3732]: root : TTY=unknown ; PWD=/ ; USER=pi ; COMMAND=/mnt/pidrive/seafile/seafile-server-latest/seahub.sh stop
Feb 12 12:39:58 pi31 sudo[3732]: pam_unix(sudo:session): session opened for user pi by (uid=0)
Feb 12 12:39:58 pi31 sudo[3732]: pam_unix(sudo:session): session closed for user pi
Feb 12 12:39:58 pi31 sudo[3745]: root : TTY=unknown ; PWD=/ ; USER=pi ; COMMAND=/mnt/pidrive/seafile/seafile-server-latest/seafile.sh stop
Feb 12 12:39:58 pi31 sudo[3745]: pam_unix(sudo:session): session opened for user pi by (uid=0)
Feb 12 12:39:58 pi31 sudo[3745]: pam_unix(sudo:session): session closed for user pi
Feb 12 12:39:58 pi31 systemd[1]: Stopped LSB: Starts Seafile Server.
Wait for 10 seconds
\t 1 2 3 4 5 6 7 8 9 10 Finished waiting.

Starting seafserv-gc, please wait …
[02/12/17 12:40:09] gc-core.c(440): GC version 1 repo Privat(xxx-xxx-xxx-xxx-xxx)
[02/12/17 12:40:18] gc-core.c(313): GC started. Total block number is 72899.
[02/12/17 12:40:18] gc-core.c(46): GC index size is 36449 Byte.
[02/12/17 12:40:18] gc-core.c(327): Populating index.
[02/12/17 12:40:18] gc-core.c(181): Populating index for repo xxx.

Any ideas why the cron triggered run is different?

I forgot the seafile script doesn’t support the ‘status’ command.

You could replace it with this command: ps -ax | grep -i “seafile”, before executing the GC, which prints out all seafile related processes to check if the seafile server is still running

Looks like the service doesn´t get stopped properly :frowning:
I guess the executing user is root/has root previleges if the scheduled entry was made with “sudo crontab -e”. I have no idea why the service looks like it´s getting stopped but still running.

Here´s the log from last night:

e Stopping SeaFile Deamon e
e Deamon stopped e

12352 ? Ss 0:00 /mnt/pidrive/seafile/seafile-server-6.0.4/seafile/bin/seafile-controller -c /mnt/pidrive/seafile/ccnet -d /mnt/pidrive/seafile/seafile-data -F /mnt/pidrive/seafile/conf
12354 ? Ss 0:01 ccnet-server -F /mnt/pidrive/seafile/conf -c /mnt/pidrive/seafile/ccnet -f /mnt/pidrive/seafile/logs/ccnet.log -d -P /mnt/pidrive/seafile/pids/ccnet.pid
12357 ? Ssl 0:30 seaf-server -F /mnt/pidrive/seafile/conf -c /mnt/pidrive/seafile/ccnet -d /mnt/pidrive/seafile/seafile-data -l /mnt/pidrive/seafile/logs/seafile.log -P /mnt/pidrive/seafile/pids/seaf-server.pid
12449 ? S 0:00 python2.7 /mnt/pidrive/seafile/seafile-server-6.0.4/seahub/manage.py runfcgi host=127.0.0.1 port=8000 pidfile=/mnt/pidrive/seafile/seafile-server-6.0.4/runtime/seahub.pid outlog=/mnt/pidrive/seafile/seafile-server-6.0.4/runtime/access.log errlog=/mnt/pidrive/seafile/seafile-server-6.0.4/runtime/error.log
12450 ? S 0:08 python2.7 /mnt/pidrive/seafile/seafile-server-6.0.4/seahub/manage.py runfcgi host=127.0.0.1 port=8000 pidfile=/mnt/pidrive/seafile/seafile-server-6.0.4/runtime/seahub.pid outlog=/mnt/pidrive/seafile/seafile-server-6.0.4/runtime/access.log errlog=/mnt/pidrive/seafile/seafile-server-6.0.4/runtime/error.log
12451 ? S 0:10 python2.7 /mnt/pidrive/seafile/seafile-server-6.0.4/seahub/manage.py runfcgi host=127.0.0.1 port=8000 pidfile=/mnt/pidrive/seafile/seafile-server-6.0.4/runtime/seahub.pid outlog=/mnt/pidrive/seafile/seafile-server-6.0.4/runtime/access.log errlog=/mnt/pidrive/seafile/seafile-server-6.0.4/runtime/error.log
12452 ? S 0:10 python2.7 /mnt/pidrive/seafile/seafile-server-6.0.4/seahub/manage.py runfcgi host=127.0.0.1 port=8000 pidfile=/mnt/pidrive/seafile/seafile-server-6.0.4/runtime/seahub.pid outlog=/mnt/pidrive/seafile/seafile-server-6.0.4/runtime/access.log errlog=/mnt/pidrive/seafile/seafile-server-6.0.4/runtime/error.log
12453 ? S 0:09 python2.7 /mnt/pidrive/seafile/seafile-server-6.0.4/seahub/manage.py runfcgi host=127.0.0.1 port=8000 pidfile=/mnt/pidrive/seafile/seafile-server-6.0.4/runtime/seahub.pid outlog=/mnt/pidrive/seafile/seafile-server-6.0.4/runtime/access.log errlog=/mnt/pidrive/seafile/seafile-server-6.0.4/runtime/error.log
12454 ? S 0:10 python2.7 /mnt/pidrive/seafile/seafile-server-6.0.4/seahub/manage.py runfcgi host=127.0.0.1 port=8000 pidfile=/mnt/pidrive/seafile/seafile-server-6.0.4/runtime/seahub.pid outlog=/mnt/pidrive/seafile/seafile-server-6.0.4/runtime/access.log errlog=/mnt/pidrive/seafile/seafile-server-6.0.4/runtime/error.log
13889 ? Ss 0:00 /bin/sh -c /mnt/pidrive/seafile/scripts/backup.sh
13890 ? S 0:00 /bin/bash /mnt/pidrive/seafile/scripts/backup.sh
13911 ? S 0:00 grep -i seafile
13912 ? S 0:00 tee -a /mnt/pidrive/seafile/logs/backup-2017-02-14-03-00-01.log
e Wait for 10 seconds e
e Finished waiting. e

12352 ? Ss 0:00 /mnt/pidrive/seafile/seafile-server-6.0.4/seafile/bin/seafile-controller -c /mnt/pidrive/seafile/ccnet -d /mnt/pidrive/seafile/seafile-data -F /mnt/pidrive/seafile/conf
12354 ? Ss 0:01 ccnet-server -F /mnt/pidrive/seafile/conf -c /mnt/pidrive/seafile/ccnet -f /mnt/pidrive/seafile/logs/ccnet.log -d -P /mnt/pidrive/seafile/pids/ccnet.pid
12357 ? Ssl 0:30 seaf-server -F /mnt/pidrive/seafile/conf -c /mnt/pidrive/seafile/ccnet -d /mnt/pidrive/seafile/seafile-data -l /mnt/pidrive/seafile/logs/seafile.log -P /mnt/pidrive/seafile/pids/seaf-server.pid
12449 ? S 0:00 python2.7 /mnt/pidrive/seafile/seafile-server-6.0.4/seahub/manage.py runfcgi host=127.0.0.1 port=8000 pidfile=/mnt/pidrive/seafile/seafile-server-6.0.4/runtime/seahub.pid outlog=/mnt/pidrive/seafile/seafile-server-6.0.4/runtime/access.log errlog=/mnt/pidrive/seafile/seafile-server-6.0.4/runtime/error.log
12450 ? S 0:08 python2.7 /mnt/pidrive/seafile/seafile-server-6.0.4/seahub/manage.py runfcgi host=127.0.0.1 port=8000 pidfile=/mnt/pidrive/seafile/seafile-server-6.0.4/runtime/seahub.pid outlog=/mnt/pidrive/seafile/seafile-server-6.0.4/runtime/access.log errlog=/mnt/pidrive/seafile/seafile-server-6.0.4/runtime/error.log
12451 ? S 0:10 python2.7 /mnt/pidrive/seafile/seafile-server-6.0.4/seahub/manage.py runfcgi host=127.0.0.1 port=8000 pidfile=/mnt/pidrive/seafile/seafile-server-6.0.4/runtime/seahub.pid outlog=/mnt/pidrive/seafile/seafile-server-6.0.4/runtime/access.log errlog=/mnt/pidrive/seafile/seafile-server-6.0.4/runtime/error.log
12452 ? S 0:10 python2.7 /mnt/pidrive/seafile/seafile-server-6.0.4/seahub/manage.py runfcgi host=127.0.0.1 port=8000 pidfile=/mnt/pidrive/seafile/seafile-server-6.0.4/runtime/seahub.pid outlog=/mnt/pidrive/seafile/seafile-server-6.0.4/runtime/access.log errlog=/mnt/pidrive/seafile/seafile-server-6.0.4/runtime/error.log
12453 ? S 0:09 python2.7 /mnt/pidrive/seafile/seafile-server-6.0.4/seahub/manage.py runfcgi host=127.0.0.1 port=8000 pidfile=/mnt/pidrive/seafile/seafile-server-6.0.4/runtime/seahub.pid outlog=/mnt/pidrive/seafile/seafile-server-6.0.4/runtime/access.log errlog=/mnt/pidrive/seafile/seafile-server-6.0.4/runtime/error.log
12454 ? S 0:10 python2.7 /mnt/pidrive/seafile/seafile-server-6.0.4/seahub/manage.py runfcgi host=127.0.0.1 port=8000 pidfile=/mnt/pidrive/seafile/seafile-server-6.0.4/runtime/seahub.pid outlog=/mnt/pidrive/seafile/seafile-server-6.0.4/runtime/access.log errlog=/mnt/pidrive/seafile/seafile-server-6.0.4/runtime/error.log
13889 ? Ss 0:00 /bin/sh -c /mnt/pidrive/seafile/scripts/backup.sh
13890 ? S 0:00 /bin/bash /mnt/pidrive/seafile/scripts/backup.sh
13928 ? S 0:00 grep -i seafile
13929 ? S 0:00 tee -a /mnt/pidrive/seafile/logs/backup-2017-02-14-03-00-01.log
e Starting GC e

seafile server is still running, stop it by “seafile.sh stop”

The command “service seafile-server stop” would redirect the output to some log files.
Can you check these two log files?
${seafile_dir}/logs/seafile.init.log
${seafile_dir}/logs/seahub.init.log

Check if they include any clue why the server fails to stop

your script doesn’t log stderr. try adding exec 2>&1 to your script and maybe write the environment to the logfile (env >>$logFile).

the cron daemon should have sent mails containing the full output of your script. do you have mail delivery configured on your box?

seafile.init.log and seahub.init.log didn´t have any interesting content.
I´m not sure where to add the exec 2>&1 line. At the crontab schedule time or inside the script (where?).

I don´t have any mail service configured on this machine.

exec 2>&1 causes bash to redirect stderr to stdout. but i just realized that this doesn’t work in your case, because the stdout you pipe into tee is grabbed before stderr is redirected to stdout.

you have to redirect stderr everytime you pipe the output into tee.

just change
echo "stuff" | tee -a $logFile
to
echo "stuff" 2>&1 | tee -a $logFile

this will redirect stderr to stdout and then stdout is piped into tee. this way stderr and stdout will be captured into the logfile.

2>&1 is useless on the echo lines. echo doesn’t print anything to stderr.

use it on these lines

  • service seafile-server stop | tee -a $logFile
    service seafile-server stop 2>&1 | tee -a $logFile

  • $seafileDir/seafile-server-latest/seaf-gc.sh | tee -a $logFile
    $seafileDir/seafile-server-latest/seaf-gc.sh 2>&1 | tee -a $logFile

for debugging you can also put the following two lines after your variable definitions:

env | tee -a $logFile # print the current environment variables
id | tee -a $logFile # print user/group information

It´s getting weirder :open_mouth:

That´s the line i changed in the script (running as root via cron)
service seafile-server stop 2>&1

The log from last night:
/mnt/pidrive/seafile/scripts/backup.sh: Zeile 33: service: Command not found
(translated from the german error message).

May i better choose another way of stopping the service? :confused:

you mentioned earlier that the script works fine when started from the commandline. it looks to me that PATH isn’t set correctly and that maybe the script is not executed as root.

have you put these two lines in your script?

what is the user id with which your script is executed?
what is the value of the PATH environment variable?

It sounds to me like the PATH issue too. Probably /usr/sbin is not included in the PATH.

As a simple workaround, you could try replacing every
sudo service seafile-server {start/stop}
to
sudo /etc/init.d/seafile-server {start/stop}
in your script

env as user pi

TERM=xterm
SHELL=/bin/bash
SSH_CLIENT=192.168.178.45 51545 22
SSH_TTY=/dev/pts/0
USER=pi
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:.tar=01;31:.tgz=01;31:.arc=01;31:.arj=01;31:.taz=01;31:.lha=01;31:.lz4=01;31:.lzh=01;31:.lzma=01;31:.tlz=01;31:.txz=01;31:.tzo=01;31:.t7z=01;31:.zip=01;31:.z=01;31:.Z=01;31:.dz=01;31:.gz=01;31:.lrz=01;31:.lz=01;31:.lzo=01;31:.xz=01;31:.bz2=01;31:.bz=01;31:.tbz=01;31:.tbz2=01;31:.tz=01;31:.deb=01;31:.rpm=01;31:.jar=01;31:.war=01;31:.ear=01;31:.sar=01;31:.rar=01;31:.alz=01;31:.ace=01;31:.zoo=01;31:.cpio=01;31:.7z=01;31:.rz=01;31:.cab=01;31:.jpg=01;35:.jpeg=01;35:.gif=01;35:.bmp=01;35:.pbm=01;35:.pgm=01;35:.ppm=01;35:.tga=01;35:.xbm=01;35:.xpm=01;35:.tif=01;35:.tiff=01;35:.png=01;35:.svg=01;35:.svgz=01;35:.mng=01;35:.pcx=01;35:.mov=01;35:.mpg=01;35:.mpeg=01;35:.m2v=01;35:.mkv=01;35:.webm=01;35:.ogm=01;35:.mp4=01;35:.m4v=01;35:.mp4v=01;35:.vob=01;35:.qt=01;35:.nuv=01;35:.wmv=01;35:.asf=01;35:.rm=01;35:.rmvb=01;35:.flc=01;35:.avi=01;35:.fli=01;35:.flv=01;35:.gl=01;35:.dl=01;35:.xcf=01;35:.xwd=01;35:.yuv=01;35:.cgm=01;35:.emf=01;35:.axv=01;35:.anx=01;35:.ogv=01;35:.ogx=01;35:.aac=00;36:.au=00;36:.flac=00;36:.m4a=00;36:.mid=00;36:.midi=00;36:.mka=00;36:.mp3=00;36:.mpc=00;36:.ogg=00;36:.ra=00;36:.wav=00;36:.axa=00;36:.oga=00;36:.spx=00;36:.xspf=00;36:
MAIL=/var/mail/pi
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/games:/usr/games
PWD=/mnt/pidrive/seafile/scripts
LANG=de_DE.UTF-8
SHLVL=1
HOME=/home/pi
LOGNAME=pi
SSH_CONNECTION=192.168.178.45 51545 192.168.2.220 22
OLDPWD=/home/pi
_=/usr/bin/env

id as user pi

uid=1000(pi) gid=1000(pi) Gruppen=1000(pi),4(adm),20(dialout),24(cdrom),27(sudo),29(audio),44(video),46(plugdev),60(games),100(users),101(input),108(netdev),997(gpio),998(i2c),999(spi)

env as root

root@pi31:/mnt/pidrive/seafile/scripts# env
SHELL=/bin/bash
TERM=xterm
USER=root
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:.tar=01;31:.tgz=01;31:.arc=01;31:.arj=01;31:.taz=01;31:.lha=01;31:.lz4=01;31:.lzh=01;31:.lzma=01;31:.tlz=01;31:.txz=01;31:.tzo=01;31:.t7z=01;31:.zip=01;31:.z=01;31:.Z=01;31:.dz=01;31:.gz=01;31:.lrz=01;31:.lz=01;31:.lzo=01;31:.xz=01;31:.bz2=01;31:.bz=01;31:.tbz=01;31:.tbz2=01;31:.tz=01;31:.deb=01;31:.rpm=01;31:.jar=01;31:.war=01;31:.ear=01;31:.sar=01;31:.rar=01;31:.alz=01;31:.ace=01;31:.zoo=01;31:.cpio=01;31:.7z=01;31:.rz=01;31:.cab=01;31:.jpg=01;35:.jpeg=01;35:.gif=01;35:.bmp=01;35:.pbm=01;35:.pgm=01;35:.ppm=01;35:.tga=01;35:.xbm=01;35:.xpm=01;35:.tif=01;35:.tiff=01;35:.png=01;35:.svg=01;35:.svgz=01;35:.mng=01;35:.pcx=01;35:.mov=01;35:.mpg=01;35:.mpeg=01;35:.m2v=01;35:.mkv=01;35:.webm=01;35:.ogm=01;35:.mp4=01;35:.m4v=01;35:.mp4v=01;35:.vob=01;35:.qt=01;35:.nuv=01;35:.wmv=01;35:.asf=01;35:.rm=01;35:.rmvb=01;35:.flc=01;35:.avi=01;35:.fli=01;35:.flv=01;35:.gl=01;35:.dl=01;35:.xcf=01;35:.xwd=01;35:.yuv=01;35:.cgm=01;35:.emf=01;35:.axv=01;35:.anx=01;35:.ogv=01;35:.ogx=01;35:.aac=00;36:.au=00;36:.flac=00;36:.m4a=00;36:.mid=00;36:.midi=00;36:.mka=00;36:.mp3=00;36:.mpc=00;36:.ogg=00;36:.ra=00;36:.wav=00;36:.axa=00;36:.oga=00;36:.spx=00;36:.xspf=00;36:
SUDO_USER=pi
SUDO_UID=1000
USERNAME=root
MAIL=/var/mail/root
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
PWD=/mnt/pidrive/seafile/scripts
LANG=de_DE.UTF-8
SHLVL=1
SUDO_COMMAND=/bin/su
HOME=/root
LOGNAME=root
SUDO_GID=1000
_=/usr/bin/env

id as root

uid=0(root) gid=0(root) Gruppen=0(root)

Next nightly run I´ll try the attempt with
sudo /etc/init.d/seafile-server {start/stop}

sudo /etc/init.d/seafile-server stop 2>&1
did the job
the gc started successfully. I guess the sudo isn´t really needed when the script is runned by root. Does anybody know why root can´t access the service command (executed by cron)?

yes, you need to use the absolute path in crontab. You can get it running whereis service.

It is because a different environment is being used. See also http://stackoverflow.com/questions/2388087/how-to-get-cron-to-call-in-the-correct-paths