Скрипт systemd для уведомления-отправки завершается с ошибкой «Соединение закрыто»

Я пытаюсь запустить системный таймер. Я публикую все соответствующие файлы и ошибку ниже. Я разместил файл nodejs, но я попытался использовать простой сценарий оболочки, а также объяснил в разделе «Правка».

/usr/bin/systemd/system/notification.service

      [Unit]
Description=Show notification
After=systemd-user-sessions.service,systemd-journald.service
Wants=notification.timer

[Service]
Type=simple
ExecStart=/usr/bin/node /home/rounak/base/scripts/get-combined-notification.js
Environment="DISPLAY=:0" "XAUTHORITY=/home/rounak/.Xauthority" "DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus"

[Install]
WantedBy=multi-user.target

/usr/bin/systemd/system/notification.timer

      [Unit]
Description=Show notification

[Timer]
OnUnitActiveSec=1m

[Install]
WantedBy=timers.target

get-combined-notification.js

      const util = require("util");
const stdExec = require("child_process").exec;
const exec = util.promisify(stdExec);

const appNameForDunst = "CombinedNotification";
const executeScript = async (shellCommand) => {
  return await exec(shellCommand);
};
const notifySendCommand = async (text) =>
  await executeScript(
    `notify-send -t 5000 -a ${appNameForDunst} " " ${JSON.stringify(
      text
    )}`
  );

const commands = [
  {
    title: "Battery",
    command: "acpi -b",
    process: 'return output.split(",")[1]',
  },
  {
    title: "Network",
    command: "nmcli -t -f NAME connection show --active",
    process: "return output",
  },

  {
    title: "Workspace",
    command: "xprop -root _NET_CURRENT_DESKTOP",
    process:
      'return ["view", "dev", "servers", "config", "notes", "av"][output.trim().substr(-1)]',
  },
  {
    title: "Date",
    command: "date '+ %a %d %b %y%nTime:   %I:%M'",
    process: "return output",
  },
  {
    title: "Window Count",
    command: "xprop -root _NET_CLIENT_LIST_STACKING",
    process: 'return output.split("#").join("").split(",").length',
  },
];

let final = "";

const handler = async (command, index) => {
  const result = await executeScript(command.command);
  const processOutput = new Function("output", command.process);
  final = final + `${command.title}: ${processOutput(result.stdout)}\n`;
};

const main = async () => {
  await Promise.allSettled(commands.map(handler));
  notifySendCommand(final);
};
main()

журналctl-u уведомление

      Jul 15 18:31:03 rounak node[3215]: Node.js v18.3.0
Jul 15 18:31:03 rounak systemd[1]: notification.service: Main process exited, code=exited, status=1/FAI>
Jul 15 18:31:03 rounak systemd[1]: notification.service: Failed with result 'exit-code'.
Jul 15 18:33:03 rounak systemd[1]: Started Show notification.
Jul 15 18:33:03 rounak node[4229]: node:internal/errors:845
Jul 15 18:33:03 rounak node[4229]:   const err = new Error(message);
Jul 15 18:33:03 rounak node[4229]:               ^
Jul 15 18:33:03 rounak node[4229]: Error: Command failed: notify-send -t 5000 -a CombinedNotification ">
Jul 15 18:33:03 rounak node[4229]: The connection is closed
Jul 15 18:33:03 rounak node[4229]:     at ChildProcess.exithandler (node:child_process:387:12)
Jul 15 18:33:03 rounak node[4229]:     at ChildProcess.emit (node:events:527:28)
Jul 15 18:33:03 rounak node[4229]:     at maybeClose (node:internal/child_process:1090:16)
Jul 15 18:33:03 rounak node[4229]:     at ChildProcess._handle.onexit (node:internal/child_process:302:>
Jul 15 18:33:03 rounak node[4229]:   code: 1,
Jul 15 18:33:03 rounak node[4229]:   killed: false,
Jul 15 18:33:03 rounak node[4229]:   signal: null,
Jul 15 18:33:03 rounak node[4229]:   cmd: 'notify-send -t 5000 -a CombinedNotification " " "Date:  Fri >
Jul 15 18:33:03 rounak node[4229]:   stdout: '',
Jul 15 18:33:03 rounak node[4229]:   stderr: 'The connection is closed\n'
Jul 15 18:33:03 rounak node[4229]: }

Редактировать:

Чтобы исключить nodejs как виновника, я использовал сценарий оболочки с одной строкойnotify-send "some" "some" вместо скрипта nodejs. Я получаю ту же ошибку в журнале:sh[2607]: The connection is closed

0 ответов

Другие вопросы по тегам