You are not logged in.

#1 2017-06-30 09:30:25

SmallAndSimple
Member
Registered: 2015-11-25
Posts: 50

[SOLVED] Dropbox (from AUR) and Systemd

So, lets talk about Dropbox: https://aur.archlinux.org/packages/dropbox/. We like to start this on login and thus we want systemd. It pretty easy:

 systemctl --user enable dropbox          
Created symlink /home/<user>/.config/systemd/user/default.target.wants/dropbox.service → /usr/lib/systemd/user/dropbox.service.

This works, but systemd believes it does not.

Arch :: ~ » ps -ef | grep dropbox
<user>     3464     1  0 11:14 pts/0    00:00:02 /home/<user>/.dropbox-dist/dropbox-lnx.x86_64-29.4.20/dropbox /newerversion
Arch :: ~ » systemctl --user status dropbox
● dropbox.service - Dropbox
   Loaded: loaded (/usr/lib/systemd/user/dropbox.service; enabled; vendor preset: enabled)
   Active: failed (Result: signal) since Fri 2017-06-30 11:14:45 CEST; 7min ago
 Main PID: 3174 (code=killed, signal=KILL)

jun 30 11:14:45 Arch-Jacko systemd[871]: dropbox.service: Unit entered failed state.
jun 30 11:14:45 Arch-Jacko systemd[871]: dropbox.service: Failed with result 'signal'.
jun 30 11:14:45 Arch-Jacko systemd[871]: dropbox.service: Service hold-off time over, scheduling restart.
jun 30 11:14:45 Arch-Jacko systemd[871]: Stopped Dropbox.
jun 30 11:14:45 Arch-Jacko systemd[871]: dropbox.service: Start request repeated too quickly.
jun 30 11:14:45 Arch-Jacko systemd[871]: Failed to start Dropbox.
jun 30 11:14:45 Arch-Jacko systemd[871]: dropbox.service: Unit entered failed state.
jun 30 11:14:45 Arch-Jacko systemd[871]: dropbox.service: Failed with result 'signal'.

And Dropbox is working fine. Why does systemd believe it is not? I think I found a clue:

Arch :: ~ » pkill dropbox                                                                                                                                                                                                                                                                                         
Arch :: ~ » dropbox
[1]    3647 killed     dropbox
Arch :: ~ »

After this sequence Dropbox is running fine. So, when you start Dropbox, it launches a main process, which searches for and launches the "real" dropbox process and then something kills the main process. The systemd unit is not build for this:

Arch :: ~ » cat /usr/lib/systemd/user/dropbox.service
[Unit]
Description=Dropbox

[Service]
Type=simple
ExecStart=/usr/bin/dropbox
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=on-failure

[Install]
WantedBy=default.target

I cannot really read these units, but it seems like it tries to keep /usr/bin/dropbox alive, which will not work out, since this process is designed to die shortly after being started.

So, my question here is: what would be a proper fix to the systemd unit?

Last edited by SmallAndSimple (2017-07-01 23:01:17)

Offline

#2 2017-06-30 09:32:08

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,424
Website

Re: [SOLVED] Dropbox (from AUR) and Systemd

Moving to AUR Issues...


Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2017-06-30 09:59:30

WorMzy
Forum Moderator
From: Scotland
Registered: 2010-06-16
Posts: 11,787
Website

Re: [SOLVED] Dropbox (from AUR) and Systemd

The behaviour you describe suggests the service file should be "forking" rather than simple.

man systemd.service wrote:
       Type=
           Configures the process start-up type for this service unit. One of
           simple, forking, oneshot, dbus, notify or idle.
[...]
           If set to forking, it is expected that the process configured with
           ExecStart= will call fork() as part of its start-up. The parent
           process is expected to exit when start-up is complete and all
           communication channels are set up. The child continues to run as
           the main daemon process. This is the behavior of traditional UNIX
           daemons. If this setting is used, it is recommended to also use the
           PIDFile= option, so that systemd can identify the main process of
           the daemon. systemd will proceed with starting follow-up units as
           soon as the parent process exits.
[...]

It seems that the service file provided by the dropbox package is not from upstream, so you will need to discuss this with the package maintainer.


Sakura:-
Mobo: MSI MAG X570S TORPEDO MAX // Processor: AMD Ryzen 9 5950X @4.9GHz // GFX: AMD Radeon RX 5700 XT // RAM: 32GB (4x 8GB) Corsair DDR4 (@ 3000MHz) // Storage: 1x 3TB HDD, 6x 1TB SSD, 2x 120GB SSD, 1x 275GB M2 SSD

Making lemonade from lemons since 2015.

Offline

#4 2017-06-30 10:12:42

SmallAndSimple
Member
Registered: 2015-11-25
Posts: 50

Re: [SOLVED] Dropbox (from AUR) and Systemd

I will discuss it with the maintainer, after I find a proper fix big_smile

So, your suggestion seems pretty good and does change things. Not fix them, though. I noticed that on successful run of Dropbox, the returncode was 137. I also noticed that restarting will not help me right now, so I changed the unit to:

[Unit]
Description=Dropbox

[Service]
Type=forking
ExecStart=/usr/bin/dropbox
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=no
SuccessExitStatus=137

[Install]
WantedBy=default.target

Which gives:

Arch :: ~ » pkill dropbox; systemctl --user daemon-reload;  systemctl --user start dropbox                                                        1 ↵
Job for dropbox.service failed because a fatal signal was delivered to the control process.
See "systemctl status dropbox.service" and "journalctl -xe" for details.

journalctl -xe:

jun 30 12:08:36 Arch systemd[871]: Starting Dropbox...
-- Subject: Unit UNIT has begun start-up
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit UNIT has begun starting up.
jun 30 12:08:38 Arch systemd[871]: dropbox.service: Control process exited, code=killed status=9
jun 30 12:08:38 Arch systemd[871]: Failed to start Dropbox.
-- Subject: Unit UNIT has failed
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
-- 
-- Unit UNIT has failed.
-- 
-- The result is failed.

So, the main process is killed by its child (I love this terminology, I am so close to google "kill childeren" again), which Systemd decides is not fun at all. man systemd.service is helping a lot, see if I get any further..

EUREKA!

[Unit]
Description=Dropbox

[Service]
Type=simple
ExecStart=/usr/bin/env "%h/.dropbox-dist/dropboxd"
ExecReload=/bin/kill -HUP $MAINPID
KillMode=process
Restart=no

[Install]
WantedBy=default.target

I dislike the /usr/bin/env part, but I cannot give %h to ExecStart directly:

jun 30 12:23:11 Arch systemd[871]: [/usr/lib/systemd/user/dropbox.service:6] Executable path is not absolute, ignoring: %h/.dropbox-dist/dropboxd
jun 30 12:23:11 Arch systemd[871]: dropbox.service: Service lacks both ExecStart= and ExecStop= setting. Refusing.

Final edit: the new patch fixed it all.

Last edited by SmallAndSimple (2017-07-01 23:01:01)

Offline

Board footer

Powered by FluxBB