LINUX.ORG.RU
решено ФорумAdmin

Не запускается сервер с помощью скрипта автозагрузки

 , ,


1

1

Здравствуйте, уважаемые профессионалы сетевого администрирования! У меня есть такой скрипт /opt/vpnserver.sh.:

#!/bin/sh
# chkconfig: 2345 99 01
# description: SoftEther VPN Server
DAEMON=/usr/src/vpnserver/vpnserver
LOCK=/var/lock/subsys/vpnserver
TAP_ADDR=192.168.10.1

test -x $DAEMON || exit 0
case "$1" in
start)
$DAEMON start
touch $LOCK
sleep 1
/sbin/ifconfig tap_tap_virtual $TAP_ADDR
systemctl start dhcpd
;;
stop)
$DAEMON stop
rm $LOCK
;;
restart)
$DAEMON stop
sleep 3
$DAEMON start
sleep 1
/sbin/ifconfig tap_tap_virtual $TAP_ADDR
systemctl start dhcpd
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit 0

После перезагрузки не срабатывает автозагрузка vpn сервера :P

● vpnserver.service - vpnserver daemon
     Loaded: loaded (/etc/systemd/system/vpnserver.service; enabled; vendor preset: enabled)
     Active: activating (auto-restart) since Mon 2024-03-11 10:37:01 GMT; 2s ago
    Process: 878 ExecStart=/opt/vpnserver.sh start (code=exited, status=0/SUCCESS)
    Process: 882 ExecStop=/opt/vpnserver.sh stop (code=exited, status=0/SUCCESS)
Всё по инструкции делал, что не так?

PS. Ubuntu 20.



Последнее исправление: Kisliy (всего исправлений: 1)
Ответ на: комментарий от eternal_sorrow

Пожалуйста, лежит здесь /etc/systemd/system/vpnserver.service:

Description = vpnserver daemon

[Service]
ExecStart = /opt/vpnserver.sh start
ExecStop = /opt/vpnserver.sh stop
ExecReload = /opt/vpnserver.sh restart
Restart = always
RestartSec=15
Type = forking

[Install]
WantedBy = multi-user.target
Kisliy
() автор топика
Ответ на: комментарий от eternal_sorrow

