Как отладить старый скрипт initd под systemd?

5032
Gene Vincent

У меня есть старый скрипт initd для запуска моего приложения. Он работал нормально под старыми версиями SuSE, но не работает на Open SuSE 12.3.

Странная вещь

cd /etc/init.d ; ./script start 

работает отлично.

/etc/init.d/script start 

показывает перенаправление на systemctl, но не запускает мое приложение (а также не показывает никакого вывода из скрипта initd).

Я не вижу записей в журнале, показывающих, что идет не так. Единственная запись, которую я вижу, находится в / var / log / messages, сообщая, что приложение было запущено.

Как мне отладить это?

5
проверить это http://0pointer.de/blog/projects/systemd-for-admins-3.html Alex 10 лет назад 2

3 ответа на вопрос

2
Otheus

Пара вещей.

  1. Запустите команду с чистой средой:

    env -i PATH=/usr/sbin:/sbin:/usr/bin:/bin /etc/init.d/SCRIPT start 
  2. Во-вторых, включите отладку оболочки. Один простой способ сделать это с помощью:

    bash -x SCRIPT start 

комбинируя два, вы получите:

 env -i PATH=/usr/sbin:/sbin:/usr/bin:/bin bash -x /etc/init.d/SCRIPT start 
  1. Отключить systemdрежим совместимости с:

    SYSTEMCTL_SKIP_REDIRECT=true 

Имя этой переменной может отличаться. Ваш сценарий инициализации, вероятно, содержит

 . /etc/sysconfig/functions 

Этот файл проверит вышеуказанную переменную среды. (Suse немного отличается от своих двоюродных братьев, основанных на RedHat, так что YMMV).

Сочетая все вышеперечисленное:

env -i PATH=/usr/sbin:/sbin:/usr/bin:/bin SYSTEMCTL_SKIP_REDIRECT=true \ bash -x /etc/init.d/SCRIPT start 

Наконец, поскольку вывод будет объемным, добавьте следующее:

2>&1 | less -r +F 

lessПрограмма буферизации вывода позволяет прокручивать назад всю историю. Нажмите, CTRL-Cчтобы выйти из режима «следуй», можно будет прокрутить назад и т. Д.

1
MariusMatutiae

The reason why the script has this behaviour is that OpenSuse 12.3 has replaced the old sysvinit with systemd, a system management daemn which controls the whole boot process.

The format of script describing services to be started by systemd differs from that of sysvinit, so it is little wonder that your script fails. Once the script is properly set up, its operation via systemctl is trivial:

sudo systemctl enable/disable your-service 

enables or disables it, and typically

sudo systemctl start/stop/status your-service 

starts it, stops it, inquiries after its status.

A typical custom service script is located in the folder /etc/systemd/system, ends with the suffix .service, and has this format:

 [Unit] Description=sdbarker.com Chiliproject Requires=mysqld.service nginx.service Wants=mysqld.service nginx.service [Service] User=www-data WorkingDirectory=/path/to/chiliproject/install ExecStart=/usr/bin/bundle PIDFile=/path/to/chiliproject/install/tmp/pids/server.pid [Install] WantedBy=multi-user.target 

As you can see, most entries are self-explanatory. Without knowing more about your script I cannot provide further assistance, but you will find in this Arch Linux Wiki page the info you need to write a proper custom service script.

0
Mihai

Most probably there is a relative path inside /etc/init.d/script that it's not relevant outside /etc/init.d/. You could put the contents of the script here (unless is really huge).

Make sure that any arguments you send to your application do not contain relative paths, since the application's working dir is the one where it is started.

Это не относительные пути. Это связано с тем, что запускается скрипт оболочки, который содержит бесконечный цикл. Gene Vincent 10 лет назад 0

Похожие вопросы