mirror of
https://github.com/QuasarApp/Patronum.git
synced 2025-04-26 07:34:32 +00:00
added custom user support
This commit is contained in:
parent
42c014fa73
commit
54becf6daa
@ -117,7 +117,7 @@ void ServiceBase::printDefaultHelp() {
|
||||
serviceHelp.unite({{QObject::tr("Options that available befor install"),{
|
||||
{"start / s", QObject::tr("Start a service in console")},
|
||||
{"daemon / d", QObject::tr("Start a service as a daemon")},
|
||||
{"install / i", QObject::tr("Install a service")},
|
||||
{"install / i / -install username", QObject::tr("Install a service. Add user name if you want to run service from custom user. Example: -install username")},
|
||||
{"unistall / u", QObject::tr("unistall a service")},
|
||||
}}});
|
||||
|
||||
@ -163,7 +163,7 @@ int ServiceBase::exec() {
|
||||
bool fDaemon = QuasarAppUtils::Params::isEndable("daemon") || QuasarAppUtils::Params::isEndable("d");
|
||||
|
||||
if (QuasarAppUtils::Params::isEndable("install") || QuasarAppUtils::Params::isEndable("i")) {
|
||||
if (!d_ptr->install())
|
||||
if (!d_ptr->install(QuasarAppUtils::Params::getArg("install", "root")))
|
||||
return Patronum::PatronumError::UnsupportedPlatform;
|
||||
return 0;
|
||||
}
|
||||
|
@ -3,8 +3,8 @@ Description=%3 service. This service generated automaticly by Patronum libarary.
|
||||
|
||||
[Service]
|
||||
Type=forking
|
||||
User=root
|
||||
Group=root
|
||||
User=%4
|
||||
Group=%4
|
||||
ExecStart=%0 d
|
||||
ExecStop=%0 stop
|
||||
PIDFile=%1
|
||||
|
@ -18,7 +18,10 @@ BaseInstaller::BaseInstaller():
|
||||
|
||||
}
|
||||
|
||||
bool BaseInstaller::install(const QString &executable) {
|
||||
bool BaseInstaller::install(const QString &executable, const QString &user) {
|
||||
|
||||
Q_UNUSED(user)
|
||||
|
||||
if (!QFile::exists(executable)) {
|
||||
QuasarAppUtils::Params::log(QObject::tr("The service executable file is not exists %0\n").arg(executable),
|
||||
QuasarAppUtils::Error);
|
||||
|
@ -25,9 +25,10 @@ public:
|
||||
/**
|
||||
* @brief install This implementation prepare executable for instalation.
|
||||
* @param executable This is path to executable file of service.
|
||||
* @param user This is user that will be run installed service. by default it is root.
|
||||
* @return true if service is not installed else false
|
||||
*/
|
||||
bool install(const QString &executable) override;
|
||||
bool install(const QString &executable, const QString& user = DEFAULT_USER) override;
|
||||
|
||||
/**
|
||||
* @brief uninstall This method check if service installed.
|
||||
|
@ -10,9 +10,11 @@
|
||||
|
||||
#include <QString>
|
||||
|
||||
#define DEFAULT_USER "root"
|
||||
|
||||
namespace Patronum {
|
||||
|
||||
|
||||
/**
|
||||
* @brief The Installer class - base interface for all plugins
|
||||
*/
|
||||
@ -22,12 +24,36 @@ public:
|
||||
Installer();
|
||||
virtual ~Installer() = default;
|
||||
|
||||
virtual bool install(const QString& executable) = 0;
|
||||
/**
|
||||
* @brief install This method install service on host.
|
||||
* @param executable This is path to service executable.
|
||||
* @param user This is user tah will run serveice. If this argument is empty the service will be use root user.
|
||||
* @return true if service installed successfull
|
||||
*/
|
||||
virtual bool install(const QString& executable, const QString& user = DEFAULT_USER) = 0;
|
||||
|
||||
/**
|
||||
* @brief uninstall This method remove service from autostart.
|
||||
* @return trur if service removed successful
|
||||
*/
|
||||
virtual bool uninstall() = 0;
|
||||
|
||||
/**
|
||||
* @brief enable This method enable installed service. This method invoked by default in the Installer::install method.
|
||||
* @return true if the service enabled successfull.
|
||||
*/
|
||||
virtual bool enable() = 0;
|
||||
|
||||
/**
|
||||
* @brief disable This method disable installed service.
|
||||
* @return true if the service disabled successfull.
|
||||
*/
|
||||
virtual bool disable() = 0;
|
||||
|
||||
/**
|
||||
* @brief isInstalled This method return true if service alredy installed.
|
||||
* @return true if service alredy installed else flase.
|
||||
*/
|
||||
virtual bool isInstalled() const = 0;
|
||||
|
||||
|
||||
|
@ -25,7 +25,7 @@ Patronum::InstallerSystemD::~InstallerSystemD() {
|
||||
|
||||
}
|
||||
|
||||
bool InstallerSystemD::install(const QString &executable) {
|
||||
bool InstallerSystemD::install(const QString &executable, const QString& user) {
|
||||
|
||||
if (!BaseInstaller::install(executable)) {
|
||||
return false;
|
||||
@ -50,6 +50,7 @@ bool InstallerSystemD::install(const QString &executable) {
|
||||
service = service.arg(PCommon::instance()->getPidfile());
|
||||
service = service.arg(PCommon::instance()->getPWD());
|
||||
service = service.arg(PCommon::instance()->getServiceName());
|
||||
service = service.arg(user);
|
||||
|
||||
templ.setFileName(absaluteServicePath());
|
||||
|
||||
|
@ -26,7 +26,7 @@ public:
|
||||
|
||||
// Installer interface
|
||||
public:
|
||||
bool install(const QString &executable) override;
|
||||
bool install(const QString &executable, const QString &user = DEFAULT_USER) override;
|
||||
bool uninstall() override;
|
||||
bool enable() override;
|
||||
bool disable() override;
|
||||
|
@ -78,7 +78,7 @@ bool ServicePrivate::sendCloseConnection() {
|
||||
return _socket->send(_parser->createPackage(Command::CloseConnection));
|
||||
}
|
||||
|
||||
bool ServicePrivate::install() {
|
||||
bool ServicePrivate::install(const QString& user) {
|
||||
|
||||
if (!_installer) {
|
||||
QuasarAppUtils::Params::log(errorToString(UnsupportedPlatform),
|
||||
@ -86,7 +86,7 @@ bool ServicePrivate::install() {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!_installer->install(getServiceLauncher())) {
|
||||
if (!_installer->install(getServiceLauncher(), user)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -48,9 +48,10 @@ public:
|
||||
|
||||
/**
|
||||
* @brief install This method install your service in thec current 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
|
||||
*/
|
||||
bool install();
|
||||
bool install(const QString &user);
|
||||
|
||||
/**
|
||||
* @brief uninstall This method unistall your service in thec current system.
|
||||
|
@ -18,8 +18,8 @@ Becouse This library offers easy interface to control your demons likewise the m
|
||||
* Auto create a Controller of your Service.
|
||||
|
||||
## Deffault sopprted commands
|
||||
* install - deploys your daemon into your host system.
|
||||
* unistall - removes old deployed daemon.
|
||||
* install - deploys your daemon into your host system. This command deploy service for root user if you want to deploy service for specify user just use **-install <UserName>** command (root right required)
|
||||
* unistall - removes old deployed daemon. (root right required)
|
||||
* start - starts your service
|
||||
* stop - stops ypur service
|
||||
* pause - sends pause command to your daemon
|
||||
|
Loading…
x
Reference in New Issue
Block a user