Der Systemctl-Daemon funktioniert nur, wenn „verbose“ aktiviert ist.

Der Systemctl-Daemon funktioniert nur, wenn „verbose“ aktiviert ist.

Ich habe einen Daemon in init.d, der bis auf den Namen und die Beschreibung genau die gleiche Struktur hat wie das Standard-UbuntuSkelettdatei. Wenn ich versuche, den besagten Daemon auszuführen mit

sudo /etc/init.d/mydaemon start

Ich erhalte die Fehlermeldung, dass der Start des Daemons fehlgeschlagen ist, mit der Meldung

Control process exited, code=exited, status=1/FAILURE

was nicht sehr hilfreich ist, da Code 1 meines Wissens nach nichts wirklich bedeutet. Während ich das debuggte, habe ich mich irgendwann dazu entschlossen, die Variable „verbose“ in /lib/init/vars.sh von „no“ auf „yes“ zu ändern, nur um eine Ausgabe zu provozieren, und als ich das tat, lief der Daemon einwandfrei. Wenn ich „verbose“ jedoch wieder auf „no“ ändere, erhalte ich dieselben Fehler wie zuvor. Ist jemandem von Ihnen schon einmal so etwas begegnet und wissen Sie, was die Ursache dafür sein könnte?

Außerdem ist der Daemon-Code in C++ und sieht wie folgt aus (obwohl ich nicht glaube, dass er hierfür unbedingt relevant ist):

#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <errno.h>
#include <unistd.h>
#include <syslog.h>
#include <string.h>
#include <string>

using namespace std;

#define DAEMON_NAME "mydaemon"

void process(){

    syslog (LOG_NOTICE, "Writing to log from Daemon");
}

int main(int argc, char *argv[]) {

    //Set our Logging Mask and open the Log
    setlogmask(LOG_UPTO(LOG_NOTICE));
    openlog(DAEMON_NAME, LOG_CONS | LOG_NDELAY | LOG_PERROR | LOG_PID, LOG_USER);

    pid_t pid, sid;

   //Fork the Parent Process
    pid = fork();

    if (pid < 0) {
      exit(EXIT_FAILURE);
    }

    //We got a good pid, Close the Parent Process
    if (pid > 0) { exit(EXIT_SUCCESS); }

    //Change File Mask
    umask(0);

    //Create a new Signature Id for our child
    sid = setsid();
    if (sid < 0) {
      exit(EXIT_FAILURE); }

    // Change to root
    chdir("/");

    //Close File Descriptors
    int x;
    for (x = sysconf(_SC_OPEN_MAX); x>=0; x--)
    {
        close (x);
    }

    //----------------
    //Main Process
    //----------------
    while(true){
        process();    //Run our Process
        sleep(30); //Sleep for 30 seconds
        break;    
    }

    //Close the log
    closelog ();
    return 0;
}

verwandte Informationen