17

Can I do This start up service below, there are no errors showing once run, but the server script below does not run!

ln /lib/systemd/aquarium.service aquarium.service
systemctl daemon-reload
systemctl enable aquarium.service
systemctl start aquarium.service

thanks

aquarium.service:

[Unit]
Description=Start aquarium server

[Service]
WorkingDirectory=/home/root/python/code/aquarium/
ExecStart=/bin/bash server.* start
KillMode=process

[Install]
WantedBy=multi-user.target

here is the server.sh script

#!/bin/bash

PID=""

function get_pid {
   PID=`pidof python ./udpthread.py`
}

function stop {
   get_pid
   if [ -z $PID ]; then
      echo "server is not running."
      exit 1
   else
      echo -n "Stopping server.."
      kill -9 $PID
      sleep 1
      echo ".. Done."
   fi
}


function start {
   get_pid
   if [ -z $PID ]; then
      echo  "Starting server.."
      ./udpthread.py &
      get_pid
      echo "Done. PID=$PID"
   else
      echo "server is already running, PID=$PID"
   fi
}

function restart {
   echo  "Restarting server.."
   get_pid
   if [ -z $PID ]; then
      start
   else
      stop
      sleep 5
      start
   fi
}


function status {
   get_pid
   if [ -z  $PID ]; then
      echo "Server is not running."
      exit 1
   else
      echo "Server is running, PID=$PID"
   fi
}

case "$1" in
   start)
      start
   ;;
   stop)
      stop
   ;;
   restart)
      restart
   ;;
   status)
      status
   ;;
   *)
      echo "Usage: $0 {start|stop|restart|status}"
esac
1

1 Answer 1

31

Try using "Type=forking" and use complete filename.

[Unit]
Description=Start aquarium server

[Service]
WorkingDirectory=/home/root/python/code/aquarium/
Type=forking
ExecStart=/bin/bash server.sh start
KillMode=process

[Install]
WantedBy=multi-user.target

if it not work, post output of this command:

# journalctl -u aquarium.service
Sign up to request clarification or add additional context in comments.

7 Comments

Thanks for that, however I get this when using the exact script you typed up there. know that /bin/bash server.sh start does start the script!! beaglebone:~# systemctl status aquarium.service aquarium.service - Start aquarium server Loaded: loaded (/etc/systemd/system/aquarium.service; enabled) Active: failed (Result: exit-code) since Fri, 01 Mar 2013 18:18:26 +1100; 23s ago Process: 12545 ExecStart=/bin/bash server.sh start (code=exited, status=200/CHDIR) Main PID: 12482 (code=exited, status=200/CHDIR) CGroup: name=systemd:/system/aquarium.service
I forgot to add this Mar 01 18:18:26 beaglebone (bash)[12545]: Failed at step CHDIR spawning /bin/bash: No such file or directory
hmm, what system you are using ? On ArchLinux this files are symbolic links: % ls -l /bin/sh /bin/bash lrwxrwxrwx 1 root root 15 Jan 26 21:19 /bin/bash -> ../usr/bin/bash* lrwxrwxrwx 1 root root 15 Jan 26 21:19 /bin/sh -> ../usr/bin/bash* Try replacing "/bin/bash" with "/bin/sh", and make sure that files exists using "ls -l"
Hi, i am using angstrom on the beaglebone /bin/sh does not work too!! This was supposed to be easy to set up
Try, "ExecStart=/bin/sh /home/root/python/code/aquarium/server.sh start"
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.