Чёт не прёт :(

● vpnserver.service - vpnserver daemon
     Loaded: loaded (/etc/systemd/system/vpnserver.service; enabled; vendor preset: enabled)
     Active: activating (auto-restart) since Mon 2024-03-11 20:12:33 GMT; 13s ago
    Process: 1058 ExecStart=/opt/vpnserver.sh start (code=exited, status=0/SUCCESS)
    Process: 1062 ExecStop=/opt/vpnserver.sh stop (code=exited, status=0/SUCCESS)
   Main PID: 1058 (code=exited, status=0/SUCCESS)
Kisliy
() автор топика
Ответ на: комментарий от eternal_sorrow

Хорошо, а как? Может я просто к началу вернусь? Если вернуть Type = forking и убрать RestartSec=15, выдаёт вот что:

● vpnserver.service - vpnserver daemon
     Loaded: loaded (/etc/systemd/system/vpnserver.service; enabled; vendor preset: enabled)
     Active: failed (Result: start-limit-hit) since Mon 2024-03-11 20:51:06 GMT; 9s ago
    Process: 3353 ExecStart=/opt/vpnserver.sh start (code=exited, status=0/SUCCESS)
    Process: 3354 ExecStop=/opt/vpnserver.sh stop (code=exited, status=0/SUCCESS)

Mar 11 20:51:06 racknerd-d194e1 systemd[1]: vpnserver.service: Scheduled restart job, restart counter is at 169.
Mar 11 20:51:06 racknerd-d194e1 systemd[1]: Stopped vpnserver daemon.
Mar 11 20:51:06 racknerd-d194e1 systemd[1]: vpnserver.service: Start request repeated too quickly.
Mar 11 20:51:06 racknerd-d194e1 systemd[1]: vpnserver.service: Failed with result 'start-limit-hit'.
Mar 11 20:51:06 racknerd-d194e1 systemd[1]: Failed to start vpnserver daemon.
Kisliy
() автор топика
Ответ на: комментарий от eternal_sorrow

Часть журнала:

-- Logs begin at Mon 2024-03-04 04:14:47 GMT, end at Mon 2024-03-11 21:08:46 GMT. --
Mar 05 23:27:47 racknerd-d194e1 systemd[1]: Starting vpnserver daemon...
Mar 05 23:27:47 racknerd-d194e1 systemd[325]: vpnserver.service: Failed to execute command: No such file or directory
Mar 05 23:27:47 racknerd-d194e1 systemd[325]: vpnserver.service: Failed at step EXEC spawning /opt/vpnserver.sh: No such file or directory
Mar 05 23:27:47 racknerd-d194e1 systemd[1]: vpnserver.service: Control process exited, code=exited, status=203/EXEC
Mar 05 23:27:47 racknerd-d194e1 systemd[1]: vpnserver.service: Failed with result 'exit-code'.
Mar 05 23:27:47 racknerd-d194e1 systemd[1]: Failed to start vpnserver daemon.
Mar 05 23:27:47 racknerd-d194e1 systemd[1]: vpnserver.service: Scheduled restart job, restart counter is at 1.
Mar 05 23:27:48 racknerd-d194e1 systemd[1]: Stopped vpnserver daemon.
Mar 05 23:27:48 racknerd-d194e1 systemd[373]: vpnserver.service: Failed to execute command: No such file or directory
Mar 05 23:27:48 racknerd-d194e1 systemd[373]: vpnserver.service: Failed at step EXEC spawning /opt/vpnserver.sh: No such file or directory
Mar 05 23:27:48 racknerd-d194e1 systemd[1]: Starting vpnserver daemon...
Mar 05 23:27:48 racknerd-d194e1 systemd[1]: vpnserver.service: Control process exited, code=exited, status=203/EXEC
Mar 05 23:27:48 racknerd-d194e1 systemd[1]: vpnserver.service: Failed with result 'exit-code'.
Mar 05 23:27:48 racknerd-d194e1 systemd[1]: Failed to start vpnserver daemon.
Mar 05 23:27:48 racknerd-d194e1 systemd[1]: vpnserver.service: Scheduled restart job, restart counter is at 2.
Mar 05 23:27:48 racknerd-d194e1 systemd[1]: Stopped vpnserver daemon.
Mar 05 23:27:48 racknerd-d194e1 systemd[381]: vpnserver.service: Failed to execute command: No such file or directory
Mar 05 23:27:48 racknerd-d194e1 systemd[381]: vpnserver.service: Failed at step EXEC spawning /opt/vpnserver.sh: No such file or directory
Mar 05 23:27:48 racknerd-d194e1 systemd[1]: Starting vpnserver daemon...
Mar 05 23:27:48 racknerd-d194e1 systemd[1]: vpnserver.service: Control process exited, code=exited, status=203/EXEC
Mar 05 23:27:48 racknerd-d194e1 systemd[1]: vpnserver.service: Failed with result 'exit-code'.
Mar 05 23:27:48 racknerd-d194e1 systemd[1]: Failed to start vpnserver daemon.
Mar 05 23:27:48 racknerd-d194e1 systemd[1]: vpnserver.service: Scheduled restart job, restart counter is at 3.
Mar 05 23:27:48 racknerd-d194e1 systemd[1]: Stopped vpnserver daemon.
Mar 05 23:27:48 racknerd-d194e1 systemd[387]: vpnserver.service: Failed to execute command: No such file or directory
Mar 05 23:27:48 racknerd-d194e1 systemd[387]: vpnserver.service: Failed at step EXEC spawning /opt/vpnserver.sh: No such file or directory
Kisliy
() автор топика
Ответ на: комментарий от eternal_sorrow

Извиняюсь, в предыдущем сообщении с начала журнала строки скопировал, а не с конца. Вот актуальное:

-- Reboot --
Mar 12 08:00:08 racknerd-d194e1 systemd[1]: Starting vpnserver daemon...
Mar 12 08:00:09 racknerd-d194e1 systemd[1]: vpnserver.service: Succeeded.
Mar 12 08:00:09 racknerd-d194e1 systemd[1]: Started vpnserver daemon.
Mar 12 08:00:09 racknerd-d194e1 systemd[1]: vpnserver.service: Scheduled restart job, restart counter is at 1.
Mar 12 08:00:10 racknerd-d194e1 systemd[1]: Stopped vpnserver daemon.
Mar 12 08:00:10 racknerd-d194e1 systemd[1]: Starting vpnserver daemon...
Mar 12 08:00:10 racknerd-d194e1 systemd[1]: vpnserver.service: Succeeded.
Mar 12 08:00:10 racknerd-d194e1 systemd[1]: Started vpnserver daemon.
Mar 12 08:00:10 racknerd-d194e1 systemd[1]: vpnserver.service: Scheduled restart job, restart counter is at 2.
Mar 12 08:00:10 racknerd-d194e1 systemd[1]: Stopped vpnserver daemon.
Mar 12 08:00:10 racknerd-d194e1 systemd[1]: Starting vpnserver daemon...
Mar 12 08:00:10 racknerd-d194e1 systemd[1]: vpnserver.service: Succeeded.
Mar 12 08:00:10 racknerd-d194e1 systemd[1]: Started vpnserver daemon.
Mar 12 08:00:10 racknerd-d194e1 systemd[1]: vpnserver.service: Scheduled restart job, restart counter is at 3.
Mar 12 08:00:10 racknerd-d194e1 systemd[1]: Stopped vpnserver daemon.
Mar 12 08:00:10 racknerd-d194e1 systemd[1]: Starting vpnserver daemon...
Mar 12 08:00:11 racknerd-d194e1 systemd[1]: vpnserver.service: Succeeded.
Mar 12 08:00:11 racknerd-d194e1 systemd[1]: Started vpnserver daemon.
Mar 12 08:00:11 racknerd-d194e1 systemd[1]: vpnserver.service: Scheduled restart job, restart counter is at 4.
Mar 12 08:00:11 racknerd-d194e1 systemd[1]: Stopped vpnserver daemon.
Mar 12 08:00:11 racknerd-d194e1 systemd[1]: Starting vpnserver daemon...
Mar 12 08:00:11 racknerd-d194e1 systemd[1]: vpnserver.service: Succeeded.
Mar 12 08:00:11 racknerd-d194e1 systemd[1]: Started vpnserver daemon.
Mar 12 08:00:11 racknerd-d194e1 systemd[1]: vpnserver.service: Scheduled restart job, restart counter is at 5.
Mar 12 08:00:11 racknerd-d194e1 systemd[1]: Stopped vpnserver daemon.
Mar 12 08:00:11 racknerd-d194e1 systemd[1]: vpnserver.service: Start request repeated too quickly.
Mar 12 08:00:11 racknerd-d194e1 systemd[1]: vpnserver.service: Failed with result 'start-limit-hit'.
Mar 12 08:00:11 racknerd-d194e1 systemd[1]: Failed to start vpnserver daemon.
Kisliy
() автор топика
Ответ на: комментарий от Kisliy

ну в блин даете :) системд не запускает оболочку для обработки командонй строчки ExecStart и иже с ними.
посему ExeceStart должон указывать на исполняемый двоичный файл, если нужно именно выполнить баш-лапшу надо запускать bash и уже ему скармливать оапшу и т.д.
https://www.freedesktop.org/software/systemd/man/latest/systemd.service.html

