0

I am trying to setup a node.js based telegram bot to run as a system service but get Access Denied error every time I try to execute it.

Here is the .service file I have created.

[Unit]
Description=Sonarr Telegram Bot

[Service]
ExecStart=/usr/local/bin/node /home/pi/telegram-sonarr-bot/sonarr.js
Restart=always
User=pi
# Note RHEL/Fedora uses 'nobody', Debian/Ubuntu uses 'nogroup'
Group=nobody
Environment=PATH=/usr/bin:/usr/local/bin
Environment=NODE_ENV=production
WorkingDirectory=/home/pi/telegram-sonarr-bot/

[Install]
WantedBy=multi-user.target

I have tried to run it as user root as well but this also doesn't work. If I execute the node.js file within terminal it works fine fyi.

Edit: Added /var/log/auth.log file

Apr 17 00:11:16 raspberrypi sudo:       pi : TTY=pts/0 ; PWD=/var/log ; USER=root ; COMMAND=/usr/bin/nano /etc/systemd/system/sonarrbot.service
Apr 17 00:11:16 raspberrypi sudo: pam_unix(sudo:session): session opened for user root by pi(uid=0)
Apr 17 00:11:21 raspberrypi sudo: pam_unix(sudo:session): session closed for user root
Apr 17 00:11:23 raspberrypi dbus[339]: [system] Rejected send message, 2 matched rules; type="method_call", sender=":1.10" (uid=1000 pid=9757 comm="systemctl start sonarrbot ") interface="org.freedesktop.systemd1.Manager" member="StartUnit" error name="(unset)" requested_reply="0" destination="org.freedesktop.systemd1" (uid=0 pid=1 comm="/sbin/init ")
Apr 17 00:11:25 raspberrypi sudo:       pi : TTY=pts/0 ; PWD=/var/log ; USER=root ; COMMAND=/usr/bin/nano /etc/systemd/system/sonarrbot.service
Apr 17 00:11:25 raspberrypi sudo: pam_unix(sudo:session): session opened for user root by pi(uid=0)
Apr 17 00:11:29 raspberrypi sudo: pam_unix(sudo:session): session closed for user root

Second update:

pi@raspberrypi:~ $ systemctl status sonarrbot.service
    ● sonarrbot.service - Sonarr Telegram Bot
       Loaded: loaded (/etc/systemd/system/sonarrbot.service; disabled)
       Active: failed (Result: start-limit) since Tue 2018-04-17 00:59:39 UTC; 22h ago
      Process: 9804 ExecStart=/usr/local/bin/node /home/pi/telegram-sonarr-bot/sonarr.js (code=exited, status=216/GROUP)
     Main PID: 9804 (code=exited, status=216/GROUP)


pi@raspberrypi:~ $ journalctl -b
No journal files were found.
8
  • How do you run /etc/systemd/system/sonarrbot.service as root? What is the output from systemctl status sonarrbot.service? Are there some hints in journalctl -b? – Ingo Apr 17 '18 at 16:03
  • Updated my original post – Imran Apr 17 '18 at 23:16
  • Running service as root doesn't work for me, e.g. sudo cron.service gives me sudo: cron.service: command not found. Your service is simply disabled. Enable it with sudo systemctl enable sonarrbot.service and start it with sudo systemctl start sonarrbot.service. What's the status then? What gives you sudo journalctl -b? For better troubleshooting on systemd you should enable persistent logging in journald. Look at zcat /usr/share/doc/systemd/README.Debian.gz | less. – Ingo Apr 18 '18 at 0:09
  • When running systemctl enable sonarr.service I still get the same error "Failed to execute operation: Access denied" – Imran Apr 18 '18 at 0:11
  • What operating system you are running? I assume it is Raspbian. – Ingo Apr 18 '18 at 0:20
0

Your question is a variation of the FAQ Why do things work differently under systemd?.

Relative binary work in the shell, but as documented in man systemd.service, the first argument to ExecStart= must be an absolute path to a binary.

3
  • I have included the absolute path (please see updated post), but I still receive the same error. – Imran Apr 17 '18 at 0:07
  • When testing, use sudo with systemctl. Also, make sure your use systemctl enable your-app-name to make it start at boot. – Mark Stosberg Apr 17 '18 at 0:49
  • Running with sudo doesn’t return any errors, but the application definitely isn’t running. – Imran Apr 17 '18 at 1:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.