1

I have written a program which works fine, but when I run it as service it cannot create or write files and folders.

My program creates folder in my home directory and in that folder creates file for storing information incoming via TCP socket.

I do use User & Group in my .service but its only creating the folder without any permissions and fails to create a file.

Your help will be appreciated.

Greg
  • 189
  • 1
  • 1
  • 12
  • 3
    Possible duplicate of [How do I make my systemd service run via specific user and start on boot?](https://askubuntu.com/questions/676007/how-do-i-make-my-systemd-service-run-via-specific-user-and-start-on-boot) – Jos Apr 29 '19 at 15:34
  • @Jos This is answer for a different question – Greg Apr 29 '19 at 16:30
  • Systemd normally runs as root. If you are populating to /home/username then you want to run the service under username. – WinEunuuchs2Unix Apr 29 '19 at 17:13
  • @WinEunuuchs2Unix Ok, I understand - but how to do it ? – Greg Apr 29 '19 at 18:33

1 Answers1

0

I fixed the problem by correct umask setting in my code.

Clarification: I had a problem creating files or folders and I assumed that the problem originates from the fact that my server program is systemd service but later I found out that I used umask erroneously:

umask(0755); <- bad

umask(0022); <- solved my problem
Greg
  • 189
  • 1
  • 1
  • 12