Timeline for How can I determine, within a shell script, whether it is being called by systemd or not?
Current License: CC BY-SA 4.0
6 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Feb 12, 2021 at 3:19 | vote | accept | Jeff Schaller♦ | ||
| Dec 7, 2020 at 16:31 | comment | added | Jeff Schaller♦ | @jpaugh yes; it's a simple workaround, which is nice in its simplicity, but also has a simple bypass, as I commented on ilkkachu's answer here. | |
| Dec 7, 2020 at 16:27 | comment | added | jpaugh | As suggested in Lucas' answer, it makes the most sense just to add an environment variable to the unit file, something like Environment=LAUNCHED_BY_SYSTEMD=1, since that's entirely in the OP's control, and not reliant on unrelated behaviors of systemd. | |
| Dec 5, 2020 at 7:23 | comment | added | iBug | Apparently this fails for user units (that resides in ~/.config/systemd/user). But yeah, most services are system services so this should cover most use cases. | |
| Dec 4, 2020 at 16:44 | history | edited | Kusalananda♦ | CC BY-SA 4.0 | Upcase PID, diagnostics to stderr. |
| Dec 4, 2020 at 13:37 | history | answered | Jeff Schaller♦ | CC BY-SA 4.0 |