Merge pull request #29 from rerdavies/rerdavies/issue17

Change Shutdown service name to PiPedalSupervisor
This commit is contained in:
Robin Davies
2022-03-11 12:19:24 -05:00
committed by GitHub
5 changed files with 51 additions and 24 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.
* `pipedald`: 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.
* `pipedald`
* `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).
* `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:
@@ -26,6 +34,9 @@ or
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.
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
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.
+2 -2
View File
@@ -197,14 +197,14 @@ export const MainPage =
let selectedItem = -1;
for (let i = 0; i < value.items.length; ++i)
{
if (this.state.selectedPedal == value.items[i].instanceId)
if (this.state.selectedPedal === value.items[i].instanceId)
{
selectedItem = this.state.selectedPedal;
break;
}
}
// if no selection the current pedalboard, reset to the first item.
if (selectedItem == -1)
if (selectedItem === -1)
{
selectedItem = value.items[0].instanceId;
}
+3 -3
View File
@@ -228,7 +228,7 @@ add_executable(pipedalconfig json.cpp json.hpp
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
json.hpp json.cpp HtmlHelper.hpp HtmlHelper.cpp Lv2Log.hpp Lv2Log.cpp
Lv2SystemdLogger.hpp Lv2SystemdLogger.cpp
@@ -239,7 +239,7 @@ add_executable(pipedalshutdownd ShutdownMain.cpp CommandLineParser.hpp
CpuGovernor.cpp CpuGovernor.hpp
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
@@ -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)
+29 -13
View File
@@ -53,9 +53,12 @@ using namespace pipedal;
#define SERVICE_PATH "/usr/lib/systemd/system"
#define NATIVE_SERVICE "pipedald"
#define SHUTDOWN_SERVICE "pipedalshutdownd"
#define ADMIN_SERVICE "pipedaladmind"
#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)
{
return std::filesystem::path(SERVICE_PATH) / (serviceName + ".service");
@@ -92,9 +95,9 @@ void EnableService()
{
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()
@@ -103,10 +106,16 @@ void DisableService()
{
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)
@@ -117,10 +126,16 @@ void StopService(bool excludeShutdownService = false)
}
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)
{
@@ -134,9 +149,9 @@ void StartService(bool excludeShutdownService = false)
silentSysExec("/usr/bin/pulseaudio --kill"); // interferes with Jack audio service startup.
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)
@@ -393,7 +408,8 @@ void Uninstall()
DisableService();
silentSysExec(SYSTEMCTL_BIN " stop 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/" JACK_SERVICE ".service");
UninstallPamEnv();
@@ -533,7 +549,7 @@ void Install(const std::filesystem::path &programPrefix, const std::string endpo
s << findOnPath("authbind").string() << " --deep ";
}
s
<< (programPrefix / "bin/pipedald").string()
<< (programPrefix / "bin" / NATIVE_SERVICE).string()
<< " /etc/pipedal/config /etc/pipedal/react -port " << endpointAddress << " -systemd -shutdownPort " << shutdownPort;
map["COMMAND"] = s.str();
@@ -545,12 +561,12 @@ void Install(const std::filesystem::path &programPrefix, const std::string endpo
std::stringstream s;
s
<< (programPrefix / "bin/pipedalshutdownd").string()
<< (programPrefix / "bin" / ADMIN_SERVICE).string()
<< " -port " << shutdownPort;
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");
+1 -1
View File
@@ -14,7 +14,7 @@ ExecStart=/etc/jackdrc
User=jack
Group=audio
Restart=always
RestartSec=15
RestartSec=30
Environment=JACK_PROMISCUOUS_SERVER=audio
Environment=JACK_NO_AUDIO_RESERVATION=1