LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Systemd fails to start same script with different name (https://www.linuxquestions.org/questions/linux-newbie-8/systemd-fails-to-start-same-script-with-different-name-4175641862/)

ZiZiL 11-06-2018 12:32 PM

Systemd fails to start same script with different name
 
So, I am pulling my hair on this. The OS is:
Code:

    $ cat /etc/os-release
    PRETTY_NAME="Raspbian GNU/Linux 9 (stretch)"

I have two php scripts under /home/pi/PlaneAlert/
Code:

    $ ls -al
    -rw-r--r-- 1 pi pi  1816 Nov  5 10:38 aircraft.db
    -rwxr-xr-x 1 pi pi  1869 Nov  5 11:09 aircraftdbcheck.php
    -rwxr-xr-x 1 pi pi 13847 Nov  5 11:05 planealert.php

Then I have following services configured:
Code:

    $ sudo cat /etc/systemd/system/planealert.service
   
        [Unit]
        Description=planealert.php
       
        [Service]
        ExecStart=/home/pi/PlaneAlert/planealert.php
        Restart=always
        RestartSec=10
        StandardOutput=null
        StandardError=null
       
        [Install]
        WantedBy=multi-user.target
   

    $ sudo cat /etc/systemd/system/aircraftdbcheck.service
   
        [Unit]
        Description=aircraftdbcheck.php
       
        [Service]
        ExecStart=/home/pi/PlaneAlert/aircraftdbcheck.php
        Restart=always
        RestartSec=10
        StandardOutput=null
        StandardError=null
       
        [Install]
        WantedBy=multi-user.target

When I start planealert service, it starts perfectly fine and runs great. However when I start aircraftdb, I get following:
Code:

    systemd[1]: Started aircraftdbcheck.php.
    systemd[5268]: aircraftdbcheck.service: Failed at step EXEC spawning /home/pi/PlaneAlert/aircraftdbcheck.php: No such file or directory
    systemd[1]: aircraftdbcheck.service: Main process exited, code=exited, status=203/EXEC
    systemd[1]: aircraftdbcheck.service: Unit entered failed state.
    systemd[1]: aircraftdbcheck.service: Failed with result 'exit-code'.

In order to make sure that the script itself is not an issue, I copied planealert.php (the one that runs fine) and renamed it as aircraftdbcheck.php. Even then, I get the same error so I know for a fact that it is not the contents of the file.

So, what the heck is different on aircraftdbcheck.php file that makes it unfindable by systemd? Please help as I am gonna lose my mind.

lazydog 11-06-2018 12:55 PM

Systemd is stating that it cannot find the file.
Double check your spelling and ensure everything is spelled the same in '/home/pi/PlaneAlert/'.

scasey 11-06-2018 12:59 PM

Does journalctl provide any more information?

ZiZiL 11-06-2018 01:04 PM

Yeah. I checked the paths like 10 times. They look alright to me. Also, I ran journalctl and watched for any logs generated while I attempt to start the service. There is no logs related to the service.

ZiZiL 11-06-2018 02:57 PM

I have kept an eye on journalctl while I attempt to start the service. There were no logs.

lazydog 11-06-2018 04:33 PM

Output from the following command:

Code:

ls -l /home/pi/PlaneAlert/

dc.901 11-06-2018 04:36 PM

Quote:

Originally Posted by ZiZiL (Post 5923479)
I have kept an eye on journalctl while I attempt to start the service. There were no logs.

In your file, I see:
Quote:

StandardOutput=null
StandardError=null
What happens if you set these to a valid file, then restart service; does it create any additional output?

michaelk 11-06-2018 06:23 PM

Quote:

I copied planealert.php (the one that runs fine) and renamed it as aircraftdbcheck.php.
Quote:

-rwxr-xr-x 1 pi pi 1869 Nov 5 11:09 aircraftdbcheck.php
-rwxr-xr-x 1 pi pi 13847 Nov 5 11:05 planealert.php

Just from the difference in file size they can not be the same unless you have already restored them back to originals. I assume the original aircraftdbcheck.php works from the command line?

ZiZiL 11-07-2018 07:44 AM

Quote:

Originally Posted by michaelk (Post 5923510)
Just from the difference in file size they can not be the same unless you have already restored them back to originals. I assume the original aircraftdbcheck.php works from the command line?


Yes. Forgot to mention that. I restored the original content of aircraftdbcheck. Also, it works flawlessly when i run $php aircraftdbcheck.php from the terminal directly. No issues whatsoever.


Quote:

Originally Posted by lazydog (Post 5923496)
Output from the following command:

Code:

ls -l /home/pi/PlaneAlert/

That was included in my first submission however here is a fresh one:

Code:

$ ls -l /home/pi/PlaneAlert/
total 28
-rw-r--r-- 1 pi pi  1816 Nov  5 10:38 aircraft.db
-rwxr-xr-x 1 pi pi  1869 Nov  5 11:26 aircraftdbcheck.php
drwxr-xr-x 3 pi pi  4096 Nov  6 09:39 dump1090-mutability-planealert
-rwxr-xr-x 1 pi pi 13847 Nov  5 11:05 planealert.php


ZiZiL 11-07-2018 07:52 AM

Quote:

Originally Posted by dc.901 (Post 5923497)
In your file, I see:


What happens if you set these to a valid file, then restart service; does it create any additional output?

I changed the service file:

Code:

$ cat /etc/systemd/system/aircraftdbcheck.service
[Unit]
Description=aircraftdbcheck.php

[Service]
ExecStart=/home/pi/PlaneAlert/aircraftdbcheck.php
Restart=always
RestartSec=10
StandardOutput=/var/log/air_out.log
StandardError=/var/log/air_err.log

[Install]
WantedBy=multi-user.target

I created two blank files under /var/log/

I attempted to start the service. Got the same file not found error from syslog. I checked the contents of the following files, they are blank.

$ cat /var/log/air_err.log
$ cat /var/log/air_out.log
--Above commands return nothing, files are empty--

zeebra 11-07-2018 07:57 AM

I don't get it..

You copied planealert.php to aircraftdbcheck.php and it works only as planealert and not as aircraftdbcheck? Well, look at the files. Why is aircraftdbcheck.php a completely different size than planealert if it is a copy?

ZiZiL 11-07-2018 07:58 AM

I have also just tried to move aircraftdb to a new folder under /usr/local/bin/airdb and recreate the service from scratch using the new location. Same error. This does not make sense whatsoever.

ZiZiL 11-07-2018 08:04 AM

Quote:

Originally Posted by zeebra (Post 5923637)
I don't get it..

You copied planealert.php to aircraftdbcheck.php and it works only as planealert and not as aircraftdbcheck? Well, look at the files. Why is aircraftdbcheck.php a completely different size than planealert if it is a copy?

What I meant there was in order to rule our the contents of the file, the script, I wanted to perform a test. So I copied the contents of planealert.php, the script runs perfectly via service, into aircraftdbcheck.php and attempted to start aircraftdbcheck service. I wanted to see if the content of the file is causing the issue or not. When i try to start the service, I got the same error which told me that the contents of the file was not an issue since planealert.php was running perfectly fine. Here it is:

Code:

$ sudo service planealert status
● planealert.service - planealert.php
  Loaded: loaded (/etc/systemd/system/planealert.service; enabled; vendor preset: enabled)
  Active: active (running) since Mon 2018-11-05 11:06:00 CST; 1 day 20h ago
 Main PID: 4740 (planealert.php)
  CGroup: /system.slice/planealert.service
          └─4740 /usr/bin/php /home/pi/PlaneAlert/planealert.php

As you can see, it runs perfectly. Even though I have same contents of planealert.php in aircraftdbcheck.php, it still wont start:

Code:

$ sudo service aircraftdbcheck status
● aircraftdbcheck.service - aircraftdbcheck.php
  Loaded: loaded (/etc/systemd/system/aircraftdbcheck.service; enabled; vendor preset: enabled)
  Active: activating (auto-restart) (Result: exit-code) since Wed 2018-11-07 08:03:02 CST; 2s ago
  Process: 32177 ExecStart=/home/pi/PlaneAlert/aircraftdbcheck.php (code=exited, status=203/EXEC)
 Main PID: 32177 (code=exited, status=203/EXEC)

Nov 07 08:03:02 *****.ddns.net systemd[1]: aircraftdbcheck.service: Failed with result 'exit-code'.

Once again, above test was just done. In the test, aircraftdbcheck had the same contents of planealert for testing purposes.

zeebra 11-07-2018 08:58 AM

Yah, I understood that. But I would go back to that situation rather than the original situation.

As far as I can understand, the problem is somewhere in the script. If you now go back to testing the same script (copied) under a different name, we can figure the reason for the problem out easier, if it is still there. But now you have taken us back to a situation with 2 different scripts, where 1 run and 1 don't. That's a PHP problem IMO. If you copy the same script into a different name and have an issue, the problem is not IN the script, but in GNU somewhere, and then we can find out.

TenTenths 11-07-2018 09:02 AM

Right, what everyone so far has missed is that you're not starting your new file properly.

You are trying to execude a php file directly, however in your example when you say it's working from the command line you show that you're actually running it with:
Quote:

Originally Posted by ZiZiL (Post 5923633)
Code:

php aircraftdbcheck.php


Change:
Code:

ExecStart=/home/pi/PlaneAlert/aircraftdbcheck.php
to:
Code:

ExecStart=/the/path/to/php /home/pi/PlaneAlert/aircraftdbcheck.php
and see how you get on.


All times are GMT -5. The time now is 04:41 PM.