mirror of
https://github.com/QuasarApp/Patronum.git
synced 2025-04-26 23:54:32 +00:00
added support of custom users
This commit is contained in:
parent
d1b866aeb2
commit
08fa00a2c2
@ -47,10 +47,14 @@ bool InstallerSystemD::install(const QString &executable, const QString& user) {
|
|||||||
templ.close();
|
templ.close();
|
||||||
|
|
||||||
service = service.arg(executable);
|
service = service.arg(executable);
|
||||||
service = service.arg(PCommon::instance()->getPidfile());
|
service = service.arg(PCommon::instance()->getPidfile(user));
|
||||||
service = service.arg(PCommon::instance()->getPWD());
|
service = service.arg(PCommon::instance()->getPWD(user));
|
||||||
service = service.arg(PCommon::instance()->getServiceName());
|
service = service.arg(PCommon::instance()->getServiceName());
|
||||||
service = service.arg(user);
|
|
||||||
|
if (user.isEmpty())
|
||||||
|
service = service.arg(DEFAULT_USER);
|
||||||
|
else
|
||||||
|
service = service.arg(user);
|
||||||
|
|
||||||
templ.setFileName(absaluteServicePath());
|
templ.setFileName(absaluteServicePath());
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
|
#include "quasarapp.h"
|
||||||
|
|
||||||
namespace Patronum {
|
namespace Patronum {
|
||||||
|
|
||||||
@ -13,8 +14,8 @@ const class PCommon *PCommon::instance() {
|
|||||||
return inst;
|
return inst;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString PCommon::getPidfile() const {
|
QString PCommon::getPidfile(const QString& customUser) const {
|
||||||
return getPWD() + "/" + getServiceName() + ".pid";
|
return getPWD(customUser) + "/" + getServiceName() + ".pid";
|
||||||
}
|
}
|
||||||
|
|
||||||
qint64 PCommon::getPidFromPidfile() const {
|
qint64 PCommon::getPidFromPidfile() const {
|
||||||
@ -30,8 +31,23 @@ qint64 PCommon::getPidFromPidfile() const {
|
|||||||
return data.toLongLong();
|
return data.toLongLong();
|
||||||
}
|
}
|
||||||
|
|
||||||
QString PCommon::getPWD() const {
|
QString PCommon::getPWD(const QString& customUser) const {
|
||||||
|
if (!customUser.size())
|
||||||
|
return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
|
||||||
|
|
||||||
|
#ifdef Q_OS_LINUX
|
||||||
|
if (customUser == "root")
|
||||||
|
return "/root/.local/share/" + getServiceName();
|
||||||
|
|
||||||
|
return "/home/" + customUser + "/.local/share/" + getServiceName();
|
||||||
|
#else
|
||||||
|
|
||||||
|
QuasarAppUtils::Params::log("The custom user not support for " +
|
||||||
|
QSysInfo::kernelType(),
|
||||||
|
QuasarAppUtils::Error);
|
||||||
|
|
||||||
return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
|
return QStandardPaths::writableLocation(QStandardPaths::AppDataLocation);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
QString PCommon::getServiceName() const {
|
QString PCommon::getServiceName() const {
|
||||||
|
@ -26,9 +26,10 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief pidFilePath This method return the absalute path to the service pid file.
|
* @brief pidFilePath This method return the absalute path to the service pid file.
|
||||||
|
* @param customUser This is name of custom user for that will return PWD dir.
|
||||||
* @return absalute path to the service pid file.
|
* @return absalute path to the service pid file.
|
||||||
*/
|
*/
|
||||||
QString getPidfile() const;
|
QString getPidfile(const QString& customUser = "") const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief getPidFromPidfile This method return the pid from pidFile.
|
* @brief getPidFromPidfile This method return the pid from pidFile.
|
||||||
@ -38,9 +39,10 @@ public:
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief getPWD This method return PWD of the service.
|
* @brief getPWD This method return PWD of the service.
|
||||||
|
* @param customUser This is name of custom user for that will return PWD dir.
|
||||||
* @return absalute path of the work directory.
|
* @return absalute path of the work directory.
|
||||||
*/
|
*/
|
||||||
QString getPWD() const;
|
QString getPWD(const QString &customUser = "") const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief getServiceName return the service name.
|
* @brief getServiceName return the service name.
|
||||||
|
@ -78,7 +78,7 @@ bool ServicePrivate::sendCloseConnection() {
|
|||||||
return _socket->send(_parser->createPackage(Command::CloseConnection));
|
return _socket->send(_parser->createPackage(Command::CloseConnection));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ServicePrivate::install(QString user) {
|
bool ServicePrivate::install(const QString &user) {
|
||||||
|
|
||||||
if (!_installer) {
|
if (!_installer) {
|
||||||
QuasarAppUtils::Params::log(errorToString(UnsupportedPlatform),
|
QuasarAppUtils::Params::log(errorToString(UnsupportedPlatform),
|
||||||
@ -86,9 +86,6 @@ bool ServicePrivate::install(QString user) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (user.isEmpty())
|
|
||||||
user = DEFAULT_USER;
|
|
||||||
|
|
||||||
if (!_installer->install(getServiceLauncher(), user)) {
|
if (!_installer->install(getServiceLauncher(), user)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ public:
|
|||||||
* @param user This is name of custom user that will be run your service after reboot system.
|
* @param user This is name of custom user that will be run your service after reboot system.
|
||||||
* @return return true if the service installed succesful
|
* @return return true if the service installed succesful
|
||||||
*/
|
*/
|
||||||
bool install(QString user);
|
bool install(const QString &user);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief uninstall This method unistall your service in thec current system.
|
* @brief uninstall This method unistall your service in thec current system.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user