Autostart Script

Hi all,

https://manual.seafile.com/deploy/start_seafile_at_system_bootup.html
Started with a clean installation with Ubuntu 16.04 (hetzner) installation.

I got problems with the: /etc/init.d/seafile-server for Ubuntu and changed the following things:

# Change the value of fastcgi to false if fastcgi is not used
fastcgi=true
# Set the port of fastcgi, default is 8000. Change it if you need different.
fastcgi_port=8000
#
# Write a polite log message with date and time
#
echo -e "\n \n About to perform $1 for seafile at `date -Iseconds` \n " >> ${seafile_init_log}
echo -e "\n \n About to perform $1 for seahub at `date -Iseconds` \n " >> ${seahub_init_log}
case "$1" in
        start)
                su ${user} ${script_path}/seafile.sh ${1} >> ${seafile_init_log}
                if [ $fastcgi = true ];
                then
                        su ${user} ${script_path}/seahub.sh ${1}-fastcgi ${fastcgi_port} >> ${seahub_init_log}
                else
                        su ${user} ${script_path}/seahub.sh ${1} >> ${seahub_init_log}
                fi
        ;;
        restart)
                su ${user} ${script_path}/seafile.sh ${1} >> ${seafile_init_log}
                if [ $fastcgi = true ];
                then
                        su ${user} ${script_path}/seahub.sh ${1}-fastcgi ${fastcgi_port} >> ${seahub_init_log}
                else
                        su ${user} ${script_path}/seahub.sh ${1} >> ${seahub_init_log}
                fi
        ;;
        stop)
                su ${user} ${script_path}/seahub.sh ${1} >> ${seahub_init_log}
                su ${user} ${script_path}/seafile.sh ${1} >> ${seafile_init_log}
        ;;
        *)
                echo "Usage: /etc/init.d/seafile-server {start|stop|restart}"
                exit 1
        ;;
esac

sudo -u is not working correctly with default user rights, and it’s not safe to add the ‘seafile user’ to the sudo list.

Message:
user@cloud:~$ /etc/init.d/seafile-server start
seafile is not in the sudoers file. This incident will be reported.
seafile is not in the sudoers file. This incident will be reported.

This is the final fix after troubleshooting a hour.

you must use systemd for Ubuntu 16.04

this method will not work

look for For systems running systemd https://manual.seafile.com/deploy/start_seafile_at_system_bootup.html all the way to the end

The manual is a bit outdated in this chapter. Ubuntu 14.04 was not using systemd, they changed it in 15.04 or something like that. I will correct the manual in the next days.

Edit:

I updated the manual and it has been merged. You can have a look at it under the known hyperlink. You can mark this topic as solved now. :slight_smile:

1 Like

Why do you not just put it in crontab?
To start ./seafile and seahub?

No script needed.

Cron is designed to start scripts/applications at given times like backup jobs or something like that. The systemd approach is way better here because it controlls / supervises the seafile and seahub processes.

For the other approaches, you can see that the init scripts do more than just start the seafile and seahub services - that would be a one-line-script.

I see thanks, I do love all the help I’m getting here.
That’s why I’m choosing seafile, the documentation and the help is great.

But, if I’m using MariaDB how do I add it?
According to the documentation it’s say

[Unit]
Description=Seafile
# add mysql.service or postgresql.service depending on your database to the line below
After=network.target

So should I just put it like this?

[Unit]
Description=Seafile
After=network.target
mariadb.service

As far as I know the values for After= have to be separated by nothing but spaces. I think (but not 100% sure) that your solution does not work

It should be:

[Unit]
Description=Seafile
After=network.target mariadb.service

You can find the systemd documentation at https://www.freedesktop.org/software/systemd/man/systemd.unit.html#[Unit]%20Section%20Options

1 Like

Thanks, and then just change the username in the file to my user name.
My seafile setup are running on a VM that only have seafile on it so I did not create a seafile user.
I’m hoping that’s not an issue?
I did not see the point to do that as the VM are dedicated to seafile.

Yes, just change your username to the one you are using as mentioned in the manual. That’s no problem at all but a separate user could improve the security a bit if it does not have root rights like the normal user. I think that’s no problem in your case.

Ok, no I don’t think it’s an issue for me as if they take over the seafile user they can do the same harm to me as if they take the root user as seafile is the only thing that are running on the machine.
I can’t see in my case how it would improve the security.

Got it inside 2 firewalls and I have boosted the security in ubuntu etc :slight_smile:

I can’t get it to work, I have done everything right but it just want to work. it do work when I start it manuelly.

[Unit]
Description=Seafile
# add mysql.service or postgresql.service depending on your database to the lin$
After=network.target mariadb.service

[Service]
Type=oneshot
ExecStart=/tinytechnet/seafile-server-latest/seafile.sh start
ExecStop=/tinytechnet/seafile-server-latest/seafile.sh stop
RemainAfterExit=yes
User=rjohansson
Group=admin

[Install]
WantedBy=multi-user.target
[Unit]
Description=Seafile hub
After=network.target seafile.service

[Service]
# change start to start-fastcgi if you want to run fastcgi
ExecStart=/tinytechnet/seafile-server-latest/seahub.sh start-fastcgi
ExecStop=/tinytechnet/seafile-server-latest/seahub.sh stop
User=rjohansson
Group=admin
Type=oneshot
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

and I have also done:

sudo systemctl enable seafile.service
sudo systemctl enable seahub.service

I did find this error log, I’m confused the directory is correct:


Jun 22 21:09:23 seafile systemd[1]: Starting Seafile...
Jun 22 21:09:23 seafile systemd[1445]: seafile.service: Failed at step EXEC spawning /tinytechnet/seafile-server-latest/seafile.sh: No such file or directory
Jun 22 21:09:23 seafile systemd[1]: seafile.service: Main process exited, code=exited, status=203/EXEC
Jun 22 21:09:23 seafile systemd[1]: Failed to start Seafile.
Jun 22 21:09:23 seafile systemd[1]: seafile.service: Unit entered failed state.
Jun 22 21:09:23 seafile systemd[1]: seafile.service: Failed with result 'exit-code'.
Jun 22 21:09:23 seafile systemd[1]: Starting Seafile hub...
Jun 22 21:09:23 seafile systemd[1447]: seahub.service: Failed at step EXEC spawning /tinytechnet/seafile-server-latest/seahub.sh: No such file or directory
Jun 22 21:09:23 seafile systemd[1]: seahub.service: Main process exited, code=exited, status=203/EXEC
Jun 22 21:09:23 seafile systemd[1]: Failed to start Seafile hub.
Jun 22 21:09:23 seafile systemd[1]: seahub.service: Unit entered failed state.
Jun 22 21:09:23 seafile systemd[1]: seahub.service: Failed with result 'exit-code'.

I did fix it, I needed to typ /home/username/