А есть ли готовый SystemD unit для службы?

8 years 1 month ago #529 by alexs
alexs replied the topic: А есть ли готовый SystemD unit для службы?
SimpleOPDS.service

[Unit]
Description=Simple OPDS
After=
Requires=mariadb.service

[Service]
ExecStart=/var/www/opds/py/sopdsd.py start
Type=forking
PIDFile=/tmp/sopds-http.pid
ExecStop=/var/www/opds/py/sopdsd.py stop

[Install]
WantedBy=multi-user.target

Please Войти or Create an account to join the conversation.

  • alexs
  • alexs's Avatar Topic Author
  • Offline
  • Новый участник
  • Новый участник
More
7 years 8 months ago #632 by ll23
ll23 replied the topic: А есть ли готовый SystemD unit для службы?
Для себя сделал такой sopds.service
[Unit]
Description=Simple OPDS
After=network.target
Requires=mysql.service

[Service]
User=ЮЗЕР
Group=ГРУППА
ExecStart=/opt/sopds/py/sopdsd.py start
Type=forking
PIDFile=/tmp/sopds-http.pid
ExecStop=/opt/sopds/py/sopdsd.py stop

[Install]
WantedBy=multi-user.target
ЮЗЕР и ГРУППА указаны в соответствии с доступами к файлам библиотеки.
Все работает, но в статусе вижу:
systemctl -l status sopds.service                                                                                                                [/etc/systemd/system]
● sopds.service - Simple OPDS
   Loaded: loaded (/etc/systemd/system/sopds.service; enabled; vendor preset: enabled)
   Active: active (running) since Вт 2016-07-26 22:29:37 MSK; 2s ago
  Process: 18558 ExecStop=/opt/sopds/py/sopdsd.py stop (code=exited, status=0/SUCCESS)
  Process: 18568 ExecStart=/opt/sopds/py/sopdsd.py start (code=exited, status=0/SUCCESS)
 Main PID: 18574 (python3)
    Tasks: 2
   Memory: 17.0M
      CPU: 241ms
   CGroup: /system.slice/sopds.service
           ├─18574 python3 /opt/sopds/py/sopdsd.py start
           └─18575 python3 /opt/sopds/py/sopdsd.py start

июл 26 22:29:37 Pine-NAS systemd[1]: Starting Simple OPDS...
июл 26 22:29:37 Pine-NAS sopdsd.py[18568]: SOPDS HTTP Daemon going to background, PID: 18574
июл 26 22:29:37 Pine-NAS sopdsd.py[18568]: SOPDS SCAN Daemon going to background, PID: 18575
июл 26 22:29:37 Pine-NAS systemd[1]: sopds.service: Supervising process 18574 which is not our child. We'll most likely not notice when it exits.
июл 26 22:29:37 Pine-NAS systemd[1]: Started Simple OPDS.
На это забивать: "Supervising process which is not our child"? Или что-то подкрутить можно/нужно?

Please Войти or Create an account to join the conversation.

  • ll23
  • ll23's Avatar
  • Offline
  • Новый участник
  • Новый участник
More
7 years 8 months ago #635 by mitshel
mitshel replied the topic: А есть ли готовый SystemD unit для службы?
sopdsd.py - утилита которая сама "форкает" два процесса:


1. Встроенный http/opds-server который можно вручную запустить командой sopdserve.py
2. Периодический сканер, который можно вручную запустить командй sopds-scan.py



. Поэтому если вы хотите использовать systemd для демонизации sopds, думаю вам нужно сделать следующее:

1. При помощи sopds.service запускать программу sopdserve.py.

2. Периодическое сканирование настроить например при помощи CRON и утилиты sopds-scan.py

Please Войти or Create an account to join the conversation.

  • mitshel
  • mitshel's Avatar
  • Offline
  • Администратор
  • Администратор
More
7 years 8 months ago - 7 years 8 months ago #637 by ll23
ll23 replied the topic: А есть ли готовый SystemD unit для службы?
К сожалению, если создать сервис в котором будет ExecStart=/opt/sopds/py/sopdserve.py, то демонизации не происходит и через пару минут systemd убивает его по таймауту.
Моих знаний не хватает на решение этой задачи, так что придется запускать через crontab по @reboot.
Если кто-нибудь может написать правильный sopds.service, то будет очень интересно ознакомиться. Но я предполагаю, что причина в самом методе демонизации через двойной форк и для корректного запуска службы нужно полностью переписывать sopsd.py
Last Edit: 7 years 8 months ago by ll23.

Please Войти or Create an account to join the conversation.

  • ll23
  • ll23's Avatar
  • Offline
  • Новый участник
  • Новый участник
More
7 years 8 months ago #640 by mitshel
mitshel replied the topic: А есть ли готовый SystemD unit для службы?
Может попробовать:
ExecStart=nohup /opt/sopds/py/sopdserve.py &

Please Войти or Create an account to join the conversation.

  • mitshel
  • mitshel's Avatar
  • Offline
  • Администратор
  • Администратор
More
7 years 8 months ago - 7 years 8 months ago #641 by ll23
ll23 replied the topic: А есть ли готовый SystemD unit для службы?
К сожалению это тоже не помогает.
systemctl status sopds.service                                                                                                                                      [/etc/systemd/system]
● sopds.service - Simple OPDS
   Loaded: loaded (/etc/systemd/system/sopds.service; disabled; vendor preset: enabled)
   Active: failed (Result: timeout) since Вс 2016-07-31 18:12:14 MSK; 23s ago
  Process: 24078 ExecStart=/usr/bin/nohup /opt/sopds/py/sopdserve.py & (code=killed, signal=TERM)

июл 31 18:10:44 Pine-NAS systemd[1]: Starting Simple OPDS...
июл 31 18:12:14 Pine-NAS systemd[1]: sopds.service: Start operation timed out. Terminating.
июл 31 18:12:14 Pine-NAS systemd[1]: Failed to start Simple OPDS.
июл 31 18:12:14 Pine-NAS systemd[1]: sopds.service: Unit entered failed state.
июл 31 18:12:14 Pine-NAS systemd[1]: sopds.service: Failed with result 'timeout'.

Запуск по крону не нравится тем, что невозможно автоматически отследить падение демона и сделать его рестарт, а если запускать как службу, то за этим следит systemd.
Last Edit: 7 years 8 months ago by ll23.

Please Войти or Create an account to join the conversation.

  • ll23
  • ll23's Avatar
  • Offline
  • Новый участник
  • Новый участник
More
Time to create page: 0.119 seconds