Я действую согласно инструкции https://www.linode.com/docs/guides/start-service-at-boot/.
Что делаю: создал в корне домашней директории два файла test_service.sh и myservice.service с таким содержанием:
test_service.sh:
DATE=`date '+%Y-%m-%d %H:%M:%S'`
echo "Example service started at ${DATE}" | systemd-cat -p info
while :
do
echo "Looping...";
sleep 30;
done
myservice.service:
[Unit]
Description=My Shell Script (VentoyWeb 1.0.71)
After=network.target
[Service]
cd /home/dragonserw/Public/ventoy-1.0.71/
ExecStart=/home/dragonserw/Public/ventoy-1.0.71/VentoyWeb.sh -H 192.168.88.48
[Install]
WantedBy=multi-user.target
Затем я в домашней директории применяю две вот такие команды:
sudo cp test_service.sh /usr/bin/test_service.sh && sudo chmod +x /usr/bin/test_service.sh
sudo cp myservice.service /etc/systemd/system/myservice.service && sudo chmod 644 /etc/systemd/system/myservice.service && sudo systemctl enable myservice
После этого перезагружаюсь, и статус у сервиса такой:
dragonserw@raspberrypi:~ $ sudo systemctl status myservice
● myservice.service - My Shell Script (VentoyWeb 1.0.71)
Loaded: loaded (/etc/systemd/system/myservice.service; enabled; vendor preset: enabled)
Active: inactive (dead) since Sun 2022-10-23 21:17:03 MSK; 55s ago
Process: 564 ExecStart=/home/dragonserw/Public/ventoy-1.0.71/VentoyWeb.sh -H 192.168.88.48 (code=exited, status=0/SUCCESS)
Main PID: 564 (code=exited, status=0/SUCCESS)
CPU: 163ms
Oct 23 21:17:02 raspberrypi systemd[1]: Started My Shell Script (VentoyWeb 1.0.71).
Oct 23 21:17:02 raspberrypi VentoyWeb.sh[606]: Ventoy failed to start http server, check log.txt for detail
Oct 23 21:17:03 raspberrypi VentoyWeb.sh[564]: ===============================================================
Oct 23 21:17:03 raspberrypi VentoyWeb.sh[564]: Ventoy Server 1.0.71 is running ...
Oct 23 21:17:03 raspberrypi VentoyWeb.sh[564]: Please open your browser and visit http://192.168.88.48:24680
Oct 23 21:17:03 raspberrypi VentoyWeb.sh[564]: ===============================================================
Oct 23 21:17:03 raspberrypi VentoyWeb.sh[564]: ################## Press Ctrl + C to exit #####################
Oct 23 21:17:03 raspberrypi systemd[1]: myservice.service: Succeeded.
dragonserw@raspberrypi:~ $
Привожу содержимое лог-файла:
[2022/09/23 21:17:02] ===============================================
[2022/09/23 21:17:02] ===== Ventoy2Disk 1.0.71 192.168.88.48:24680 =====
[2022/09/23 21:17:02] ===============================================
[2022/09/23 21:17:02] ventoy_disk_enumerate_all
[2022/09/23 21:17:02] get disk info mmcblk0
[2022/09/23 21:17:02] get disk size from sysfs for mmcblk0
[2022/09/23 21:17:02] /sys/block/mmcblk0/device/vendor not exist
[2022/09/23 21:17:02] /sys/block/mmcblk0/device/model not exist
[2022/09/23 21:17:02] ventoy_get_vtoy_data /dev/mmcblk0
[2022/09/23 21:17:02] Not valid ventoy partition layout [8192 524288] [532480 243765248]
[2022/09/23 21:17:02] disk:</dev/mmcblk0 179:0> model:< (sd/mmc)> size:125080436736 (128 GB)
[2022/09/23 21:17:02] /dev/mmcblk0 NO Ventoy detected
[2022/09/23 21:17:02] ============= DISK DUMP ============
[2022/09/23 21:17:02] /dev/mmcblk0 [128 GB] (sd/mmc) Ventoy: NA
[1666549022] [error] [client ] cannot bind to 192.168.88.48:24680: 99 (Cannot assign requested address)
Что удивительно, команда
sudo systemctl restart myservice && sudo systemctl status myservice
оживляет сервис!
Да, совсем забыл uname -a
показать:
dragonserw@raspberrypi:~ $ uname -a
Linux raspberrypi 5.15.61-v8+ #1579 SMP PREEMPT Fri Aug 26 11:16:44 BST 2022 aarch64 GNU/Linux
dragonserw@raspberrypi:~ $