缺少“=”。在 Debian 服务中

Missing '='. in Debian service

我在 /etc/systemd/system/webapp.service

中创建了这个服务

Distributor ID: Debian
Description:    Debian GNU/Linux 10 (buster)
Release:    10

这是内容:

[Unit]
Description=webapp daemon
After=network.target

[Service]
Type=notify
ExecStart=/usr/local/bin/start-webapp.sh
ExecStop=/usr/local/bin/stop-webapp.sh
ExecReload=/usr/local/bin/reload-webapp.sh
StandardOutput=null

[Install]
WantedBy=multi-user.target
Alias=webapp.service

我尝试使用以下方式启动服务:

sudo systemctl start webapp.service

但是当我这样做时

sudo systemctl status webapp.service 

我收到这个错误:

● webapp.service - webapp daemon
   Loaded: loaded (/etc/systemd/system/webapp.service; disabled; vendor preset: enabled)
   Active: inactive (dead)

Jun 01 11:31:48 localhost systemd[1]: /etc/systemd/system/webapp.service:8: Missing '='.
Jun 01 11:31:52 localhost systemd[1]: /etc/systemd/system/webapp.service:8: Missing '='.
Jun 01 11:35:21 localhost systemd[1]: /etc/systemd/system/webapp.service:8: Missing '='.
Jun 01 11:35:31 localhost systemd[1]: /etc/systemd/system/webapp.service:8: Missing '='.

   admin@localhost:/etc/systemd/system$ cat -vetn webapp.service 
         1  [Unit]$
         2  Description=webapp daemon$
         3  [Service]$
         4  Type=simple$
         5  ExecStart=/usr/local/bin/start-webapp.sh$
         6  ExecStop=/usr/local/bin/stop-webapp.sh$
         7  ExecReload=/usr/local/bin/reload-webapp.sh$
         8  [Install]$
         9  WantedBy=multi-user.target$

你的配置内容好像没什么问题,所以我把它复制到我的debian服务器上试试运行,果然没问题。

但是奇怪的是cat -vetn webapp.service的stdout并不是你原来配置的内容,所以你介意把原来的配置去掉再做一次吗?

参考:https://wiki.debian.org/systemd/Services

  1. 重做:

    mv webapp.service /tmp/webapp.service vi webapp.service # check characters

  2. 在创建或修改任何单元文件后,我们必须告诉 systemd 我们希望它寻找新的东西:

    systemctl daemon-reload

  3. 然后,告诉systemd启用它,这样它就会在我们每次启动时启动:

    systemctl enable myservice.service

  4. 终于开始了:

    systemctl start myservice.service