Don't know how to setup MonaServer as a daemon on Ubuntu

633 views
Skip to first unread message

Bert Hrothgar

unread,
Feb 6, 2016, 11:39:07 AM2/6/16
to MonaServer
Hi! I've successfully installed MonaServer on a VPS running Ubuntu 15.04, but I seem unable to run it as a daemon in the background. sudo ./MonaServer --daemon [--pidfile=/var/run/MonaServer.pid] doesn't do anything, and the service file from this topic always ends in Failed to start mona.service: Unit mona.service failed to load: No such file or directory. Am I doing something wrong, or is there another way to run MonaServer in the background without having to manually start it every time? Any help would be greatly appreciated.

KawaiiWoIf

unread,
Feb 8, 2016, 9:54:48 PM2/8/16
to MonaServer, swis...@gmail.com
Not sure how you'd do it in ubuntu specifically but for my Debian server I made up a script in /etc/init.d and registered it via update-rc.d. Directions would be similar to https://www.debian-administration.org/article/28/Making_scripts_run_at_boot_time_with_Debian

#!/bin/sh
# init script for MonaServer

### BEGIN INIT INFO
# Provides:          mona
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# X-Interactive:     true
# Short-Description: mona rtmp server
# Description:       Start the rtmp server and associated helpers
### END INIT INFO

case "$1" in
 start)
  cd /usr/src/MonaServer/MonaServer
  echo "Starting MonaServer"
  ./MonaServer --daemon
 ;;
 stop)
  pkill MonaServer
  echo "Stopping MonaServer"
  ;;
 *)
  echo "Usage: /etc/init.d/mona {start|stop|restart}"
  exit 1
  ;;
esac

exit 0


It's not the most comprehensive script but it'll start up when the server does and I can start/stop it with "/etc/init.d/mona stop", etc.. Good luck on Ubuntu !

Bert Hrothgar

unread,
Feb 9, 2016, 5:23:48 AM2/9/16
to MonaServer
Thanks for your suggestion! I couldn't adopt your script and method directly, probably because Ubuntu 15.04 uses systemd instead of upstart, but after using your script as a base, with some trial and error (and a lot of swearing) I managed to get it working. For anyone else having a similar problem, I've placed the following script named as mona somewhere first:

#! /bin/sh

start
() {
 cd
/usr/MonaServer/MonaServer

 echo
"Starting MonaServer"
 
./MonaServer --daemon
}


stop
() {

 pkill
MonaServer
 echo
"Stopping MonaServer"
}
case "$1" in
    start
)
        start
       
;;
    stop
)
        stop
       
;;
    restart
)
        stop
        sleep
1
        start
       
;;
   
*) exit 1
esac

Then I created the following file called mona.service in /etc/systemd/system :

[Unit]
Description=MonaServer

[Service]
Type=oneshot
ExecStart=<directory of script>mona start
ExecStop=<directory of script>mona stop
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

After that, I enabled the service with:

systemctl enable mona.service

And of course you can manually start/stop/restart the service with:

systemctl start/stop/restart mona

Thomas Jammet

unread,
Feb 28, 2016, 12:24:43 PM2/28/16
to MonaServer, swis...@gmail.com
Great job!

You can also try this service file without the mona script :

[Unit]
Description=MonaServer service

[Service]
Type=forking
WorkingDirectory=/home/user/MonaServer/MonaServer
ExecStart=/home/user/MonaServer/MonaServer/MonaServer --daemon
Restart=on-abort

[Install]
WantedBy=multi-user.target

For me it works well on Fedora, that's the simplest way I've found.

Regards
Reply all
Reply to author
Forward
0 new messages