Change Shutdown service name to PiPedalSupervisor

Fixes #17
This commit is contained in:
Robin Davies
2022-03-11 12:06:32 -05:00
parent f60c85070d
commit c3da75ba34
4 changed files with 49 additions and 22 deletions
+16 -5
View File
@@ -4,15 +4,23 @@ PipPedal consists of the following components:
* A web application build in React, found in the react subdirectory. * A web application build in React, found in the react subdirectory.
* `pipedald`: a Web server, written in C++, serving a web socket, and pre-built HTML components from the React app. * `pipedald`
All audio services are provided by the pipedald process.
* `pipedalshutdownd`: A service to execute operations that require root credentials on behalf of pipedald. (e.g. shutdown, reboot, A web server, written in C++, serving a web socket, and pre-built HTML components from the React app.
All audio services are provided by the pipedald process.
* `pipedaladmind`:
A service to execute operations that require root credentials on behalf of pipedald. (e.g. shutdown, reboot,
and pushing configuration changes). and pushing configuration changes).
* `pipedalconfig`: A CLI utility for managing and configuring the pipedald services. * `pipedalconfig`:
A CLI utility for managing and configuring the pipedald services.
* `pipedaltest`: Test cases for pipedald, built using the Catch2 framework. * `pipedaltest`:
Test cases for pipedald, built using the Catch2 framework.
You must stop the pipedald service before launching a debug instance of pipedald: You must stop the pipedald service before launching a debug instance of pipedald:
@@ -26,6 +34,9 @@ or
But there's no harm in running a debug react server that's configured to connect to the web But there's no harm in running a debug react server that's configured to connect to the web
socket of a production instance of pipedald on port 80, if you aren't planning to debug C++ code. socket of a production instance of pipedald on port 80, if you aren't planning to debug C++ code.
The pipedald service will run with or without the pipedaladmind service, but some operations (shutdown, reboot,
audio and Wi-Fi configuration changes) may fail if the pipedaladmind service is not running.
In production, the pipedald web server serves the PiPedal web socket, as well as static HTML from the built In production, the pipedald web server serves the PiPedal web socket, as well as static HTML from the built
react components. But while debugging, it is much more convenient to use the React debug server for react components. But while debugging, it is much more convenient to use the React debug server for
React sources, and configure pipedald to serve only the websocket. React sources, and configure pipedald to serve only the websocket.
+3 -3
View File
@@ -228,7 +228,7 @@ add_executable(pipedalconfig json.cpp json.hpp
target_link_libraries(pipedalconfig PRIVATE pthread atomic stdc++fs target_link_libraries(pipedalconfig PRIVATE pthread atomic stdc++fs
) )
add_executable(pipedalshutdownd ShutdownMain.cpp CommandLineParser.hpp add_executable(pipedaladmind ShutdownMain.cpp CommandLineParser.hpp
JackServerSettings.hpp JackServerSettings.cpp JackServerSettings.hpp JackServerSettings.cpp
json.hpp json.cpp HtmlHelper.hpp HtmlHelper.cpp Lv2Log.hpp Lv2Log.cpp json.hpp json.cpp HtmlHelper.hpp HtmlHelper.cpp Lv2Log.hpp Lv2Log.cpp
Lv2SystemdLogger.hpp Lv2SystemdLogger.cpp Lv2SystemdLogger.hpp Lv2SystemdLogger.cpp
@@ -239,7 +239,7 @@ add_executable(pipedalshutdownd ShutdownMain.cpp CommandLineParser.hpp
CpuGovernor.cpp CpuGovernor.hpp CpuGovernor.cpp CpuGovernor.hpp
asan_options.cpp asan_options.cpp
) )
target_link_libraries(pipedalshutdownd PRIVATE pthread atomic stdc++fs systemd) target_link_libraries(pipedaladmind PRIVATE pthread atomic stdc++fs systemd)
add_executable(processcopyrights copyrightMain.cpp add_executable(processcopyrights copyrightMain.cpp
@@ -283,7 +283,7 @@ add_custom_target (
) )
install (TARGETS pipedalconfig pipedald pipedalshutdownd DESTINATION ${CMAKE_INSTALL_PREFIX}/bin install (TARGETS pipedalconfig pipedald pipedaladmind DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
EXPORT pipedalTargets) EXPORT pipedalTargets)
+29 -13
View File
@@ -53,9 +53,12 @@ using namespace pipedal;
#define SERVICE_PATH "/usr/lib/systemd/system" #define SERVICE_PATH "/usr/lib/systemd/system"
#define NATIVE_SERVICE "pipedald" #define NATIVE_SERVICE "pipedald"
#define SHUTDOWN_SERVICE "pipedalshutdownd" #define ADMIN_SERVICE "pipedaladmind"
#define JACK_SERVICE "jack" #define JACK_SERVICE "jack"
#define REMOVE_OLD_SERVICE 1 // Grandfathering: whether to remove the old shutdown service (now pipedaladmind)
#define OLD_SHUTDOWN_SERVICE "pipedalshutdownd"
std::filesystem::path GetServiceFileName(const std::string &serviceName) std::filesystem::path GetServiceFileName(const std::string &serviceName)
{ {
return std::filesystem::path(SERVICE_PATH) / (serviceName + ".service"); return std::filesystem::path(SERVICE_PATH) / (serviceName + ".service");
@@ -92,9 +95,9 @@ void EnableService()
{ {
cout << "Error: Failed to enable the " NATIVE_SERVICE " service."; cout << "Error: Failed to enable the " NATIVE_SERVICE " service.";
} }
if (sysExec(SYSTEMCTL_BIN " enable " SHUTDOWN_SERVICE ".service") != EXIT_SUCCESS) if (sysExec(SYSTEMCTL_BIN " enable " ADMIN_SERVICE ".service") != EXIT_SUCCESS)
{ {
cout << "Error: Failed to enable the " SHUTDOWN_SERVICE " service."; cout << "Error: Failed to enable the " ADMIN_SERVICE " service.";
} }
} }
void DisableService() void DisableService()
@@ -103,10 +106,16 @@ void DisableService()
{ {
cout << "Error: Failed to disable the " NATIVE_SERVICE " service."; cout << "Error: Failed to disable the " NATIVE_SERVICE " service.";
} }
if (sysExec(SYSTEMCTL_BIN " disable " SHUTDOWN_SERVICE ".service") != EXIT_SUCCESS) if (sysExec(SYSTEMCTL_BIN " disable " ADMIN_SERVICE ".service") != EXIT_SUCCESS)
{ {
cout << "Error: Failed to disable the " SHUTDOWN_SERVICE " service."; cout << "Error: Failed to disable the " ADMIN_SERVICE " service.";
} }
#if REMOVE_OLD_SERVICE
if (sysExec(SYSTEMCTL_BIN " disable " OLD_SHUTDOWN_SERVICE ".service") != EXIT_SUCCESS)
{
cout << "Error: Failed to disable the " OLD_SHUTDOWN_SERVICE " service.";
}
#endif
} }
void StopService(bool excludeShutdownService = false) void StopService(bool excludeShutdownService = false)
@@ -117,10 +126,16 @@ void StopService(bool excludeShutdownService = false)
} }
if (!excludeShutdownService) if (!excludeShutdownService)
{ {
if (sysExec(SYSTEMCTL_BIN " stop " SHUTDOWN_SERVICE ".service") != EXIT_SUCCESS) if (sysExec(SYSTEMCTL_BIN " stop " ADMIN_SERVICE ".service") != EXIT_SUCCESS)
{ {
cout << "Error: Failed to stop the " SHUTDOWN_SERVICE " service."; cout << "Error: Failed to stop the " ADMIN_SERVICE " service.";
} }
#if REMOVE_OLD_SERVICE
if (sysExec(SYSTEMCTL_BIN " stop " OLD_SHUTDOWN_SERVICE ".service") != EXIT_SUCCESS)
{
cout << "Error: Failed to stop the " OLD_SHUTDOWN_SERVICE " service.";
}
#endif
} }
if (sysExec(SYSTEMCTL_BIN " stop " JACK_SERVICE ".service") != EXIT_SUCCESS) if (sysExec(SYSTEMCTL_BIN " stop " JACK_SERVICE ".service") != EXIT_SUCCESS)
{ {
@@ -134,9 +149,9 @@ void StartService(bool excludeShutdownService = false)
silentSysExec("/usr/bin/pulseaudio --kill"); // interferes with Jack audio service startup. silentSysExec("/usr/bin/pulseaudio --kill"); // interferes with Jack audio service startup.
if (!excludeShutdownService) if (!excludeShutdownService)
{ {
if (sysExec(SYSTEMCTL_BIN " start " SHUTDOWN_SERVICE ".service") != EXIT_SUCCESS) if (sysExec(SYSTEMCTL_BIN " start " ADMIN_SERVICE ".service") != EXIT_SUCCESS)
{ {
throw PiPedalException("Failed to start the " SHUTDOWN_SERVICE " service."); throw PiPedalException("Failed to start the " ADMIN_SERVICE " service.");
} }
} }
if (sysExec(SYSTEMCTL_BIN " start " NATIVE_SERVICE ".service") != EXIT_SUCCESS) if (sysExec(SYSTEMCTL_BIN " start " NATIVE_SERVICE ".service") != EXIT_SUCCESS)
@@ -393,7 +408,8 @@ void Uninstall()
DisableService(); DisableService();
silentSysExec(SYSTEMCTL_BIN " stop jack"); silentSysExec(SYSTEMCTL_BIN " stop jack");
silentSysExec(SYSTEMCTL_BIN " disable jack"); silentSysExec(SYSTEMCTL_BIN " disable jack");
std::filesystem::remove("/usr/bin/systemd/system/" SHUTDOWN_SERVICE ".service"); std::filesystem::remove("/usr/bin/systemd/system/" OLD_SHUTDOWN_SERVICE ".service");
std::filesystem::remove("/usr/bin/systemd/system/" ADMIN_SERVICE ".service");
std::filesystem::remove("/usr/bin/systemd/system/" NATIVE_SERVICE ".service"); std::filesystem::remove("/usr/bin/systemd/system/" NATIVE_SERVICE ".service");
std::filesystem::remove("/usr/bin/systemd/system/" JACK_SERVICE ".service"); std::filesystem::remove("/usr/bin/systemd/system/" JACK_SERVICE ".service");
UninstallPamEnv(); UninstallPamEnv();
@@ -533,7 +549,7 @@ void Install(const std::filesystem::path &programPrefix, const std::string endpo
s << findOnPath("authbind").string() << " --deep "; s << findOnPath("authbind").string() << " --deep ";
} }
s s
<< (programPrefix / "bin/pipedald").string() << (programPrefix / "bin" / NATIVE_SERVICE).string()
<< " /etc/pipedal/config /etc/pipedal/react -port " << endpointAddress << " -systemd -shutdownPort " << shutdownPort; << " /etc/pipedal/config /etc/pipedal/react -port " << endpointAddress << " -systemd -shutdownPort " << shutdownPort;
map["COMMAND"] = s.str(); map["COMMAND"] = s.str();
@@ -545,12 +561,12 @@ void Install(const std::filesystem::path &programPrefix, const std::string endpo
std::stringstream s; std::stringstream s;
s s
<< (programPrefix / "bin/pipedalshutdownd").string() << (programPrefix / "bin" / ADMIN_SERVICE).string()
<< " -port " << shutdownPort; << " -port " << shutdownPort;
map["COMMAND"] = s.str(); map["COMMAND"] = s.str();
} }
WriteTemplateFile(map, std::filesystem::path("/etc/pipedal/templateShutdown.service"), GetServiceFileName(SHUTDOWN_SERVICE)); WriteTemplateFile(map, std::filesystem::path("/etc/pipedal/templateShutdown.service"), GetServiceFileName(ADMIN_SERVICE));
sysExec(SYSTEMCTL_BIN " daemon-reload"); sysExec(SYSTEMCTL_BIN " daemon-reload");
+1 -1
View File
@@ -14,7 +14,7 @@ ExecStart=/etc/jackdrc
User=jack User=jack
Group=audio Group=audio
Restart=always Restart=always
RestartSec=15 RestartSec=30
Environment=JACK_PROMISCUOUS_SERVER=audio Environment=JACK_PROMISCUOUS_SERVER=audio
Environment=JACK_NO_AUDIO_RESERVATION=1 Environment=JACK_NO_AUDIO_RESERVATION=1