How to debug old initd script under systemd?

5,787

Solution 1

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.

Solution 2

A couple of things.

  1. Run the command with a clean environment:

    env -i PATH=/usr/sbin:/sbin:/usr/bin:/bin /etc/init.d/SCRIPT start
    
  2. Second, turn on shell debugging. One simple way to do this is with:

    bash -x SCRIPT start
    

combining the two, you get:

    env -i PATH=/usr/sbin:/sbin:/usr/bin:/bin bash -x /etc/init.d/SCRIPT start
  1. Disable systemd's compatibility mode with:

    SYSTEMCTL_SKIP_REDIRECT=true
    

The name of this variable might vary. Your init script probably includes something like

    . /etc/sysconfig/functions

That file will check on the above environment variable. (Suse is a bit different than it's RedHat based cousins, so YMMV).

Combining all the above:

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

Finally, since the output will be voluminous, append the following:

2>&1 | less -r +F

The less program will buffer the output allowing you to scroll back the entire history. Hit CTRL-C to exit it's "follow" mode do be able to scroll back, etc.

Share:
5,787

Related videos on Youtube

Gene Vincent
Author by

Gene Vincent

Updated on September 18, 2022

Comments

  • Gene Vincent
    Gene Vincent over 1 year

    I have an older initd script to start my application. It worked fine under older versions of SuSE, but fails on Open SuSE 12.3.

    The strange thing is

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

    works fine.

    /etc/init.d/script start
    

    shows a redirection to systemctl, but doesn't start my application (and also doesn't show any output from the initd script).

    I don't see any log entries showing me what goes wrong. The only entry I see is in /var/log/messages saying the application was started.

    How do I debug this ?

  • Gene Vincent
    Gene Vincent over 10 years
    Its not a relavive paths. It has to do with the fact that its a shell script thats being started that conatins a never ending loop.