0

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?

suchislife
  • 4,251
  • 10
  • 47
  • 78

2 Answers2

1

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

schuelermine
  • 1,958
  • 2
  • 17
  • 31
suchislife
  • 4,251
  • 10
  • 47
  • 78
  • Deno won't run as a sudo user unless you have Deno installed for the superuser. Iirc Deno is a per-user install (~/.deno/) – Saddy Jun 25 '20 at 19:56
  • Ok. So the correct way is to install Deno as root and then run it as root? – suchislife Jun 26 '20 at 14:44
  • If you need it as root I presume; I run my stuff without root – Saddy Jun 26 '20 at 16:23
  • Ok. From scratch, when I install deno from a sudo user account and attempt to run a script with read and net turned on, it still gives me permission errors. Why? – suchislife Jun 26 '20 at 16:33
  • Argh! They don't exist anymore... So after installation, I don't need to set any file or folder permissions, correct? I guess the simplicity of deno blows my mind. – suchislife Jun 26 '20 at 16:41
  • 1
    Lol yeah Deno is awesome; since you are running as super user you shouldnt really need to edit any folder permissions unless it isn’t working – Saddy Jun 26 '20 at 16:42
0

For a more up to date answer, have a look at https://deno.land/x/service

A combined cli tool or library which helps you install any script as a service with systemd, sysvinit, docker-init and launchd. It can also install a user mode service on systemd without the need for root access.

For a more versatile option, check out https://deno.land/x/pup , which is a fully featured process manager for Deno.

Hexagon
  • 1
  • 1