Question: systemd: Coordinating root and user jobs
I have a setup where I use "nginx" webserver to front-end a "Calibre" ebook server. I use nginx to support SSL, and also to require client certs to access Calibre.
I have a primary Calibre instance on one computer that nobody gets to access except me. I have a nightly job that rsyncs my primary Calibre data over to a secondary Calibre instance (this runs on a different computer). It is this second instance that users can access, provided I have given them an appropriate client cert to use for authentication through the nginx front-end. The daily rsync follows up with a restart of the secondary Calibre instance. This is required to re-index any new data that may have come across. I have found that restarting the secondary Calibre instance breaks the nginx front-end access to it. The fix is simple - restart nginx. And then everything works fine again. My issue is that the rsync and Calibre restart systemd stuff runs as userid "calibre". However, the nginx systemd stuff runs as "root". What I would like to do, if possible in systemd, is have a root job that restarts nginx trigger off of the completion of the user job that does the rsync/Calibre_restart. Is this possible? How? An alternate, of course, is to run all jobs - the rsync, the Calibre restart, and the nginx restart as root. I can do that. But I would like to know if it is even possible to do this the way I describe above, as a root systemd job that triggers off of a user systemd job. Thanks! ================================================== As userid "calibre" (e.g., "systemctl --user ..."): Code:
[calibre@rpi3b user]$ cat rsync_calibre.timer Code:
[calibre@rpi3b user]$ cat rsync_calibre.service Code:
[calibre@rpi3b bin]$ cat rsync_calibre_books.sh Code:
[calibre@rpi3b user]$ cat calibre-server.service Code:
[calibre@rpi3b bin]$ cat start_calibre.sh As userid "root": Code:
[root@rpi3b]# cat nginx.service |
Is your "nightly job" in cron? If so is it in the crontab for the calibre user?
Have you thought of moving it from the calbre user's crontab to instead be in the root user's crontab and modify the job so it runs the resync as calibre (su - calibre -C <commands>) then do the restart of nginx without the su? |
Quote:
I'm actually using "systemd timers" instead of cron. But I could do the same thing as you suggest (functionally) in systemd. Run everything as "root" with selective su's to "calibre". Since I am less knowledgeable in systemd than I am in cron, that's why I decided to use systemd. To practice and learn more about it. A good brain exercise. cron is definitely simpler, systemd is more flexible/configurable. All that code I posted above, in my initial post, is systemd configuration. You can see it's nowhere near as simple as cron! That's why I was asking about how to do this job coordination using systemd. So I could increase my knowledge (decrease my ignorance!) My question was not really "I don't know any way to accomplish this task by any means". I do. My question was more like "I want to learn how to accomplish this task in a new way (using systemd). Can anyone give me any pointers?" ( I view systemd vs. cron similarly to how I view legacy grub vs. grub2. I can do everything I need in legacy grub (cron), but I learned grub2 (systemd) so I wouldn't fall too far behind on the technology curve. systemd is a lot more than just a cron replacement. It's an init replacement, and all kinds of other stuff too. ) |
fwiw, archwiki has been very helpful in systemd matters:
https://wiki.archlinux.org/index.php/Systemd/User hope it helps. |
So I hadn't been aware of systemd timers as an alternative to cron. On our systemd based servers we've continued to use cron.
I just asked a co-worker about this and he said he'd played with timers but didn't like them. Of course that's an opinion and I found others on the internet. Also I found mention of the need to specify user with in the unit file but see you using "systemctl --user". On my RHEL7 system I found that "--user" flag doesn't work at all which led to this from RedHat saying they didn't implement it on RHEL7 because it was listed as not stable and they weren't sure it wouldn't be removed later: https://bugzilla.redhat.com/show_bug.cgi?id=1198655 All that leads to the question: Which distro and version of Linux are you using? |
I am running this on an Arch ARM installation (Raspberry Pi3 hardware).
The command that reportedly does not work correctly in the RedHat bug report you mentioned, works just fine under Arch. See below. Note that you have to manually enable the systemd stuff to run in the user environment ... it is not enabled by default. It is only enabled by default in the root environment. Code:
[calibre@rpi3b ~]$ uname -a Code:
[calibre@rpi3b ~]$ systemctl --user status Code:
[calibre@rpi3b ~]$ systemctl --user |
Quote:
Some old sayings hold very true: If you want highly technical/competent help with Linux, any Linux distro, ask a Slackware guru. If you want good documentation, look to the Arch stuff. If you want highly active forums with lots of places to find answers to simple and/or beginner questions, go with Ubuntu (or something built on top of Ubuntu, like LinuxMint). |
Quote:
I wasn't suggesting Arch didn't support it. I was just asking which distro/version you were using which I now know is Arch so the Arch Wiki is going to be more helpful than I am. |
All times are GMT -5. The time now is 05:26 PM. |