You are not logged in.

#1 2013-04-27 15:03:43

silentsnake
Member
Registered: 2012-02-23
Posts: 57

[solved] systemd: Start process as specific user

Hi,

I plan to use bittorrent-sync, and want to run it for each user separately. So I would like to modify the service to run the process as the user instead of root. Like bittorrent-sync@user1… and so on.

Is this possible?

Thanks

Last edited by silentsnake (2013-04-27 15:13:25)

Offline

#2 2013-04-27 15:10:15

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 30,234
Website

Re: [solved] systemd: Start process as specific user

Two ways:

One, under [Service] include a line "User=<username to run as>".

Two, use a systemd --user session.


"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman

Offline

#3 2013-04-27 15:13:09

silentsnake
Member
Registered: 2012-02-23
Posts: 57

Re: [solved] systemd: Start process as specific user

Thanks smile

Offline

#4 2013-04-27 15:20:21

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: [solved] systemd: Start process as specific user

If you want to take the time to set it up, systemd --user is pretty awesome.  I use it to handle just about everything for my user, including X and the i3wm.  I don't use a DM, so it just takes me straight to the GUI.

To add to what Trilby is telling you above.  To make per user system services, instead of simply adding a User=silentsnake, you could instead use "User=%I" and then rename the service as bt-sync@.service.  That way you can enable bt-sync@silentsnake.service as well as bt-sync@wonderwoofy.service and bt-sync@Trilby.service.

Offline

#5 2013-04-27 15:59:10

silentsnake
Member
Registered: 2012-02-23
Posts: 57

Re: [solved] systemd: Start process as specific user

Thanks to you too, WonderWoofy. smile

[Unit]
Description=BitTorrent Sync service
After=network.target

[Service]
ExecStart=/usr/bin/btsync --nodaemon --config /home/%i/.sync/btsync.conf
Restart=on-abort
User=%i
Group=users

[Install]
WantedBy=multi-user.target

This allows me to run one instance per user with its own configuration. Since it's a server with no users actively working on, I think this is the way to go. But will investigate the systemd user session for my desktop clients. smile

Offline

#6 2013-04-27 16:14:21

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: [solved] systemd: Start process as specific user

See, the only problem with the bt-sync@.service (system service) is that only root is able to start/stop/enable/etc. these services.  By setting up systemd user services, you can mae it so that each user has the ability to turn this syncing on or off as desired.

Offline

#7 2013-04-27 16:39:21

silentsnake
Member
Registered: 2012-02-23
Posts: 57

Re: [solved] systemd: Start process as specific user

Thats a good point indeed. smile

Offline

#8 2013-04-27 19:35:40

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,414

Re: [solved] systemd: Start process as specific user

You also don't have to use systemd --user for all your stuffs like I do.  You can choose to use it for as much or as little as you would like.  There is a wiki page covering what you need to do to get this working.  Also gtmanfred has a great blog post (I think it is the only post on his blog actually) from which that wiki page is referenced.  Reading through it will give you an idea of what you need to set up to get it going.  Though you do not have to include the stuff about getting your window manager running though it.

Offline

Board footer

Powered by FluxBB