Now starts properly at boot with the Galileo's systemd.

This commit is contained in:
2018-11-22 03:02:45 +00:00
parent cbc6991385
commit 35cdf5823f
2 changed files with 25 additions and 0 deletions

12
robot.service Normal file
View File

@@ -0,0 +1,12 @@
#! /bin/sh
[Unit]
Description=Robot daemon
[Service]
Type=forking
PIDFile=/var/run/robot.pid
WorkingDirectory=/home/root/Robotd
ExecStart=/etc/init.d/robot start
ExecReload=/etc/init.d/robot restart
ExecStop=/etc/init.d/robot stop
[Install]
WantedBy=multi-user.target

View File

@@ -3,6 +3,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <signal.h> #include <signal.h>
#include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include <errno.h> #include <errno.h>
#include <syslog.h> #include <syslog.h>
@@ -50,6 +51,18 @@ int main(int argc, char ** argv) {
return EXIT_FAILURE; return EXIT_FAILURE;
} }
// Create PID file
FILE * pid = fopen("/var/run/robot.pid", "w");
if (pid == NULL) {
perror("FILE * pid = fopen(\"/var/run/robot.pid\", \"w\")");
syslog(LOG_DAEMON | LOG_ERR, "Failed to create PID file.");
return EXIT_FAILURE;
}
fprintf(pid, "%d", getpid());
fclose(pid);
// Open a syslog connection // Open a syslog connection
openlog(argv[0], LOG_NDELAY | LOG_PID, LOG_DAEMON); openlog(argv[0], LOG_NDELAY | LOG_PID, LOG_DAEMON);
syslog(LOG_DAEMON | LOG_NOTICE, "Started robot daemon."); syslog(LOG_DAEMON | LOG_NOTICE, "Started robot daemon.");