Made starting and killing of z-Leaves independent of installed scripts

remotes/origin/HEAD
markuspg 8 years ago
parent 8756b8e862
commit 598e68855a

@ -22,6 +22,8 @@ dvips_command=/usr/bin/dvips
file_manager=/usr/bin/dolphin
# The port which shall be used by zTree by default
initial_port=8000
# The command used to kill 'zleaf.exe' instances (part of the 'psmisc' package)
killall_command=/usr/bin/killall
# Where all Labcontrol data got installed
labcontrol_installation_directory=/usr/local/share/labcontrol
latex_command=/usr/bin/latex

@ -1,3 +0,0 @@
#!/bin/bash
/usr/bin/killall -I -q zleaf.exe

@ -1,15 +0,0 @@
#!/bin/bash
# Start a zLeaf with the given arguments
if [ $# == 2 ]; then
DISPLAY=:0.0 /usr/bin/wine /opt/z-Leaves/zTree_$1/zleaf.exe /server $2 &
exit
fi
if [ $# == 3 ]; then
DISPLAY=:0.0 /usr/bin/wine /opt/z-Leaves/zTree_$1/zleaf.exe /server $2 /channel $3 &
exit
fi
if [ $# == 4 ]; then
DISPLAY=:0.0 /usr/bin/wine /opt/z-Leaves/zTree_$1/zleaf.exe /server $2 /channel $3 /name $4 &
exit
fi

@ -138,11 +138,11 @@ void lc::Client::GotStatusChanged( state_t argState ) {
qDebug() << name << "status changed to:" << static_cast< unsigned short int >( argState );
}
void lc::Client::KillZLeaf( const QString &argPublickeyPathUser,
const QString &argUserNameOnClients ) {
void lc::Client::KillZLeaf() {
QStringList arguments;
arguments << "-i" << argPublickeyPathUser << QString{ argUserNameOnClients + "@" + ip }
<< QString{ settings->lcInstDir + "/scripts/kill_zLeaf_labcontrol2.sh" };
arguments << "-i" << settings->pkeyPathUser
<< QString{ settings->userNameOnClients + "@" + ip }
<< settings->killallCmd << "-I" << "-q" << "zleaf.exe";
// Start the process
QProcess killZLeafProcess;
@ -267,40 +267,51 @@ void lc::Client::Shutdown( const QString &argPublickeyPathUser, const QString &a
GotStatusChanged( state_t::SHUTTING_DOWN );
}
void lc::Client::StartZLeaf( const QString &argPublickeyPathUser,
const QString &argUserNameOnClients,
const QString * const argZTreeVersion,
const QString &argServerIP, unsigned short int argPort,
void lc::Client::StartZLeaf( const QString * const argZTreeVersion, unsigned short int argPort,
const QString * const argFakeName ) {
if ( state < state_t::RESPONDING ) {
return;
}
// Create a QMessageBox for user interaction if there is already a zLeaf running
QMessageBox *messageBoxRunningZLeafFound = nullptr;
std::unique_ptr< QMessageBox > messageBoxRunningZLeafFound;
if ( state == state_t::ZLEAF_RUNNING ) {
messageBoxRunningZLeafFound = new QMessageBox{ QMessageBox::Warning, "Running zLeaf found",
QString{ "There is already a zLeaf running on " + name + "." }, QMessageBox::No | QMessageBox::Yes };
messageBoxRunningZLeafFound->setInformativeText( "Do you want to start a zLeaf on client " + name + " nonetheless?" );
messageBoxRunningZLeafFound.reset( new QMessageBox{ QMessageBox::Warning, "Running zLeaf found",
QString{ "There is already a zLeaf running on " + name + "." },
QMessageBox::No | QMessageBox::Yes } );
messageBoxRunningZLeafFound->setInformativeText( "Do you want to start a zLeaf on client "
+ name + " nonetheless?" );
messageBoxRunningZLeafFound->setDefaultButton( QMessageBox::No );
messageBoxRunningZLeafFound->exec();
}
if ( ( messageBoxRunningZLeafFound != nullptr && messageBoxRunningZLeafFound->clickedButton() == messageBoxRunningZLeafFound->button( QMessageBox::Yes ) ) || state != state_t::ZLEAF_RUNNING ) {
if ( ( messageBoxRunningZLeafFound.get() != nullptr
&& messageBoxRunningZLeafFound->clickedButton()
== messageBoxRunningZLeafFound->button( QMessageBox::Yes ) )
|| state != state_t::ZLEAF_RUNNING ) {
QStringList arguments;
if ( argFakeName == nullptr && argPort == 7000 ) {
arguments << "-i" << argPublickeyPathUser << QString{ argUserNameOnClients + "@" + ip }
<< "DISPLAY=:0.0" << QString{ "/home/" + argUserNameOnClients + "/start_zLeaf_labcontrol2.sh" }
<< *argZTreeVersion << argServerIP;
arguments << "-i" << settings->pkeyPathUser
<< QString{ settings->userNameOnClients + "@" + ip }
<< "DISPLAY=:0.0" << settings->tasksetCmd << "0x00000001" << settings->wineCmd
<< QString{ settings->zTreeInstDir + "/zTree_" + *argZTreeVersion + "/zleaf.exe" }
<< "/server" << settings->serverIP;
} else {
if ( argFakeName == nullptr ) {
arguments << "-i" << argPublickeyPathUser << QString{ argUserNameOnClients + "@" + ip }
<< "DISPLAY=:0.0" << QString{ "/home/" + argUserNameOnClients + "/start_zLeaf_labcontrol2.sh" }
<< *argZTreeVersion << argServerIP << QString::number( static_cast< int >( argPort ) - 7000 );
arguments << "-i" << settings->pkeyPathUser
<< QString{ settings->userNameOnClients + "@" + ip }
<< "DISPLAY=:0.0" << settings->tasksetCmd << "0x00000001" << settings->wineCmd
<< QString{ settings->zTreeInstDir + "/zTree_" + *argZTreeVersion + "/zleaf.exe" }
<< "/server" << settings->serverIP << "/channel"
<< QString::number( static_cast< int >( argPort ) - 7000 );
} else {
arguments << "-i" << argPublickeyPathUser << QString{ argUserNameOnClients + "@" + ip }
<< "DISPLAY=:0.0" << QString{ "/home/" + argUserNameOnClients + "/start_zLeaf_labcontrol2.sh" }
<< *argZTreeVersion << argServerIP << QString::number( static_cast< int >( argPort ) - 7000 ) << *argFakeName ;
arguments << "-i" << settings->pkeyPathUser
<< QString{ settings->userNameOnClients + "@" + ip }
<< "DISPLAY=:0.0" << settings->tasksetCmd << "0x00000001" << settings->wineCmd
<< QString{ settings->zTreeInstDir + "/zTree_" + *argZTreeVersion + "/zleaf.exe" }
<< "/server" << settings->serverIP << "/channel"
<< QString::number( static_cast< int >( argPort ) - 7000 )
<< "/name" << *argFakeName;
}
}
@ -313,5 +324,4 @@ void lc::Client::StartZLeaf( const QString &argPublickeyPathUser,
// Output message via the debug messages tab
qDebug() << settings->sshCmd << arguments.join( " " );
}
delete messageBoxRunningZLeafFound;
}

@ -89,12 +89,10 @@ public:
@return The current state of the client
*/
state_t GetClientState() const { return state; }
//! Kills all processes 'zleaf.exe' on the client
/*!
@param argPublickeyPathUser The path to the publickey for user login on the clients
@param argUserNameOnClients The name of the user on the clients
*/
void KillZLeaf( const QString &argPublickeyPathUser, const QString &argUserNameOnClients );
* \brief Kills all processes 'zleaf.exe' on the client
*/
void KillZLeaf();
//! Opens a file manager for the client's file system
/*!
@param argUserToBeUsed The name of the user on the clients
@ -120,16 +118,12 @@ public:
void Shutdown( const QString &argPublickeyPathUser, const QString &argUserNameOnClients );
//! Starts a zLeaf instance on the client
/*!
@param argPublickeyPathUser The path to the publickey for user login on the clients
@param argUserNameOnClients The name of the user on the clients
@param argZTreeVersion The version of zLeaf which shall be started
@param argServerIP The ip of the server which is running zTree
@param argPort The port zTree ist listening on on the server
@param argFakeName The name the zLeaf instance shall have (if not the default, which is the hostname of the client)
*/
void StartZLeaf( const QString &argPublickeyPathUser, const QString &argUserNameOnClients,
const QString * const argZTreeVersion, const QString &argServerIP,
unsigned short int argPort, const QString * const argFakeName = nullptr );
void StartZLeaf( const QString * const argZTreeVersion, unsigned short int argPort,
const QString * const argFakeName = nullptr );
private:
unsigned short int protectedCycles;

@ -16,6 +16,9 @@ lc::Settings::Settings( const QSettings &argSettings, QObject *argParent ) :
fileMngr{ ReadSettingsItem( "file_manager",
"The display of preprints will not work.",
argSettings, true ) },
killallCmd{ ReadSettingsItem( "killall_command",
"Killing 'zleaf.exe' instances will not work.",
argSettings, true ) },
latexCmd{ ReadSettingsItem( "latex_command",
"Receipts creation will not work.",
argSettings, true ) },

@ -23,6 +23,7 @@ public:
const QString browserCmd;
const QString dvipsCmd;
const QString fileMngr;
const QString killallCmd;
const QString latexCmd;
const QString lcInstDir;
const QString localUserName;

@ -69,6 +69,11 @@ bool lc::MainWindow::CheckIfUserIsAdmin() {
}
void lc::MainWindow::DisableDisfunctionalWidgets() {
// Disable all z-Leaf killing related buttons if the 'killall' command is not available
if ( settings->killallCmd.isEmpty() ) {
ui->PBKillLocalzLeaf->setEnabled( false );
ui->PBKillzLeaf->setEnabled( false );
}
// Disable all functions relying on the labcontrol installation directory if it is not available
if ( settings->lcInstDir.isEmpty() ) {
ui->CBClientNames->setEnabled( false );
@ -331,18 +336,20 @@ void lc::MainWindow::on_PBExecute_clicked() {
}
void lc::MainWindow::on_PBKillLocalzLeaf_clicked() {
QString program{ settings->lcInstDir + "/scripts/kill_zLeaf_labcontrol2.sh" };
QString program{ settings->killallCmd };
QStringList arguments;
arguments << "-I" << "-q" << "zleaf.exe";
// Start the process
QProcess kill_zleaf_process;
QProcess killLocalzLeafProc;
QProcessEnvironment env = QProcessEnvironment::systemEnvironment();
kill_zleaf_process.setProcessEnvironment( env );
kill_zleaf_process.startDetached( program );
killLocalzLeafProc.setProcessEnvironment( env );
killLocalzLeafProc.startDetached( program, arguments );
local_zLeaves_are_running = false;
// Output message via the debug messages tab
qDebug() << program;
qDebug() << program << arguments;
}
void lc::MainWindow::on_PBKillzLeaf_clicked() {
@ -350,7 +357,7 @@ void lc::MainWindow::on_PBKillzLeaf_clicked() {
for ( QModelIndexList::ConstIterator it = activated_items.cbegin(); it != activated_items.cend(); ++it ) {
if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) {
Client *client = static_cast< Client* >( ( *it ).data( Qt::UserRole ).value< void * >() );
client->KillZLeaf( settings->pkeyPathUser, settings->userNameOnClients );
client->KillZLeaf();
}
}
}
@ -439,8 +446,7 @@ void lc::MainWindow::on_PBRunzLeaf_clicked() {
for ( QModelIndexList::ConstIterator it = activatedItems.cbegin(); it != activatedItems.cend(); ++it ) {
if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) {
Client *client = static_cast< Client* >( ( *it ).data( Qt::UserRole ).value< void * >() );
client->StartZLeaf( settings->pkeyPathUser, settings->userNameOnClients,
zLeafVersion, settings->serverIP, ui->SBzLeafPort->value(),
client->StartZLeaf( zLeafVersion, ui->SBzLeafPort->value(),
fakeName );
}
}
@ -529,8 +535,7 @@ void lc::MainWindow::on_PBStartzLeaf_clicked() {
for ( QModelIndexList::ConstIterator it = activated_items.cbegin(); it != activated_items.cend(); ++it ) {
if ( ( *it ).data( Qt::DisplayRole ).type() != 0 ) {
Client *client = static_cast< Client* >( ( *it ).data( Qt::UserRole ).value< void * >() );
client->StartZLeaf( settings->pkeyPathUser, settings->userNameOnClients,
zLeafVersion, settings->serverIP, ui->SBzLeafPort->value(),
client->StartZLeaf( zLeafVersion, ui->SBzLeafPort->value(),
nullptr );
}
}

Loading…
Cancel
Save