https://github.com/tomenz/srvlib
A plugin library to make your console application a windows system service, or a Linux daemon service
https://github.com/tomenz/srvlib
cpp-library cpp11 daemon daemonize library linux-daemon service systemd windows windows-service
Last synced: 8 months ago
JSON representation
A plugin library to make your console application a windows system service, or a Linux daemon service
- Host: GitHub
- URL: https://github.com/tomenz/srvlib
- Owner: Tomenz
- License: mit
- Created: 2020-09-16T14:37:36.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-11-13T12:41:12.000Z (over 1 year ago)
- Last Synced: 2025-04-03T08:22:24.657Z (11 months ago)
- Topics: cpp-library, cpp11, daemon, daemonize, library, linux-daemon, service, systemd, windows, windows-service
- Language: C++
- Homepage:
- Size: 88.9 KB
- Stars: 6
- Watchers: 1
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SrvLib
[](https://app.codacy.com/gh/Tomenz/SrvLib?utm_source=github.com&utm_medium=referral&utm_content=Tomenz/SrvLib&utm_campaign=Badge_Grade)
[](https://ci.appveyor.com/project/Tomenz/srvlib)
[](https://github.com/Tomenz/SrvLib/actions/workflows/codeql.yml)
[](https://github.com/Tomenz/SrvLib/actions/workflows/cmake.yml)
A plugin library to make your console application a windows system service, or a linux daemon service
# Windows
On Windows there are commandline option to install,remove,start and stop the service.
-i Install the system service
-r Removes the system service
-s Starts the system service
-e Shuts down the system service
-p System service is paused (pause)
-c System service will continue (Continue)
-f Start the application as a console application
-k Reload configuration
-h Show this help
# Linux - systemd
Rename an copy the example.service file after editing to /etc/systemd/system/
Reload the systemd as root with: systemctl daemon-reload
IN THE NEXT COMMANDS USE THE NAME OF THE RENAMED "example" FILE!
Enable the auto start run this command as root: systemctl enable example.service
To start the service, run as root: systemctl start example.service
To stop the service, run as root: systemctl stop example.service
To reload the what ever, run as root: systemctl reload example.service
# Linux - init.d
Copy the file in the init.d directory to /etc/init.d/ and rename it, modify the execution rights, and change the application name and the path for the application in that file.
commanline option are:
/etc/init.d/filename start|stop|status|restart|reload|install|remove
# Example
```
#include "Service.h"
int main(int argc, const char* argv[])
{
SrvParam svParam;
#if defined(_WIN32) || defined(_WIN64)
svParam.szDspName = L"Example Service"; // Servicename in Service control manager of windows
svParam.szDescrip = L"Example Service by your name"; // Description in Service control manager of windows
#endif
svParam.szSrvName = L"ExampleServ"; // Service name (service id)
svParam.fnStartCallBack = []()
{ // Start you server here
};
svParam.fnStopCallBack = []()
{ // Stop you server here
};
svParam.fnSignalCallBack = []()
{ // what ever you do with this callback, maybe reload the configuration
};
return ServiceMain(argc, argv, svParam);
}
```