New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add systemd unit file #1716
Add systemd unit file #1716
Conversation
# -2 ensures Octoprint has a slight priority over user processes. | ||
Nice=-2 | ||
|
||
ExecStart=/home/pi/OctoPrint/venv/bin/octoprint serve --basedir ${BASEDIR} --config ${CONFIGFILE} --port ${PORT} --foobar $DAEMON_ARGS" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--foobar
? O_o
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another thing here - I guess it's not possible to leave --config
, --basedir
and --port
out unless the corresponding environment variables are set? The defaults in octoprint.defaults
are what OctoPrint would automatically use unless overridden via command line.
Thanks! Just did a quick review and added two comments, could you take a look at those? Cheers! |
O_o indeed. Regarding the always present If you would be willing to ignore the current
Googling systemd variable expansion suggests it might be possible to do fancy variable expansion by involving one or more instances of bash. But by now you'd be roaming into ridiculous territory.. |
8387186
to
7589115
Compare
I just realized I hadn't gotten back to you here, sorry for that. I was out sick the last two weeks and am still playing catch up with everything that accumulated during that time. I agree, we don't want to overengineer this... If I understand the general approach to customizing systemd service files correctly, you usually don't really use the So in that case I'd say having it instead be |
@noahwilliamsson still waiting for an answer here :) |
I think this would be way better with optional systemd socket activation (optional because it would break plugins like OctoPrint-Telegram).
I also don't like the fact that paths are hardcoded to |
I think this should be a user-service file rather than tied to pi user. Benefits
https://gist.github.com/Lewiscowles1986/5ecfc1f4125a7e6a39006cbb7d69229a Linked a Gist (just published) from the build I made for my BiL last week using user. It's much more basic, but essentially runs octoprint. instead of
|
@Lewiscowles1986 I'm afraid user services only starts once the user logs in, and are killed when the user logs out. So it would only work if you've configured your Raspberry Pi installation to automatically login during boot. |
I was going to work on this and other issues but I'm currently veeery busy.
I believe 8p should run as it's own non-system user, but not as a user
unit, for the reasons noahwilliamsson pointed out. Other means of privilege
escalation can be set up to allow easier administration (e.g visudo, some
dbus/policykit policy, etc)
…On Mon, Sep 18, 2017, 11:12 AM noahwilliamsson ***@***.***> wrote:
@Lewiscowles1986 <https://github.com/lewiscowles1986> I'm afraid user
services only starts once the user logs in, and are killed when the user
logs out. So it would only work if you've configured your Raspberry Pi
installation to automatically login during boot.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#1716 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABGRWUeDVjBiyXyKd-ew5B0_ZOU6-zjeks5sjjPXgaJpZM4LkDBK>
.
|
@noahwilliamsson well if a user is not logged in (btw default for jessie and stretch gui is to have user |
What? I never log in to the GUI on my OctoPrint installations. OctoPi
doesn't even have a GUI.
…On 18 September 2017 at 11:41, Lewis Cowles ***@***.***> wrote:
@noahwilliamsson <https://github.com/noahwilliamsson> well if a user is
not logged in (btw default for jessie and stretch gui is to have user
logged in automatically) you wouldn't want them running octoprint, that's
kinda the point, to isolate it to run under one user, only when they are
using GUI.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#1716 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAijhWMnKnsSHiXMluOWUg_p3qKoPoqwks5sjki8gaJpZM4LkDBK>
.
|
I built octoprint from repo and install only. Probably why there is a difference.
Each to their own I suppose. I'd still say the single user makes more sense, but regardless networking.target would be sensible if you're running headless |
@Lewiscowles1986 While it might be the case that automatic login is turned on by default on Raspbian Stretch with Desktop it most certainly isn't on most Linux distributions, including Raspbian Jessie Lite. I understand that for your particular use case, it is sufficient if OctoPrint is running only when the user is logged in with a desktop session on the Raspberry Pi. However, some people might have a different setup with a headless computer (e.g., a Raspberry Pi running Raspbian Stretch Lite) permanently connected to their printer in order to provide remote access to the printer via OctoPrint's API or web GUI. I do like the fact that non-privileged users can manage their own services with systemd but in this case I don't think it's a good fit. Sorry. |
okay, but that aside the Btw I have no dog in this, I'm totally borrowing parts of your systemD file to enhance my rather rushed and cobbled together attempt. At the same time, I'd like to understand what the sane defaults are and why they are 👍 |
@noahwilliamsson @Lewiscowles1986 It is possible to configure systemd to allow user daemons to be started and stopped as all other units handled by systemd. But thats much more complicated to configure than to install the service as root. But at the end its the same file, so if a user knows how to setup systemd linger for users, he will know how to install the service, too. (And especially on Jessie configuring that is an extra pain as there are some files missing and dbus needs to be configured, too) |
@bzed it's not about what the user knows, it's about access. The entire program should be able to run after install for any user that belongs to the right groups, regardless of root access IMO. As I'm not largely involved I don't really expect my opinion to count for alot, but just saying "users must know how to manage systemd" misses the point. |
It's a server program, I think assuming a system wide install under its own user as the default scenario is fair game (and also in line with the SysV initscript this service file is supposed to replace. |
FWIW, this is the unit file I use:
|
Sadly never got an answer to the open question and still lack the experience with systemd to answer it myself. Closing 😕 |
@foosel I missed that question, but... Using /etc/default is like using a paper phone book with your android mobile phone. Systemd has various ways to extend and override a given service, there is no need to stay with old init.d stuff (which is supported for compatibility reasons...). |
As discussed in OctoPrint#1716
What does this PR do and why is it necessary?
This PR adds a systemd unit file to allow OctoPrint to be started at boot time in a modern Linux distribution that runs the systemd init system. The unit file's defaults are suitable for the instructions provided in Setup on a Raspberry Pi running Raspbian
It tries to be backwards compatible with the existing init script with respect to envs defined in
/etc/default/octoprint
, although a few of them (OCTOPRINT_USER
,DAEMON
,NICE
andUMASK
) were not possible to support in the unit file. See the unit file for instructions on howto override these.OctoPrint already comes with a SysV and Debian-style init script and configuration template. These work fine, even in a systemd world. But since most modern Linux distributions have moved over to systemd, I figured a systemd unit file would be a more proper way of doing things moving forward.
That way new OctoPrint users, some of who perhaps come in contact with Linux for the first time, don't unnecessarily get "exposed" to the old (and in the future, perhaps deprecated) way of adding boot services, but instead get to learn the modern way with
systemctl
(andjournalctl
for debugging) right from the start.How was it tested? How can it be tested by the reviewer?
Any background context you want to provide?
What are the relevant tickets if any?
Screenshots (if appropriate)
Further notes
Like the author of the current init script, some helpful instructions are provided at the top of the file. They may serve as a starting point if the instructions in the wiki should be updated aswell.