CommandLine: add option --systemd
This way, MPD can reliably detect whether it was started as systemd service, which is better than checking sd_booted(), which only checks whether systemd manages all services, but still MPD could be started manually.
This commit is contained in:
parent
be3eca39e8
commit
ce77b148d9
|
@ -86,6 +86,9 @@ enum Option {
|
|||
OPTION_KILL,
|
||||
OPTION_NO_CONFIG,
|
||||
OPTION_NO_DAEMON,
|
||||
#ifdef __linux__
|
||||
OPTION_SYSTEMD,
|
||||
#endif
|
||||
OPTION_STDOUT,
|
||||
OPTION_STDERR,
|
||||
OPTION_VERBOSE,
|
||||
|
@ -98,6 +101,9 @@ static constexpr OptionDef option_defs[] = {
|
|||
{"kill", "kill the currently running mpd session"},
|
||||
{"no-config", "don't read from config"},
|
||||
{"no-daemon", "don't detach from console"},
|
||||
#ifdef __linux__
|
||||
{"systemd", "systemd service mode"},
|
||||
#endif
|
||||
{"stdout", nullptr}, // hidden, compatibility with old versions
|
||||
{"stderr", "print messages to stderr"},
|
||||
{"verbose", 'v', "verbose logging"},
|
||||
|
@ -349,6 +355,13 @@ ParseCommandLine(int argc, char **argv, struct options &options,
|
|||
options.daemon = false;
|
||||
break;
|
||||
|
||||
#ifdef __linux__
|
||||
case OPTION_SYSTEMD:
|
||||
options.daemon = false;
|
||||
options.systemd = true;
|
||||
break;
|
||||
#endif
|
||||
|
||||
case OPTION_STDOUT:
|
||||
case OPTION_STDERR:
|
||||
options.log_stderr = true;
|
||||
|
|
|
@ -25,6 +25,11 @@ struct ConfigData;
|
|||
struct options {
|
||||
bool kill = false;
|
||||
bool daemon = true;
|
||||
|
||||
#ifdef __linux__
|
||||
bool systemd = false;
|
||||
#endif
|
||||
|
||||
bool log_stderr = false;
|
||||
bool verbose = false;
|
||||
};
|
||||
|
|
|
@ -5,7 +5,7 @@ After=network.target sound.target
|
|||
|
||||
[Service]
|
||||
Type=notify
|
||||
ExecStart=@prefix@/bin/mpd --no-daemon
|
||||
ExecStart=@prefix@/bin/mpd --systemd
|
||||
|
||||
# Create /run/mpd (if MPD is launched without the socket unit and is
|
||||
# configured to bind listener sockets there).
|
||||
|
|
|
@ -5,7 +5,7 @@ After=network.target sound.target
|
|||
|
||||
[Service]
|
||||
Type=notify
|
||||
ExecStart=@prefix@/bin/mpd --no-daemon
|
||||
ExecStart=@prefix@/bin/mpd --systemd
|
||||
|
||||
# Create /run/user/$UID/mpd (if MPD is launched without the socket
|
||||
# unit and is configured to bind listener sockets there).
|
||||
|
|
Loading…
Reference in New Issue