Announcement

Collapse
No announcement yet.

user systemctl service is suddenly failing

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    [RESOLVED] user systemctl service is suddenly failing

    I'm not entirely sure what's changed.
    I have a custom user service, dropped into `etc/systemd/user` called luna.service. It's a Discord bot that runs on a plex server, ubuntu 22.04

    Code:
    [Unit]
    Description=Luna, my Discord support bot.
    Wants=network-online.target
    After=network-online.target
    
    [Service]
    WorkingDirectory=/home/plex/bots/Luna
    ExecStart=/home/plex/bots/bot.sh
    
    [Install]
    WantedBy=default.target
    
    ​
    Until tonight, the service launched on every startup, and worked perfectly fine. Tonight, I restarted the service, and got the following on a status check.

    Code:
    luna.service - Luna, my Discord support bot.
         Loaded: loaded (/etc/xdg/systemd/user/luna.service; enabled; vendor preset: enabled)
         Active: failed (Result: exit-code) since Thu 2022-12-22 04:09:40 EST; 4s ago
        Process: 5560 ExecStart=/home/plex/bots/bot.sh (code=exited, status=127)
       Main PID: 5560 (code=exited, status=127)
            CPU: 5ms
    
    Dec 22 04:09:40 Plex systemd[1549]: Started Luna, my Discord support bot..
    Dec 22 04:09:40 Plex systemd[1549]: luna.service: Main process exited, code=exited, status=127/n/a
    Dec 22 04:09:40 Plex systemd[1549]: luna.service: Failed with result 'exit-code'.
    
    ​
    If I navigate to the working directory listed in the service, and run bot.sh manually from any terminal, it works fine, but the point of the service was to make it so I didn't need to manually run it, or keep a terminal open.

    Any help would be greatly appreciated.

    #2
    Exit status 127 is typically a "command not found" error (trying to run something that is not found, or is not accessible or executable for the UID trying to run it).

    It's hard to pinpoint the cause with the information available, could be a PATH or permissions issue during startup or something in the script itself, although it is a bit strange if it works if you start it manually (are you starting it by running the script directly, or starting the systemd service, when it works?...one thing I noticed is that the working directory and exec paths are different in your service file, is that intentional?)

    You can also check if there are anyhting in the systemd logs "journalctl --user --unit luna.service"

    Comment


      #3
      To answer the questions in the order they make sense for my explanation...

      Yes it's intentional, because at one point, there were multiple bots running. Successful runs are either the script, or the launch command inside the script, from the working directory. if I run
      Code:
      systemctl --user start luna.service
      , now I get the message that the service is inactive (dead), exit code 0, right when the service fails to run.

      I added some echo lines to the script, echoing out the working dir, and hints about the various parts of the script. When run as a service, the script has the correct working directory, and makes it to EOL, but the command doesn't run.

      I am not sure if this makes a difference, but I recently installed NVM (Nodejs version manager), changing the nodejs version from the manually installed "system" version (12.22.2) to the same version installed by NVM.

      stopping and starting the service at the time of the change seemed to work fine, but not now.

      Comment


        #4
        Originally posted by jasoncollege24 View Post
        I am not sure if this makes a difference, but I recently installed NVM (Nodejs version manager), changing the nodejs version from the manually installed "system" version (12.22.2) to the same version installed by NVM.
        I'd guestimate this could likely have something to do with it (provided the script is meant to start a node.js bot). I'm not that familiar with node.js or NVM, but was able to find a few similar (if somewhat old) issues you could check out for tips (or search for more, since it could well be a node.js/NVM issue):
        https://unix.stackexchange.com/quest...xit-status-127
        https://stackoverflow.com/questions/...error-on-start


        Comment


          #5
          Thank you! in this case, the service itself was fine. Adding the full path of node to the launch command in bot.sh resolved the issue. Just means I will have to update the path, if I change which version I'm using.

          For anyone else, it was the NVM related answer in the very first link that pointed me in the right direction.

          Comment

          Working...
          X