Fedora – Systemd Service Script Not Echoing

fedorascriptingsystemd

I've recently setup Fedora 22 onto a machine and it's using the systemd init system.

I've been reading up on it and now I need to create a systemd start up script for postgresql

For testing I created the following shell script, hello_world

#! /bin/sh
#  testing systemctl script

start() {
   echo "Executing Start"
   echo "Testing 01"
   echo "Testing 02"
   echo "Testing 03"
}

stop() {
   echo "Stopping Hello World Script"
}

case "$1" in
   start)
      start
   ;;
   stop)
      stop
   ;;
   restart)
      stop
      sleep 2
      start
   ;; 
   *) exit 1
esac

Which when I run it using the terminal it does what I expect and echos the strings

. hello_world start

This echos "Starting Hello World Script" then I placed it inside /usr/lib/systemd/scripts

Then I tried to create the systemd service script as follows, hello_world.service

[Unit]
Description=Hello World Testing Script

[Service]
Type=oneshot
ExecStart=/usr/lib/systemd/scripts/hello_world start
ExecStop=/usr/lib/systemd/scripts/hello_world stop
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

Which I placed inside /usr/lib/systemd/system and tried to execute with

systemctl start hello_world.service

Which did not give any errors but I did not get the echo string that I expected when i executed the hello_world script alone.

So I can't tell if it is actually working, did I miss something? why is the systemctl command not echoing the string from the script?

Best Answer

It seems that the output for the script is not sent to the terminal it is instead redirected to the status command

After the service is running

# systemctl start hello_world.service

I can view my outputs in the status

# systemctl status hello_world.service

Which will include any outputs from the script like bellow

Apr 28 10:18:00 centos7.adminserv systemd[1]: Starting Hello World Testing S....
Apr 28 10:18:00 centos7.adminserv hello_world[18164]: Executing Start
Apr 28 10:18:00 centos7.adminserv hello_world[18164]: Testing 01
Apr 28 10:18:00 centos7.adminserv hello_world[18164]: Testing 02
Apr 28 10:18:00 centos7.adminserv hello_world[18164]: Testing 03
Apr 28 10:18:00 centos7.adminserv systemd[1]: Started Hello World Testing Sc....