mirror of
https://github.com/miky-kr5/Robotd.git
synced 2023-01-29 18:47:06 +00:00
Now starts properly at boot with the Galileo's systemd.
This commit is contained in:
12
robot.service
Normal file
12
robot.service
Normal 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
|
13
robotd.c
13
robotd.c
@@ -3,6 +3,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <syslog.h>
|
||||
@@ -50,6 +51,18 @@ int main(int argc, char ** argv) {
|
||||
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
|
||||
openlog(argv[0], LOG_NDELAY | LOG_PID, LOG_DAEMON);
|
||||
syslog(LOG_DAEMON | LOG_NOTICE, "Started robot daemon.");
|
||||
|
Reference in New Issue
Block a user