Note that shell command lines are not directly supported. If shell command lines are to be used, they need to be passed explicitly to a shell implementation of some kind.
Example:

ExecStart=sh -c ‘dmesg | tac’

т.е. запускать надо

ExecStart =  /usr/bin/bash /opt/vpnserver.sh start
ExecStop =   /usr/bin/bash /opt/vpnserver.sh stop
ExecReload = /usr/bin/bash /opt/vpnserver.sh restart

но я б плюнул на баше лапшу и запускал напрямую. чтонить типа такого. куча костылей баш-лапши отваливается.

[Unit]
Description = vpnserver daemon
Environment="TAP_ADDR=192.168.10.1"

[Service]
ExecStart = /usr/src/vpnserver/vpnserver start
ExecStart = /sbin/ifconfig tap_tap_virtual $TAP_ADDR
ExecStartPost= systemctl start dhcpd


ExecStop = /usr/src/vpnserver/vpnserver stop
Restart = always
RestartSec=15
Type = forking

[Install]
WantedBy = multi-user.target
pfg ★★★★★
()
Последнее исправление: pfg (всего исправлений: 2)
Ответ на: комментарий от pfg

Тем не менее надо разобраться этим, уже большой путь проделан и стали терзать сомнения по поводу глюченности ubuntu. Во-первых, баш у меня в другом месте сидит - по адресу: /bin/bash, но даже исправив этот путь в коде выдаётся тоже самое:

Mar 12 13:13:23 racknerd-d194e1 systemd[1]: Stopped vpnserver daemon.
Mar 12 13:13:23 racknerd-d194e1 systemd[1]: Starting vpnserver daemon...
Mar 12 13:13:23 racknerd-d194e1 systemd[1]: vpnserver.service: Succeeded.
Mar 12 13:13:23 racknerd-d194e1 systemd[1]: Started vpnserver daemon.
Mar 12 13:13:38 racknerd-d194e1 systemd[1]: vpnserver.service: Scheduled restart job, restart counter is at 34.
Mar 12 13:13:38 racknerd-d194e1 systemd[1]: Stopped vpnserver daemon.
Mar 12 13:13:38 racknerd-d194e1 systemd[1]: Starting vpnserver daemon...
Mar 12 13:13:38 racknerd-d194e1 systemd[1]: vpnserver.service: Succeeded.
Mar 12 13:13:38 racknerd-d194e1 systemd[1]: Started vpnserver daemon.
Mar 12 13:13:53 racknerd-d194e1 systemd[1]: vpnserver.service: Scheduled restart job, restart counter is at 35.
Mar 12 13:13:53 racknerd-d194e1 systemd[1]: Stopped vpnserver daemon.
Mar 12 13:13:53 racknerd-d194e1 systemd[1]: Starting vpnserver daemon...
Mar 12 13:13:53 racknerd-d194e1 systemd[1]: vpnserver.service: Succeeded.
Mar 12 13:13:53 racknerd-d194e1 systemd[1]: Started vpnserver daemon.
Mar 12 13:14:08 racknerd-d194e1 systemd[1]: vpnserver.service: Scheduled restart job, restart counter is at 36.
Mar 12 13:14:08 racknerd-d194e1 systemd[1]: Stopped vpnserver daemon.
Mar 12 13:14:08 racknerd-d194e1 systemd[1]: Starting vpnserver daemon...
Mar 12 13:14:08 racknerd-d194e1 systemd[1]: vpnserver.service: Succeeded.
Mar 12 13:14:08 racknerd-d194e1 systemd[1]: Started vpnserver daemon.
Kisliy
() автор топика