Systemd ubuntu scripts in manual are faulty

Could it be possible that not all Pro services started before your server has started (maybe Elasticsearch?) and that’s why it fails?

no, as it always fails when i start seahub via services command, but it does not fail when i start it via bash seahub.sh.

I now updated to Seafile-Server-Pro 6.3.13 and the problem persists:

GNU nano 2.9.3 /etc/systemd/system/seafile.service

### BEGIN INIT INFO
# Provides:          seafile_server
# Required-Start:    $all
# Required-Stop:
# Default-Start:     5
# Default-Stop:         4
# Short-Description: Halts USB power...
### END INIT INFO
[Unit]
Description=Seafile
# add mysql.service or postgresql.service depending on your database to the line below
After=network.target mysql.service

[Service]
Type=forking
ExecStart=/mnt/xxx/seafile-server/seafile-server-latest/seafile.sh start
ExecStop=/mnt/xxx/seafile-server/seafile-server-latest/seafile.sh stop
User=f
Group=f

[Install]
WantedBy=multi-user.target

syslog gives me:

seahub.sh[24265]: Seahub is already running.
Mar 31 14:56:38 f systemd[1]: seahub.service: Control process exited, code=exited status=1
Mar 31 14:56:38 f systemd[1]: seahub.service: Failed with result 'exit-code'.
Mar 31 14:56:38 f systemd[1]: Failed to start Seafile hub.

i as always can invoke it directly by ./seahub.sh start but never via systemctl. what could that be? seafile service starts fine.

as systemd options i tried the once where it just runs the task and leaves it and fork and simple and exec, always the same, as if seahub could not find the relative folders when invoked that way.

Try debugging with another shell session to start seahub: sh -c " /mnt/xxx/seafile-server/seafile-server-latest/seahub.sh start

Is the disk correctly mounted on fstab? Are you sure, that the fs has execution permissions?

The seafile user f can write to the server dir and seahub.sh has
-rwxrwxr-x

sh -c works in the shell but not in the systemd script.
with “fs” do you mean filesystem or seafile user? my seafile user can run the script fine.

Just use /bin/sh -c "command"

no, does not work:

Process: 29366 ExecStart=/bin/sh -c /mnt/xxx/seafile-server/seafile-server-latest/seahub.sh start     (code=exited, status=1/FAILURE)
 Main PID: 29366 (code=exited, status=1/FAILURE)

Apr 02 22:17:42 f-pc systemd[1]: Started Seafile hub.
Apr 02 22:17:42 f-pc sh[29366]: Usage:
Apr 02 22:17:42 f-pc sh[29366]:   seahub.sh { start <port> | stop | restart <port> }
Apr 02 22:17:42 f-pc sh[29366]: To run seahub in fastcgi:
Apr 02 22:17:42 f-pc sh[29366]:   seahub.sh { start-fastcgi <port> | stop | restart-fastcgi <port> }
Apr 02 22:17:42 f-pc sh[29366]: <port> is optional, and defaults to 8000
Apr 02 22:17:42 f-pc systemd[1]: seahub.service: Main process exited, code=exited,     status=1/FAILURE
Apr 02 22:17:42 f-pc systemd[1]: seahub.service: Failed with result 'exit-code'.

Of course it fails, you forgot to " around your code. Otherwise start isn’t recognized. Do /bin/sh -c "/mnt/xxx/seafile-server/seafile-server-latest/seahub.sh start"
There are many big OSS who use /bin/sh -c as a workaround for scripting, because systemd hasn’t the capabilities of SysVinit, e.g. nearly every display manager does.

I have a new intall of ubuntu 18.04 and still seahub does not come up at boot. seafile is doing fine. after logging in, seahub service can be started fine manually. what is it? thanks

@gaga9999 I find it strange it doesn’t work for you. I did have issues once myself, and finally got it working. These are my scripts on Ubuntu 18.04:

For seafile:

 root@seafile:~# cat /etc/systemd/system/seafile.service 
[Unit]
Description=Seafile
# add mysql.service or postgresql.service depending on your database to the line below
After=network.target mysql.service

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

[Install]
WantedBy=multi-user.target

For seahub:

root@seafile:~# cat /etc/systemd/system/seahub.service 
[Unit]
Description=Seafile hub
After=network.target seafile.service

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

[Install]
WantedBy=multi-user.target

of course, the next thing is so that it will start at boot:

systemctl enable seafile
systemctl enable seahub
systemctl start seafile
systemctl start seahub

and that works fine for me. This is on Ubuntu 18.04:

root@seafile:~# lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 18.04.4 LTS
Release:	18.04
Codename:	bionic

if it’s still not working, will need to check your configuration - it’s most likely because of this than a problem with systemd.

Thanks it worked with your config. I had the config of the manual. And I have a user not root as user.
I rebooted 2 times now, every time it came up.

Glad to hear it finally worked for you.
Can you please mark as solved.

1 Like

@gaga9999 yes, my scripts were using as root. Anyway, just to make sure, I created a user called “seafile” on my system:

useradd -m -s /bin/false seafile

I then changed permissions on /opt/seafile:

chown -R seafile:seafile /opt/seafile

as that is where I have everything. And then I edited seafile.service and seahub.service and replaced User and Group values from root to seafile.

I started the services without problems for both seafile and seahub.

thanks, but i always have my seafile server run as the user.

If you read my reply properly, I just changed it to run as a user instead of root…

I wrote “the” user, i meant the user who is logged in. in my case its the only user using ist.

Yep, it depends how the system is configured. My server was setup without users so I ran as root, which is a bit of a security risk. Since then I have now configured a special user for it called “seafile”. I also have my own user on the system for myself, but prefer to keep seafile separate from my user login - again for security. If I run seafile as it’s own user, then it only has access to the files I gave it permission to, and not my user files also eg: in my home directory.

1 Like