Keep Directus running in the background on Linux

So you've installed Directus on your server or local computer but it keeps crashing when you logout or close your terminal. This article shows you how to set up Directus as a service.

Keep Directus running in the background on Linux

So you have installed Directus on your server or local computer and run the npx command, what comes next? When you close your terminal session, Directus closes as well. What you need to do is create a background service.

Step 1: Create Service

Create a new service using the following command:

vim /etc/systemd/system/directus.service

Paste the following code into the editor and replace User and the Working Directory

[Unit]
Description=Directus 9
After=network.target
StartLimitIntervalSec=0

[Service]
WorkingDirectory=/path/to/directus/project
Type=simple
Restart=always
RestartSec=1
User=webuser
ExecStart=npx directus start

[Install]
WantedBy=multi-user.target

Save the changes and close. For those unfamiliar with vim, make sure you are out of the editing mode by pressing ESC, then type :wq and press ENTER.

Step 2: Start the new service

Type the following command to start the new service.

systemctl start directus

Step 3: Add the service to system startup

Type the following command and your service will start on system boot.

systemctl enable directus

It's now safe to close your terminal. You can confirm if Directus is running by using this command:

systemctl status directus

This will output the most recent logs.

Now that the background service is running, you can continue to access Directus after you close your session.

What's Next

You'll need a domain name or subdomain for accessing Directus. Once you have one, I recommend using Nginx to host your new system. See Set up Directus in Nginx.

By continuing to use our website, you consent to use essential cookies. We also use optional tracking cookies which help us gather statistics to improve our services. Do you consent to these cookies?

I Consent Do not track