There's an init.d file for Dropbox for non-GUI servers. I'd like to use drobpox as a way to understand systemd a little better.
In the init.d file, it pulls in a list of users from /etc/sysconfig. I'm trying to figure out how to do something like that with a service file.
My dropbox.service file is:
cat /etc/systemd/system/dropbox.service
---------------------------------------
[Unit] Description=Dropbox as a system service
[Service] ExecStart=/home/sdstern/.dropbox-dist/dropboxd User=sdstern # 'LANG' might be unnecessary, since systemd already sets the # locale for all services according to "/etc/locale.conf". # Run `systemctl show-environment` to make sure. Environment=LANG=en_US.utf-8
[Install] WantedBy=multi-user.target
---------------------------------------
Ideally, I'd look at a list of users entered in a file in /etc/sysconfig and loop through ExecStart and User for each user, substituting the user name for "sdstern" on each.
So, pointers on how to do things like this in a .service file?
On Sun, Aug 24, 2014 at 10:38 AM, Steven Stern < subscribed-lists@sterndata.com> wrote:
Ideally, I'd look at a list of users entered in a file in /etc/sysconfig and loop through ExecStart and User for each user, substituting the user name for "sdstern" on each.
So, pointers on how to do things like this in a .service file?
I don't think a dropbox like service really lends itself to system-wide
startup. What if one of your users isn't signed up, or doesn't want to be?
Richard
On 08/24/2014 08:52 PM, Richard Shaw wrote:
On Sun, Aug 24, 2014 at 10:38 AM, Steven Stern <subscribed-lists@sterndata.com mailto:subscribed-lists@sterndata.com> wrote:
Ideally, I'd look at a list of users entered in a file in /etc/sysconfig and loop through ExecStart and User for each user, substituting the user name for "sdstern" on each. So, pointers on how to do things like this in a .service file?
I don't think a dropbox like service really lends itself to system-wide startup. What if one of your users isn't signed up, or doesn't want to be?
That's the function of the file in /etc/sysconfig. It lists the users who are. Actually, this is just my system but I run a couple of dropbox user accounts on it -- one as my main one and one to backup client websites.
On 08/24/2014 08:52 PM, Richard Shaw wrote:
On Sun, Aug 24, 2014 at 10:38 AM, Steven Stern <subscribed-lists@sterndata.com mailto:subscribed-lists@sterndata.com> wrote:
Ideally, I'd look at a list of users entered in a file in /etc/sysconfig and loop through ExecStart and User for each user, substituting the user name for "sdstern" on each. So, pointers on how to do things like this in a .service file?
I don't think a dropbox like service really lends itself to system-wide startup. What if one of your users isn't signed up, or doesn't want to be?
Richard
Then the service file simply runs an if/then loop, only initiating for users that have ~/.dropbox-dist/ directory.
On 09/22/2014 09:18 AM, Dan Mossor wrote:
On 08/24/2014 08:52 PM, Richard Shaw wrote:
On Sun, Aug 24, 2014 at 10:38 AM, Steven Stern <subscribed-lists@sterndata.com mailto:subscribed-lists@sterndata.com> wrote:
Ideally, I'd look at a list of users entered in a file in
/etc/sysconfig and loop through ExecStart and User for each user, substituting the user name for "sdstern" on each.
So, pointers on how to do things like this in a .service file?
I don't think a dropbox like service really lends itself to system-wide startup. What if one of your users isn't signed up, or doesn't want to be?
Richard
Then the service file simply runs an if/then loop, only initiating for users that have ~/.dropbox-dist/ directory.
Can I treat a .service file like a bash script and do all those "loop" sorts of things?
On Mon, Sep 22, 2014 at 12:40 PM, Steven Stern subscribed-lists@sterndata.com wrote:
Can I treat a .service file like a bash script and do all those "loop" sorts of things?
No, but you can invoke a bash script from a service file that does things in a loop. But that doesn't buy you much^D anything really over the initial initscript. ;-)
A proper systemdish way to accomplish this would be to use an instance service for dropbox and use the standard systemd tools to enable/disable it for particular users instead of keeping the list in an /etc/sysconfig file.
First, I'd suggest reading this nice introduction to instance services; it's not very long and afterward you'll have a full understanding of what's going on with my example below: http://0pointer.de/blog/projects/instances.html
To create an instance service for dropbox, instead of using "dropbox.service", create a "dropbox@.service" file (the @ is very important), with the following contents: -- [Unit] Description=Dropbox service for user %I
[Service] ExecStart=/home/%i/.dropbox-dist/dropboxd User=%i
[Install] WantedBy=multi-user.target
--
Once you have that, instead of managing the users it is started for with a file in /etc/sysconfig, just use systemctl to enable/disable it for users as appropriate.
To enable the dropbox service for the "sdstern" user: # systemctl enable dropbox@sdstern.service
To disable the dropbox service for the "sdstern" user later on: # systemctl disable dropbox@sdstern.service
And, to see all the users dropbox is enabled for: % ls /etc/systemd/system/multi-user.target.wants/dropbox@*
-T.C.