- Check to see if musikcubed is already running before allowing the process to start.

- Fixed rpath linking in musikcubed CMakeLists.
- CMake "install" fixes to properly include shared library and daemon.
- Experimental changes to use a shared libmusikcore library, instead of
  a static one.
This commit is contained in:
casey langen 2018-01-28 15:47:23 -08:00
parent 369f9054ba
commit c1574960db
7 changed files with 85 additions and 16 deletions

1
.gitignore vendored
View File

@ -32,4 +32,5 @@ src/plugins/taglib_plugin/obj
src/plugins/taglib_plugin/taglib-1.11
src/musikbox/musikbox
src/musikcube/musikcube
src/musikcubed/musikcubed
taglib-prefix

View File

@ -112,7 +112,7 @@ if (CMAKE_SYSTEM_NAME MATCHES "Linux")
add_subdirectory(src/plugins/pulseout)
add_dependencies(musikcube alsaout pulseout)
if (${ENABLE_SNDIO} MATCHES "true")
add_subdirectory(src/plugins/sndioout)
add_subdirectory(src/plugins/sndioout)
add_dependencies(musikcube sndioout)
endif()
elseif (CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
@ -127,14 +127,6 @@ elseif (CMAKE_SYSTEM_NAME MATCHES "Darwin")
add_dependencies(musikcube coreaudioout)
endif()
# install the binary
install(
FILES bin/musikcube DESTINATION share/musikcube
PERMISSIONS
OWNER_EXECUTE OWNER_READ OWNER_WRITE
GROUP_EXECUTE GROUP_READ GROUP_WRITE
WORLD_EXECUTE WORLD_READ)
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
file(GLOB plugins "bin/plugins/*.dylib")
install(FILES ${plugins} DESTINATION share/musikcube/plugins)
@ -154,7 +146,21 @@ file(GLOB locales "src/musikcube/data/locales/*.json")
file(COPY ${locales} DESTINATION bin/locales)
install(FILES ${locales} DESTINATION share/musikcube/locales)
# shell script that starts the app.
# libmusikcore sshared library
if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
install(FILES "bin/libmusikcore.dylib" DESTINATION share/musikcube)
else ()
install(FILES "bin/libmusikcore.so" DESTINATION share/musikcube)
endif ()
# executable and shell script for musikcube
install(
FILES bin/musikcube DESTINATION share/musikcube
PERMISSIONS
OWNER_EXECUTE OWNER_READ OWNER_WRITE
GROUP_EXECUTE GROUP_READ GROUP_WRITE
WORLD_EXECUTE WORLD_READ)
install(
FILES src/musikcube/musikcube
DESTINATION bin/
@ -163,6 +169,23 @@ install(
GROUP_EXECUTE GROUP_READ GROUP_WRITE
WORLD_EXECUTE WORLD_READ)
# executable and shell script for daemon
install(
FILES bin/musikcubed DESTINATION share/musikcube
PERMISSIONS
OWNER_EXECUTE OWNER_READ OWNER_WRITE
GROUP_EXECUTE GROUP_READ GROUP_WRITE
WORLD_EXECUTE WORLD_READ)
install(
FILES src/musikcubed/musikcubed
DESTINATION bin/
PERMISSIONS
OWNER_EXECUTE OWNER_READ OWNER_WRITE
GROUP_EXECUTE GROUP_READ GROUP_WRITE
WORLD_EXECUTE WORLD_READ)
# deb generation
if (GENERATE_DEB MATCHES "1")
if (CMAKE_SYSTEM_NAME MATCHES "Linux")
set(DEB_BOOST_VERSION "1.55.0")

View File

@ -62,5 +62,9 @@ include_directories(
../3rdparty/include/sqlite
)
add_library(musikcore STATIC ${CORE_SOURCES})
add_library(musikcore SHARED ${CORE_SOURCES})
set_target_properties(musikcore PROPERTIES
LIBRARY_OUTPUT_DIRECTORY ${musikcube_SOURCE_DIR}/bin)
target_link_libraries(musikcore ${musikcube_LINK_LIBS})

View File

@ -52,7 +52,6 @@ set (CUBE_SRCS
)
set(musikcube_INSTALL_DIR ${HOMEBREW_PREFIX})
if (NOT DEFINED musikcube_INSTALL_DIR)
set(musikcube_INSTALL_DIR ${CMAKE_INSTALL_PREFIX})
endif()
@ -60,9 +59,10 @@ endif()
configure_file("musikcube.in" "musikcube" @ONLY)
add_executable(musikcube ${CUBE_SRCS})
add_definitions(-DNCURSES_WIDECHAR)
set_target_properties(musikcube PROPERTIES LINK_FLAGS "-Wl,-rpath,./")
if (CMAKE_SYSTEM_NAME MATCHES "Linux" OR CMAKE_SYSTEM_NAME MATCHES "FreeBSD")
target_link_libraries(musikcube ${musikcube_LINK_LIBS} ncursesw panelw musikcore)
else()

View File

@ -1,6 +1,14 @@
set (DAEMON_SRCS
./main.cpp
./main.cpp
)
set(musikcube_INSTALL_DIR ${HOMEBREW_PREFIX})
if (NOT DEFINED musikcube_INSTALL_DIR)
set(musikcube_INSTALL_DIR ${CMAKE_INSTALL_PREFIX})
endif()
configure_file("musikcubed.in" "musikcubed" @ONLY)
add_executable(musikcubed ${DAEMON_SRCS})
target_link_libraries(musikcubed ${musikcube_LINK_LIBS} musikcore)
set_target_properties(musikcubed PROPERTIES LINK_FLAGS "-Wl,-rpath,./")

View File

@ -3,6 +3,8 @@
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <signal.h>
#include <iostream>
#include <core/audio/PlaybackService.h>
#include <core/audio/MasterTransport.h>
@ -21,6 +23,27 @@ using namespace musik::core;
using namespace musik::core::audio;
using namespace musik::core::runtime;
#ifdef __APPLE__
#define LOCKFILE "/tmp/musikcubed.lock"
#else
#define LOCKFILE "/var/lock/musikcubed.lock"
#endif
bool exitIfRunning() {
std::ifstream lock(LOCKFILE);
if (lock.good()) {
int pid;
lock >> pid;
if (kill((pid_t) pid, 0) == 0) {
std::cerr << "musikcubed is already running!\n";
exit(EXIT_SUCCESS);
return true;
}
}
std::cerr << "musikcubed is starting...\n";
return false;
}
void startDaemon() {
pid_t pid = fork();
@ -45,13 +68,18 @@ void startDaemon() {
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
freopen("/tmp/musikcube.log", "w", stderr);
std::ofstream lock(LOCKFILE);
if (lock.good()) {
lock << std::to_string((int) getpid());
}
}
int main() {
exitIfRunning();
startDaemon();
freopen("/tmp/musikcube.log", "w", stderr);
srand((unsigned int) time(0));
std::locale locale = std::locale();

View File

@ -0,0 +1,5 @@
#!/usr/bin/env bash
pushd @musikcube_INSTALL_DIR@/share/musikcube/ > /dev/null
{
./musikcubed && popd
} || popd > /dev/null