Reputation: 31
When I'm trying to execute script through systemd service - I receive error message and script can't be run.
init_something.service file:
[Unit]
Description=Loading module --module_name module
[Service]
Type=oneshot
ExecStart=/usr/lib/systemd/init_script
[Install]
WantedBy=multi-user.target
init_script file:
#!/bin/bash -
/usr/local/bin/init.sh --module_init
And now if I try to start service by systemctl I receive error message:
# systemctl start init_something.service
Job for init_something.service failed. See 'systemctl status init_something.service' and 'journalctl -xn' for details
# systemctl status init_something.service
init_something.service - Loading module --module_name module
Loaded: loaded (/usr/lib/systemd/init_something.service)
Active: failed (Result: exit-code) since Thu 1970-01-01 08:00:24 CST; 1min 49s ago
Process: 243 ExecStart=/usr/lib/systemd/init_script (code=exited, status=1/FAILURE)
Main PID: 243 (code=exited, status=1/FAILURE)
But if I try to run init_script manualy - it works perfectly:
# /usr/lib/systemd/init_script
[ 447.409277] SYSCLK:S0[...]
[ 477.523434] VIN: (...)
Use default settings
map_size = (...)
u_code version = (...)
etc.
And finally module is loaded successfully.
So the question is - why systemctl can't execute this script, but manually it's no problem?
Upvotes: 0
Views: 775
Reputation: 976
For running any script file, system needs shell. But systemd do'nt have its own shell. So you need to provide shell for running script.
so use ExecStart=/bin/sh /usr/lib/systemd/init_script
in your service unit.
[Unit]
Description=Loading module --module_name module
[Service]
Type=oneshot
ExecStart=/bin/sh /usr/lib/systemd/init_script
[Install]
WantedBy=multi-user.target
And
chmod 777 /usr/lib/systemd/init_script
before running your script.
Upvotes: 1