adding systemd service

main
Steffen Pohle 3 weeks ago
parent eeac4f134b
commit 526e29739f

@ -7,6 +7,7 @@ PREFIX=/usr/local
DATAPREFIX=/var/lib
RUNPID=/var/run/miniwebcam.pid
ETCPREFIX=/etc
SYSTEMDUNITDIR=$(ETCPREFIX)/systemd/system
DEFAULT_SERVERPORT=20010
ARCH=$(shell uname -m)
CXX=g++
@ -33,10 +34,13 @@ miniwebcam: $(OBJFILES) assets.obj
rm -rf assets.obj
install: miniwebcam
cp -rf miniwebcam $(PREFIX)/bin
install -d $(DESTDIR)$(PREFIX)/bin $(DESTDIR)$(SYSTEMDUNITDIR)
install -m 755 miniwebcam $(DESTDIR)$(PREFIX)/bin/miniwebcam
sed 's|@PREFIX@|$(PREFIX)|g' miniwebcam.service > $(DESTDIR)$(SYSTEMDUNITDIR)/miniwebcam.service
uninstall:
rm -rf $(PREFIX)/bin/miniwebcam
rm -f $(DESTDIR)$(PREFIX)/bin/miniwebcam
rm -f $(DESTDIR)$(SYSTEMDUNITDIR)/miniwebcam.service
config:
echo "#ifndef _CONFIG_H_" > config.h

@ -12,6 +12,20 @@ The configuration is loaded in the following order.
- program parameters
- user defined configurtion file defined in the program parameters
The program runs in the foreground by default. Use `-D` to detach and run as a
daemon, or `-F` to explicitly run in the foreground. Daemon mode redirects
standard input, output, and error to `/dev/null`; use `-debug` only when running
in the foreground if you need to see debug output.
The default system configuration file is `/etc/miniwebcam.conf`. `make install`
installs the executable and a systemd service unit. After installing, reload
systemd and enable/start the service with:
```sh
sudo systemctl daemon-reload
sudo systemctl enable --now miniwebcam.service
```
# INFORMATION
here are some usefull commands, maybe it helps to set the resolution to a readonable value

@ -257,7 +257,7 @@ int Configuration::LoadArgs(int argc, char **argv) {
void Configuration::Help() {
printf ("Parameters:\n");
printf (" -F run in foreground\n");
printf (" -F run in foreground (default)\n");
printf (" -D run as daemon\n");
printf (" -debug enable debug output\n");
printf (" -debug_off disable debug output\n");
@ -281,7 +281,7 @@ void Configuration::Help() {
printf (" -config FILE load this configfile\n");
printf (" -dump_config print the config file\n");
printf ("\n");
printf (" -H print this help\n");
printf (" -h, --help print this help\n");
printf ("\n\nSample:\n");
printf (" ./miniwebcam -sslkey ./ssl-key.pem -sslcert ./ssl-cert.pem -websize 800x600\n");
}

@ -10,7 +10,7 @@
#define DEFAULT_HTTP_PORT 8080
#define DEFAULT_HTTPS_PORT 8081
#define DEFAULT_CONFIG_FILE "/etc/miniwebcam/miniwebcam.conf"
#define DEFAULT_CONFIG_FILE "/etc/miniwebcam.conf"
#define DEFAULT_SSL_KEY "/etc/miniwebcam/ssl-key.pem"
#define DEFAULT_SSL_CERT "/etc/miniwebcam/ssl-cert.pem"
#define DEFAULT_VDEV_IOMODE 1
@ -71,4 +71,3 @@ public:
extern Configuration config;
#endif

@ -1,8 +1,11 @@
#define _DEFAULT_SOURCE
#include <stdio.h>
#include <stdlib.h>
#include <sysexits.h>
#include <signal.h>
#include <unistd.h>
#include <string>
@ -146,13 +149,17 @@ int main(int argc, char **argv) {
return 0;
}
printf ("MiniWebCam:\n");
if (config.GetInitFlags() & CONF_INITFLAGS_HELP) {
config.Help();
return 0;
}
if (config.runasdaemon && daemon(0, 0) != 0) {
perror("could not daemonize");
return EX_OSERR;
}
printf ("MiniWebCam:\n");
debug_enable(config.debug);
pthread_create(&thr_webserver, NULL, &thread_webserver, NULL);
@ -231,4 +238,3 @@ int timedeiff_ms(timeval *t1) {
return res;
};

@ -0,0 +1,11 @@
[Unit]
Description=MiniWebCam server
After=network.target
[Service]
Type=simple
ExecStart=@PREFIX@/bin/miniwebcam -F
Restart=on-failure
[Install]
WantedBy=multi-user.target
Loading…
Cancel
Save