mirror of
https://github.com/badaix/snapcast.git
synced 2025-05-30 09:26:15 +02:00
configurable user and group
This commit is contained in:
parent
f103788398
commit
ed1c5d6606
4 changed files with 21 additions and 4 deletions
|
@ -88,6 +88,7 @@ int main (int argc, char **argv)
|
|||
Implicit<int> daemonOption("d", "daemon", "daemonize, optional process priority [-20..19]", -3, &processPriority);
|
||||
Value<int> latencyValue("", "latency", "latency of the soundcard", 0, &latency);
|
||||
Value<size_t> instanceValue("i", "instance", "instance id", 1, &instance);
|
||||
Value<string> userValue("", "user", "the user[:group] to run snapclient as when daemonized", "snapclient:audio");
|
||||
|
||||
OptionParser op("Allowed options");
|
||||
op.add(helpSwitch)
|
||||
|
@ -100,6 +101,7 @@ int main (int argc, char **argv)
|
|||
#endif
|
||||
#ifdef HAS_DAEMON
|
||||
.add(daemonOption)
|
||||
.add(userValue)
|
||||
#endif
|
||||
.add(latencyValue)
|
||||
.add(instanceValue);
|
||||
|
@ -163,7 +165,14 @@ int main (int argc, char **argv)
|
|||
string pidFile = "/var/run/snapclient/pid";
|
||||
if (instance != 1)
|
||||
pidFile += "." + cpt::to_string(instance);
|
||||
daemonize("snapclient", "audio", pidFile);
|
||||
|
||||
if (userValue.getValue().empty())
|
||||
std::invalid_argument("user must not be empty");
|
||||
|
||||
vector<string> user_group = split(userValue.getValue(), ':');
|
||||
string user = user_group[0];
|
||||
string group = (user_group.size() == 1)?user_group[0]:user_group[1];
|
||||
daemonize(user, group, pidFile);
|
||||
if (processPriority < -20)
|
||||
processPriority = -20;
|
||||
else if (processPriority > 19)
|
||||
|
|
|
@ -9,7 +9,7 @@ SERVICE_PID_FILE=/var/run/$SERVICE_NAME/pid
|
|||
|
||||
DESC="Snapcast client"
|
||||
DAEMON=/usr/bin/$SERVICE_NAME
|
||||
SNAPCLIENT_OPTS="-d"
|
||||
SNAPCLIENT_OPTS="-d --user root"
|
||||
|
||||
|
||||
# Exit if the package is not installed
|
||||
|
|
|
@ -9,7 +9,7 @@ SERVICE_PID_FILE=/var/run/$SERVICE_NAME/pid
|
|||
|
||||
DESC="Snapcast server"
|
||||
DAEMON=/usr/bin/$SERVICE_NAME
|
||||
SNAPSERVER_OPTS="-d"
|
||||
SNAPSERVER_OPTS="-d --user root"
|
||||
|
||||
|
||||
# Exit if the package is not installed
|
||||
|
|
|
@ -68,6 +68,7 @@ int main(int argc, char* argv[])
|
|||
|
||||
Value<int> bufferValue("b", "buffer", "Buffer [ms]", settings.bufferMs, &settings.bufferMs);
|
||||
Implicit<int> daemonOption("d", "daemon", "Daemonize\noptional process priority [-20..19]", 0, &processPriority);
|
||||
Value<string> userValue("", "user", "the user[:group] to run snapserver as when daemonized", "snapserver:snapserver");
|
||||
|
||||
OptionParser op("Allowed options");
|
||||
op.add(helpSwitch)
|
||||
|
@ -81,6 +82,7 @@ int main(int argc, char* argv[])
|
|||
.add(bufferValue)
|
||||
#ifdef HAS_DAEMON
|
||||
.add(daemonOption)
|
||||
.add(userValue)
|
||||
#endif
|
||||
;
|
||||
|
||||
|
@ -144,7 +146,13 @@ int main(int argc, char* argv[])
|
|||
if (daemonOption.isSet())
|
||||
{
|
||||
#ifdef HAS_DAEMON
|
||||
daemonize("snapserver", "snapserver", "/var/run/snapserver/pid");
|
||||
if (userValue.getValue().empty())
|
||||
std::invalid_argument("user must not be empty");
|
||||
|
||||
vector<string> user_group = split(userValue.getValue(), ':');
|
||||
string user = user_group[0];
|
||||
string group = (user_group.size() == 1)?user_group[0]:user_group[1];
|
||||
daemonize(user, group, "/var/run/snapserver/pid");
|
||||
if (processPriority < -20)
|
||||
processPriority = -20;
|
||||
else if (processPriority > 19)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue