| 1 | package systemd // import "gopkg.in/hlandau/svcutils.v1/systemd" |
| 2 | |
| 3 | import "os" |
| 4 | |
| 5 | // IsRunningSystemd checks whether the host was booted with systemd as its init |
| 6 | // system. This functions similar to systemd's `sd_booted(3)`: internally, it |
| 7 | // checks whether /run/systemd/system/ exists and is a directory. |
| 8 | // http://www.freedesktop.org/software/systemd/man/sd_booted.html |
| 9 | func IsRunning() bool { |
| 10 | fi, err := os.Lstat("/run/systemd/system") |
| 11 | if err != nil { |
| 12 | return false |
| 13 | } |
| 14 | return fi.IsDir() |
| 15 | } |
| 16 | |
| 17 | // Deprecated. Use IsRunning() instead. |
| 18 | func IsRunningSystemd() bool { |
| 19 | return IsRunning() |
| 20 | } |
| 21 | |
| 22 | // Technically this is 'is running under systemd with the notify service type'. |
| 23 | // The purpose of this is to allow a daemon to determine whether it should |
| 24 | // behave in a systemd-like way, though, so that's fine. |
| 25 | func IsRunningUnder() bool { |
| 26 | return IsRunning() && os.Getenv("NOTIFY_SOCKET") != "" |
| 27 | } |
| 28 | |
| 29 | // © 2015 CoreOS, Inc. Apache 2.0 License |