mirror of
https://github.com/QuasarApp/Patronum.git
synced 2025-04-26 07:34: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();
|
||||
|
||||
service = service.arg(executable);
|
||||
service = service.arg(PCommon::instance()->getPidfile());
|
||||
service = service.arg(PCommon::instance()->getPWD());
|
||||
service = service.arg(PCommon::instance()->getPidfile(user));
|
||||
service = service.arg(PCommon::instance()->getPWD(user));
|
||||
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());
|
||||
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
#include <QFile>
|
||||
#include <QStandardPaths>
|
||||
#include "quasarapp.h"
|
||||
|
||||
namespace Patronum {
|
||||
|
||||
@ -13,8 +14,8 @@ const class PCommon *PCommon::instance() {
|
||||
return inst;
|
||||
}
|
||||
|
||||
QString PCommon::getPidfile() const {
|
||||
return getPWD() + "/" + getServiceName() + ".pid";
|
||||
QString PCommon::getPidfile(const QString& customUser) const {
|
||||
return getPWD(customUser) + "/" + getServiceName() + ".pid";
|
||||
}
|
||||
|
||||
qint64 PCommon::getPidFromPidfile() const {
|
||||
@ -30,8 +31,23 @@ qint64 PCommon::getPidFromPidfile() const {
|
||||
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);
|
||||
#endif
|
||||
}
|
||||
|
||||
QString PCommon::getServiceName() const {
|
||||
|
@ -26,9 +26,10 @@ public:
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*/
|
||||
QString getPidfile() const;
|
||||
QString getPidfile(const QString& customUser = "") const;
|
||||
|
||||
/**
|
||||
* @brief getPidFromPidfile This method return the pid from pidFile.
|
||||
@ -38,9 +39,10 @@ public:
|
||||
|
||||
/**
|
||||
* @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.
|
||||
*/
|
||||
QString getPWD() const;
|
||||
QString getPWD(const QString &customUser = "") const;
|
||||
|
||||
/**
|
||||
* @brief getServiceName return the service name.
|
||||
|
@ -78,7 +78,7 @@ bool ServicePrivate::sendCloseConnection() {
|
||||
return _socket->send(_parser->createPackage(Command::CloseConnection));
|
||||
}
|
||||
|
||||
bool ServicePrivate::install(QString user) {
|
||||
bool ServicePrivate::install(const QString &user) {
|
||||
|
||||
if (!_installer) {
|
||||
QuasarAppUtils::Params::log(errorToString(UnsupportedPlatform),
|
||||
@ -86,9 +86,6 @@ bool ServicePrivate::install(QString user) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (user.isEmpty())
|
||||
user = DEFAULT_USER;
|
||||
|
||||
if (!_installer->install(getServiceLauncher(), user)) {
|
||||
return false;
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ public:
|
||||
* @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
|
||||
*/
|
||||
bool install(QString user);
|
||||
bool install(const QString &user);
|
||||
|
||||
/**
|
||||
* @brief uninstall This method unistall your service in thec current system.
|
||||
|
Loading…
x
Reference in New Issue
Block a user