How to create a service on OSMC

Hi,

I use OSMC also to manage my photo. I use flickrsmartsync

to keep a folder in sync with a folder with my Flickr account.

The only problem is that I want to manage it as a service that I can start/sto going on My OSMC->Services as I already do for Samba, TvHeadend, SSH and so on.
I searched several web pages but not sure exactly how to do that.

Basicall I run a command:
flickrsmartsync sync-path

and it keep that folder in sync. I want it to be launched at start up and I can stop/start going in My OSMC->Services or running the command: sudo service flickrsmartsync stop.

Can someone help me to do that?
Thanks

This article in Wiki, might be what you are looking for:

Doing it in the MyOSMC is abit over my head. Else just ssh into your device and run “sudo systemctl start or stop [yourservicename]”

In my minecraft-server post here on the forum you got a service that starts and stops a script, almost at the bottom of first post.

Thank you for the reply.
What I need is how to create the flickr.service file.
What I need to so at the startup is the following command:

flickrsmartsync --monitor --sync-path /media/KODI/FLICKRFS

this command as it is is synchronous and it syncs up the folder /media/KODI/FLICKRFS with my Flickr account. When the process finishes it monitor the folder so that if I copy or remove a file from that folder automatically the change is applied to the server.

As you can understand I need that the service fork the command so it can run in the background. How I have to define my flickr.service file.

I did this but not sure it is ok. I need to run the service as soon as the networking is up and running. Can you help me to understand how to write this file? Thanks.

[Unit]
Description=Flickr Synchronizer
After=network.target

[Service]
Type=fork
ExecStart=/usr/local/bin/flickrsmartsync --monitor --sync-path /media/KODI/FLICK

[Install]
WantedBy=multi-user.target
Alias=flickr.service

Looks good, the only thing i would do diffrent is create a small bash script to start the flicker service and call that from the service file. insted of haveing that long line with parameters. If there is a change of patch to sync you edit the bash-script insted of service file.

So you dont have to run daemon-reload, when/if ever you need to change path.

Forgot to mention, how to remove the service if I do not need it anymore?

sudo systemctl disable flickr

That should disable the the service to start from boot

sudo systemctl enable flickr

To enable it to start from boot again

sudo systemctl stop flickr

To stop it, but it will start next you boot up

sudo systemctl start flickr

To start it up again without rebooting

https://wiki.archlinux.org/index.php/Systemd

There is something I am missing. Here what I did. I created the file /home/osmc/flickr.sh with the following content:

#!/bin/bash
/usr/local/bin/flickrsmartsync --monitor --sync-path /media/KODI/FLICKRFS

Then:

sudo vi /etc/systemd/system/flickr.service

with the content above (I replaced the long line with shell script call).

Then I did:

sudo chmod 664 /etc/systemd/system/flickr.service
sudo systemctl daemon-reload
sudo systemctl enable flickr.service

but I got the error:

osmc@osmc:~$ sudo systemctl enable flickr.service
Failed to execute operation: Invalid argument

the script alone works fine. What I am missing?

Put and exit in the last line of your bash-script, and perhaps “User=osmc” before Execstart,

Try 755, the error message indicates permissions problem.

Doing

> ls -la /etc/systemd/system shows the default as 755.

1 Like

Changed the wiki to reflect 755, type error that slipped through

Hi Again,
I did everything suggested but without success. Here what I have:

  1. File /etc/systemd/system/flickr.service
    [Unit]
    Description=Flickr Synchronizer
    After=network.target
    [Service]
    User=osmc
    ExecStart=/home/osmc/flickr.sh
    [Install]
    WantedBy=multi-user.target
    Alias=flickr.service

  2. File /home/osmc/flickr.sh:
    #!/bin/bash
    /usr/local/bin/flickrsmartsync --monitor --sync-path /media/KODI/FLICKRFS
    exit 0

  3. Both files have 755.

  4. I did:
    sudo systemctl daemon-reload
    sudo systemctl enable flickr.service

but error is the same.
Any suggestion?

For me, I placed my service file in:
/lib/systemd/system/
instead of
/etc/systemd/system/

edited:
both directories do the same but
/etc/systemd/system/
overrides
/lib/systemd/system/

Found this while googleing:

You have an Alias with the same name as the unit. This caused the same issue for me while writing a service file. It is completely redundant, so just remove it.

Ok. This solved the issue. The start command:
sudo systemctl enable test.service

activated the flickrsmartsync process.
My goal here is when I come back from a vacation, travel or whatever even I can put my SD Card in SD Reader connected via USB to Raspberry, copy photo in my folder and it automatically synch up with Flickr. I can watch the photo on TV where the view is much better. Another alternative is to copy them on my PC when I want to edit them and later copy on Kodi to sync up. In general, watch Pictures on TV with family as Slideshow is very a beautiful experience but to be honest Kodi support for Images is not so advanced. In my opinion, have Slideshow without Music is a big limitation. Yes, I can start Music before launching Slideshow but it is not the same thing. Hope in future this limitation solved.

I talked too soon. I just noticed the Flickr service I have created does not appear in MyOSMC -> Service. In my original post I asked specifically for this and I thought the tutorial and link proposed solved this problem.
I am able to start stop service from shell command line, but I want to do this from KODI interface. The reason I need this is simple. I do not want have this daemon up and running always, because I do not have photo to upload every day. Once in a while, when I need it I can activate the service and do everything from KODI interface.

Is this possible?

Guys, here things are getting worse. I just find out that with KODI 17 I can only do Slideshow of my whole source (all my photo) and not a single folder like in KODI 16. Let me explain. I have a folder:

/media/KODI/FLICKRFS

where I have a folder for each event. In Kodi 16 I went in Pictures->FLICKRFS (where FLICKRFS was my source for the folder above) and I could see a folder for each event or vacation. I entered in a folder and clicked on Slideshow. Now this is not possible anymore. If I click in a folder the Slideshow menu disappear. I can only do presentation of the whole source.

If my understanding is correct I can put the whole Picture feature of Kodi in a trash. Sorry for saying this.

Address this with Kodi. OSMC has no bearing on such specific Kodi functions.

Ok, hope someone can answer other question above that I think it is 100% OSMC.

Ok, sorry. My fault. The option is now visible. You have to move focus on first image.

However, I hope someone can help on the other question I asked above:

Sorry, for all these posts. Next time I will spend more time to understand the new interface before post questions :slight_smile: