
他のアプリケーションを起動するためのLinuxサービスを作成したいと思います。単純化のためにFirefoxだとしましょう。
システムメッセージ:
➜ ~ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.4 LTS
Release: 18.04
Codename: bionic
Firefoxを実行するためのbashスクリプトを作成しました。
#!/bin/bash
currentTime=$(date +"%I:%M:%S")
echo "My Test: Starting Firefox @ $currentTime"
firefox &
systemd用の.serviceファイルを作成しました。
[Unit]
Description=My Test Service
After=network.target
[Service]
Type=simple
User=myuser
SyslogIdentifier=mytest
ExecStart=/home/myuser/test.sh
[Install]
WantedBy=multi-user.target
.serviceファイルを挿入し、/etc/systemd/system
次を使用して有効/開始しました。
sudo systemctl daemon-reload
sudo systemctl enable mytest.service
sudo systemctl start mytest
これはの出力です。sudo systemctl status mytest
● mytest.service - My Test Service
Loaded: loaded (/etc/systemd/system/mytest.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Tue 2020-02-11 16:11:59 CST; 6s ago
Process: 4131 ExecStart=/home/myuser/linux-scripts/test.sh (code=exited, status=0/SUCCESS)
Main PID: 4131 (code=exited, status=0/SUCCESS)
Feb 11 16:11:59 NUC5i3RYH systemd[1]: Started My Test Service.
Feb 11 16:11:59 NUC5i3RYH mytest[4131]: My Test: Starting firefox @ 04:11:59
スクリプトが実行されているように見えますが、Firefoxは起動しません。 bashスクリプトを直接実行すると、Firefoxがすぐに開きます。私がここで何を間違っているのかを見ることができる人はいますか?私はLinuxとそのユーティリティに初めて触れたので、助けてくれてありがとう。