Search code examples
ubuntusystemddeno

Deno as Linux systemd service. How?


For reasons I don't understand, Deno is not a systemd service by default. It has an auto install script that drops the deno executable file in your /home folder. When you deno run a Typescript file using this executable, it loads up your script and them you can say goodbye to the console being used for anything else.

How do I add deno as a systemd service to Ubuntu?


Solution

  • YES! I figured it out!

    Although, it would be really nice if you could help me figure out why deno only executes if you are logged in as a root user. I cannot get deno to run with sudo user.

    Steps:

    1. Install deno using the .sh script they provide at deno.land

    2. Copy your httpServer.ts to your /home directory.

    3. Tell systemd about the application by creating the service file we will be using.

    4. sudo touch /etc/systemd/system/deno.service

    5. Edit this recently created empty file using the template below.

    [Unit]
    Description=Deno 1.1.1 service
    Documentation=http://deno.land
    Wants=network-online.target
    After=network-online.target
    [Service]
    Type=simple
    User=user1
    WorkingDirectory=/home
    ExecStart=/home/user1/.deno/bin/deno run --allow-net --allow-read httpServer.ts
    Restart=on-failure
    
    [Install]
    WantedBy=multi-user.target
    
    1. Then enable and start it.

    sudo systemctl enable deno

    sudo systemctl start deno

    1. Check status of deno service.

    sudo systemctl status deno

    Screenshot

    enter image description here