Skip to content

Commit

Permalink
Move server restart to service
Browse files Browse the repository at this point in the history
  • Loading branch information
tcorbly committed Nov 30, 2023
1 parent 2834418 commit ac6d572
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 48 deletions.
3 changes: 1 addition & 2 deletions include/botui/Create3Widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ private slots:
int m_position_1;
double m_vel_1;

QProcess *podmanStop;
QProcess *podmanStart;
QProcess *create3ServerService;

};

Expand Down
57 changes: 11 additions & 46 deletions src/Create3Widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ Create3Widget::Create3Widget(Device *device, QWidget *parent)
connect(ui->Create3SensorListButton, SIGNAL(clicked()), SLOT(sensorList()));
connect(ui->Create3ExampleProgramButton, SIGNAL(clicked()), SLOT(exampleList()));

podmanStop = new QProcess(this);
podmanStart = new QProcess(this);

create3ServerService = new QProcess(this);

ui->create3IP->setText(getIP());
}
Expand Down Expand Up @@ -117,58 +115,25 @@ int Create3Widget::isConnected()

void Create3Widget::resetServer()
{
QString podmanStopCommand = "sudo";
QStringList podmanStopArgs = {
"podman",
"stop",
"-a"
};

connect(podmanStop, &QProcess::readyReadStandardOutput, [=]() {
QByteArray data = podmanStop->readAllStandardOutput();
qDebug() << "Output:" << data;
});

connect(podmanStop, &QProcess::readyReadStandardError, [=]() {
QByteArray data = podmanStop->readAllStandardError();
qDebug() << "Error:" << data;
});

podmanStop->start(podmanStopCommand, podmanStopArgs);

if (podmanStop->waitForFinished())
{
qDebug() << "Podman container successfully stopped with exit code:" << podmanStop->exitCode();
}
else
{
qDebug() << "Podman stop failed to start or crashed.";
}

QString podmanStartCommand = "sudo";
QStringList podmanStartArgs = {
"podman",
"run",
"-dt",
"--rm",
"--net=host",
"--env",
"IP=192.168.125.1",
"docker.io/kipradmin/create3_docker"
QString restartCommand = "sudo";
QStringList restartArgs = {
"systemctl",
"restart",
"create3_server.service"
};

connect(podmanStart, &QProcess::readyReadStandardError, [=]() {
QByteArray data = podmanStart->readAllStandardError();
connect(create3ServerService, &QProcess::readyReadStandardError, [=]() {
QByteArray data = create3ServerService->readAllStandardError();
qDebug() << "Error:" << data;
});

if (podmanStart->startDetached(podmanStartCommand, podmanStartArgs))
if (create3ServerService->startDetached(restartCommand, restartArgs))
{
qDebug() << "Podman container successfully started and detached";
qDebug() << "Create3 Server successfully restarted and detached";
}
else
{
qDebug() << "Podman container failed to start or crashed.";
qDebug() << "Create3 Server failed to restart or crashed.";
}
}

Expand Down

0 comments on commit ac6d572

Please sign in to comment.