Starting insync-headless with systemd (or a fix for the autostart method)

I have a Debian 9 stretch install which I am setting up to use as a music server but also as a backup machine for my dropbox and goodgle drive accounts. I have managed to install dropbox and get it started using systemd as a background process on boot up.

I have installed insync without a problem and sync’d to my google drive. I used the autostart command which comes with insync headless which works well BUT when this is enabled, it interferes with unmounting my /home partition and unmounting fails at shutdown. I have localised it to the insync-headless service as when I quit this prior to shutting down there is no unmounting error.

Needless to say I don’t want my /home partition to become corrupted over time with unmounting being an issue.

My thought was to use systemd to start/stop the insync-headless service so it was definitely stopped prior to unmounting at shutdown. I have tried to setup a systemd .service file in /etc/systemd/system/ with various files posted around the internet and enable with systemctl but I keep getting an invalid argument error.

I don’t have enough experience with systemd at present to know how to sort this out, or why insync-headless won’t let me unmount my /home partition. I will keep reading about systemd service files but any help would be greatly appreciated.

Cheers,

Ollie

Tagging our engineer @jimperio and he will get back to you.

Other community members want to hear solution too, please post it here.

2 Likes

Hey @Murz,

Thanks for the input! Tagging our engineer @Kurt_Ko.

1 Like

as i had the same idea as ollie i found this thread but unfortunately dead end after passing the inquiry to the engineer :slight_smile: so i started googleing and reading around and created myself something working for me. it is not tested until the very end in order to ensure functionality in all use cases but if you like to give it a try or even improve my solution, please feel free to do so.

i am not responsible if you loose your valuable data (i.e. cat pictures or videos, etc) nor if this planet gets destroyed unexptedly :slight_smile:

my task was to automate the start and stop of insync-headless on my openmediavault based nas (debian 9) so insync-headless is getting started at boot time after network is up and getting stopped when the machine gets rebooted or powered off.

the command insync-headless set_autostart yes does not work as it requires a login with running xsession and usually my machine starts up and nobody logs in but for maintenance reason.

all actions taken require root privileges:

1. create a file /etc/systemd/system/insync-headless.service and fill it with this content:

[Unit]
Description=Insync Headless
After=network.target
After=systemd-user-sessions.service
After=network-online.target

[Service]
User=root
Type=forking
ExecStart=/usr/lib/insync/insync-headless-start.sh
ExecStop=/usr/lib/insync/insync-headless-stop.sh
TimeoutSec=30
TimeoutStopSec=30
Restart=on-failure
RestartSec=30
StartLimitInterval=350
StartLimitBurst=10

[Install]
WantedBy=multi-user.target

2. create another file /usr/lib/insync/insync-headless-start.sh and fill it with this content:
#!/bin/bash
/usr/bin/insync-headless start

3. create another file /usr/lib/insync/insync-headless-stop.sh and fill it with this content:
#!/bin/bash
/usr/bin/insync-headless quit

4. make both files from step 2 and 3 executable:
chmod u+x /path/to/spark/sbin/insync-headless-start.sh
chmod u+x /path/to/spark/sbin/insync-headless-stop.sh

5. test the start and stop script (allow some 20-30 seconds between start and stop script command as insync requires this time to come up and run):
systemctl start insync-headless

check if insync is running:
pgrep -l insync

should give you something like the next line (process number is most likely a different one):
2259 insync

now (after waiting some seconds) test the stop command:
systemctl stop insync-headless

check if insync is still running:
pgrep -l insync

should give you no result at this time.

6. finally enable autostart:
systemctl enable insync-headless

you are done.

any suggestions, improvement or other type of feedback is welcome.

best regards
peter

I am looking for a solution as well. Please provide fix. @Peter_Altherr I can not get your solution to work.

1 Like

hi j_dalton_humpf,

the only problem i have is the autostart is not 100% reliable. in 9 out of 10 reboots it works as expected but sometimes it fails and i have to start insync-headless manually.

what operating system are you using where you try to get it working?

best regards
peter

This is pretty old and I don’t know if there’s a newer systemd configuration for insync-headless, but I wanted to report that this config doesn’t work. I get an error from insync-headless asking me to run add_account first. I don’t think that’s right because if I run insync-headless start manually, it works fine.

1 Like

did you add the account to insync as root or with a different account? this must be done as root.