How to create a simple service which run before gdm3

Below is my configuration, but it has no effect after restarting the computer. I have tried these commands and still have no effect.

sudo systemctl daemon-reload
sudo systemctl enable hello.service
#sudo vim /lib/systemd/system/hello.service
[Unit]
Description=Hello Manager
Before=gdm.service

[Service]
Type=simple
ExecStart=/usr/local/bin/hello-manager --enable-lane true > /tmp/hello.log 2>&1
Restart=always
RestartSec=60s

[Install]
WantedBy=multi-user.target

You’re doing shell redirections in the ExecStart= line, but ExecStart= isn’t a shell and doesn’t do shell redirections.

You’ll either need to wrap your command in sh -c "", or once systemd v258 is out you can prefix the command line with the | character to tell systemd to wrap it in a shell for you.

Documentation

Thanks, this worked for me

I forgot to mention, but systemd also natively has various output redirection settings.

See StandardOutput= and StandardError=

So rather than wrapping everything in a shell and using shell redirection, you can do:

ExecStart=/usr/local/bin/hello-manager --enable-lane true
StandardOutput=truncate:/tmp/hello.log
StandardError=inherit

Which is a bit more self-descriptive than the redirections