User avatar
Skraaj
Posts: 29
Joined: Wed Nov 20, 2019 11:35 pm
Contact: Website

Creating systemd service files - documentation

Sat Jul 18, 2020 3:56 pm

Hi folks, any chance someone could point me to proper documentation of how to set up services? I'd prefer something noob-friendly, but I'm open to everything :) I'd love to explore all options and find out what else can I do in sections like eg [Unit]. I know it's sort of a question that usually gets a LMGTFY reply, but I can't find anything substantial except for tutorials without clear explanation of what does what, only examples with "do this and that".

Basically I had a problem with umask when service was saving files with 755 permissions and I needed 777 so I just added UMask=0777 to [Service] section of /etc/systemd/system/$service.service, but I feel like I should explore that a bit more instead of just winging it.
codedoneright.eu – newbie friendly raspberry tutorials

User avatar
RamaSpaceShip
Posts: 70
Joined: Sun Apr 26, 2020 12:19 pm

Re: Creating systemd service files - documentation

Sat Jul 18, 2020 4:14 pm

I don't know any systemd service tutorial, so I won't help you on this aspect.

For your other question, as your service was saving files with 755, umask won't help you as it only restricts permissions. It does not set them.
You must also change your service to set 777 permissions on created files.

By the way, I am just curious, why do you need 777?
It's a bit strange and violates basic security policies.
Does your service run as root?
Does your service produce executable files?

User avatar
Skraaj
Posts: 29
Joined: Wed Nov 20, 2019 11:35 pm
Contact: Website

Re: Creating systemd service files - documentation

Sat Jul 18, 2020 4:43 pm

Local service that writes to my NAS available only on LAN, runs as a sudo user, not root. I want all devices to be able to read / write files saved by that service.

What I did:

Code: Select all

sudo nano /etc/systemd/system/$service.service
Inside placed

Code: Select all

[Unit]
Description=$service
Wants=network-online.target
After=network-online.target nss-lookup.target

[Service]
Type=exec
Restart=always
RestartSec=1
User=$user
UMask=0000
ExecStart=/usr/bin/$service

[Install]
WantedBy=multi-user.target

Code: Select all

sudo systemctl daemon-reload
sudo systemctl start $service
sudo systemctl enable $service
Without "UMask=0000" it saved files with 744 permissions so I had to use sudo or SSH to my Pi to modify files, strangely enough now it saves with 666 despite 0000 mask.

Just want to explore the service setup process a bit more and I don't know where to start, Debian wiki is not that helpful... I found some descriptions of lies used in the service file, but I cant find documentation of how the file should be structured and all options, like eg. if the order makes any difference etc.
codedoneright.eu – newbie friendly raspberry tutorials

User avatar
B.Goode
Posts: 10399
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: Creating systemd service files - documentation

Sat Jul 18, 2020 5:08 pm

Skraaj wrote:
Sat Jul 18, 2020 3:56 pm
Hi folks, any chance someone could point me to proper documentation of how to set up services? I'd prefer something noob-friendly, but I'm open to everything :) I'd love to explore all options and find out what else can I do in sections like eg [Unit]. I know it's sort of a question that usually gets a LMGTFY reply, but I can't find anything substantial except for tutorials without clear explanation of what does what, only examples with "do this and that".

Basically I had a problem with umask when service was saving files with 755 permissions and I needed 777 so I just added UMask=0777 to [Service] section of /etc/systemd/system/$service.service, but I feel like I should explore that a bit more instead of just winging it.


On this very website, published by Raspberry Pi themselves, there is https://www.raspberrypi.org/documentati ... systemd.md

A short tutorial referring to that page: https://blog.usedbytes.com/2019/11/run- ... -rc.local/


For anything more detailed, I think you are into RTFM territory...

andrum99
Posts: 1247
Joined: Fri Jul 20, 2012 2:41 pm

Re: Creating systemd service files - documentation

Tue Jul 21, 2020 6:56 pm

Have a look at https://github.com/raspberrypi/document ... systemd.md - it's currently undergoing review for integration into the documentation (at raspberrypi.org/documentation).

Return to “Raspberry Pi OS”