systemd 服务未启用

systemd 服务未启用

我需要您的帮助来启用一项服务,该服务可以在启动时启动并执行我编写的程序。该程序是一个命令行程序,通过标志获取参数,因此在/ETC服务conf文件看起来像这样

  GNU nano 4.8                                                                                      ip-tracker.conf                                                                                                
SERVER=-server=smtp.gmail.com
PORT=-port=587
USER=-user=supdosedlyMyUsername
PASS=-password=supdosedlyMyPassword
[email protected]
[email protected]

并在/lib/systemd/myProgram.service看起来像这样

[Unit]
Description=Some description for the service

[Service]
Type=simple
#Restart=always
#RestartSec=5s
EnvironmentFile=/etc/mySuperProgram.conf

# HERE I GET MY VALUES FROM conf file FOR THE PROGRAM FLAGS 
ExecStart=/usr/bin/ip-tracker $SERVER $PORT $USER $PASS $FROM $TO

[Install]
WantedBy=multi-user.target

如果我在运行之前尝试启用该服务,则问题如下

sudo systemctl start myService

我在控制台中没有收到错误,如果我运行

sudo systemctl status myService

我明白了

ip-tracker.service - tracking your ip after system reboot
     Loaded: loaded (/lib/systemd/system/ip-tracker.service; enabled; vendor preset: enabled)
     Active: failed (Result: exit-code) since Fri 2022-04-22 18:14:46 EEST; 39min ago
   Main PID: 925 (code=exited, status=2)

apr 22 18:14:46 dev ip-tracker[925]: [signal SIGSEGV: segmentation violation code=0x1 addr=0x40 pc=0x642f9f]
apr 22 18:14:46 dev ip-tracker[925]: goroutine 19 [running]:
apr 22 18:14:46 dev ip-tracker[925]: main.getIp(0xc00013e060)
apr 22 18:14:46 dev ip-tracker[925]:         /home/adi/Projects/ip_finder/main.go:27 +0xff
apr 22 18:14:46 dev ip-tracker[925]: main.main.func1()
apr 22 18:14:46 dev ip-tracker[925]:         /home/adi/Projects/ip_finder/main.go:112 +0x26
apr 22 18:14:46 dev ip-tracker[925]: created by main.main
apr 22 18:14:46 dev ip-tracker[925]:         /home/adi/Projects/ip_finder/main.go:111 +0xb1
apr 22 18:14:46 dev systemd[1]: ip-tracker.service: Main process exited, code=exited, status=2/INVALIDARGUMENT
apr 22 18:14:46 dev systemd[1]: ip-tracker.service: Failed with result 'exit-code'.

如果我跑

sudo systemctl start myService

服务启动并执行应该执行的操作...然后,如果我运行命令来启用它,我不会收到错误消息,但如果我检查状态,它会显示该服务未处于活动状态,如下所示:

ip-tracker.service - tracking your ip after system reboot
     Loaded: loaded (/lib/systemd/system/ip-tracker.service; enabled; vendor preset: enabled)
     Active: inactive (dead) since Fri 2022-04-22 18:54:40 EEST; 10min ago
    Process: 13189 ExecStart=/usr/bin/ip-tracker $SERVER $PORT $USER $PASS $FROM $TO (code=exited, status=0/SUCCESS)
   Main PID: 13189 (code=exited, status=0/SUCCESS)

apr 22 18:54:36 dev systemd[1]: Started tracking your ip after system reboot.
apr 22 18:54:37 dev ip-tracker[13189]: ISV  true
apr 22 18:54:40 dev systemd[1]: ip-tracker.service: Succeeded

如何启用我的服务并保持这种状态?

谢谢

相关内容