Can't start the clean-up script?

Hi,
I have been trying but I can’t start the cleanupScript.sh file.

I have tried:
./cleanupScript.sh
sudo ./cleanupScript.sh
sudo cleanupScript.sh

This is the error message I get:

sudo: ./cleanupScript.sh: command not found

Here is my file:

#!/bin/bash

#####
# Uncomment the following line if you rather want to run the script manually.
# Display usage if the script is not run as root user
        if [[ $USER != "root" ]]; then
                echo "This script must be run as root user!"
                exit 1
        fi
#
echo "Super User detected!!"
read -p "Press [ENTER] to start the procedure, this will stop the seafile server!!"
#####

# stop the server
echo Stopping the Seafile-Server...
/etc/systemd/system/seafile.service stop

echo Giving the server some time to shut down properly....
sleep 10

# run the cleanup
echo Seafile cleanup started...
sudo -u seafile /homex/xxx/xx/seafile-server-latest/seaf-gc.sh -r

echo Giving the server some time....
sleep 3

# start the server again
echo Starting the Seafile-Server...
/etc/systemd/system/seafile.service start

echo Seafile cleanup done!

That is the basic of my script with systemd (I did not write it).
You you start and stop the services and does the user Seafile exist?

What permission does the script have?

yes, I have change it to systemd as that’s where I have the startup script service according to seafile manual how to write it.
The script have user premission, yes the seafile user exist.

Try bash ./cleanupScript.sh or sudo bash ./cleanupScript.sh.

The script needs execution rights: chmod +x /path/to/yourscript.sh

Hi again @DerDanilo
I did try bash and it worked but I was given multi error messages:


Super User detected!!
Press [ENTER] to start the procedure, this will stop the seafile server!!
Stopping the Seafile-Server...
sudo: /etc/systemd/system/seafile.service: command not found
Giving the server some time to shut down properly....

Seafile cleanup started...

seafile server is still running, stop it by "seafile.sh stop"

Giving the server some time....
Starting the Seafile-Server...
./cleanupScript.sh: line 31: /etc/systemd/system/seafile.service: Permission denied
Seafile cleanup done!

When I was setting up the auto-startscript I was following this guide:
https://manual.seafile.com/deploy/start_seafile_at_system_bootup.html

And my autostart works, but as you can see it’s in the systemd folder.

You should rather use systemctl stop seafile.service and systemctl start seafile.service

My current setup is not with systemd, so you need to add the following to the script:
systemctl stop seahub.service and systemctl start seahub.service

Google is your friend:

1 Like

a quastion regarding this old topic, do I really need to run it with sudo command?
I did try to run the seaf-gc.sh -r with only ./seaf-gc.sh -r and I did get this:

Starting seafserv-gc, please wait …
[10/30/17 07:29:39] gc-core.c(384): === Repos deleted by users ===
[10/30/17 07:29:39] gc-core.c(392): GC deleted repo 73695e16.
[10/30/17 07:29:40] gc-core.c(392): GC deleted repo 6c280379.
[10/30/17 07:29:40] gc-core.c(392): GC deleted repo 168acfb9.
seafserv-gc run done

It seems that it will work without the sudo command.

nvm see the note above.