Skip to content

Instantly share code, notes, and snippets.

@gregology
Last active September 24, 2024 14:49
Show Gist options
  • Save gregology/5313326 to your computer and use it in GitHub Desktop.
Save gregology/5313326 to your computer and use it in GitHub Desktop.
Service script for dashing. Update DASHING_DIR variable, add this file to /etc/init.d/ , chmod to 755, and let update rc.d with $ sudo update-rc.d dashboard defaults This scripts stops the dashing service with "killall thin" which will kill all thin services running on your server.
#!/bin/bash
# Dashing service
# Add this file to /etc/init.d/
# $ sudo cp dashboard /etc/init.d/
# Update variables DASHING_DIR, GEM_HOME, & PATH to suit your installation
# $ sudo nano /etc/init.d/dashboard
# Make executable
# $ sudo chmod 755 /etc/init.d/dashboard
# Update rc.d
# $ sudo update-rc.d dashboard defaults
# Dashboard will start at boot. Check out the boot log for trouble shooting "/var/log/boot.log"
# USAGE: start|stop|status|logs
### BEGIN INIT INFO
# Provides: dashboard
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start daemon at boot time
# Description: Enable service provided by daemon.
### END INIT INFO
# Gregology <[email protected]>
# https://gist.github.com/gregology/5313326
# Based on Faraz Haider's LifeRay Startup Service script
# https://gist.github.com/haiderfaraz/2773431
DASHING_DIR=/path/to/dashboard/
GEM_HOME=/usr/local/lib/ruby/gems/1.9.1
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
case "$1" in
start)
echo "Starting Dashing."
cd $DASHING_DIR; dashing start -d
;;
stop)
echo "Stopping Dashing."
killall thin
;;
logs)
echo "See the logs of the Dashing."
tail -f $DASHING_DIR'log/thin.log'
;;
status)
# Check to see if the process is running
ps aux|grep -i dashing
;;
*)
echo "Dashing"
echo $"Usage: $0 {start|stop|status|logs}"
exit 1
esac
exit 0
@RSO
Copy link

RSO commented May 22, 2013

Hey, I did some small changes to you're awesome init script for Dashing. It now uses start-stop-daemon and kills only the specific Thin process, instead of all processes!

#!/bin/bash
# Dashing service
# Add this file to /etc/init.d/
# $ sudo cp dashboard /etc/init.d/
# Update variables DASHING_DIR, GEM_HOME, & PATH to suit your installation
# $ sudo nano /etc/init.d/dashboard
# Make executable
# $ sudo chmod 755 /etc/init.d/dashboard
# Update rc.d
# $ sudo update-rc.d dashboard defaults
# Dashboard will start at boot. Check out the boot log for trouble shooting "/var/log/boot.log"
# USAGE: start|stop|status|logs

### BEGIN INIT INFO
# Provides:          dashboard
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start daemon at boot time
# Description:       Enable service provided by daemon.
### END INIT INFO

set -e

# Must be a valid filename
NAME=dashing
DASHING_DIR=/path/to/dashboard/
DAEMON=/path/to/executable/dashing
DAEMON_OPTS="start -d -P $PIDFILE"
GEM_HOME=/usr/local/lib/ruby/gems/1.9.1

export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

case "$1" in
  start)
    echo -n "Starting daemon: "$NAME
    start-stop-daemon --start --quiet --chdir $DASHING_DIR --exec $DAEMON -- $DAEMON_OPTS
    echo "."
  ;;
  stop)
    echo -n "Stopping daemon: "$NAME
    start-stop-daemon --stop --quiet --signal 9 --oknodo --pidfile $PIDFILE
    echo "."
  ;;
  restart)
    echo -n "Restarting daemon: "$NAME
    start-stop-daemon --stop --quiet --signal 9 --oknodo --retry 30 --pidfile $PIDFILE
    start-stop-daemon --start --quiet --chdir $DASHING_DIR --exec $DAEMON -- $DAEMON_OPTS
    echo "."
  ;;
  logs)
    echo "See the logs of the Dashing."
    tail -f $DASHING_DIR'log/thin.log'
  ;;

  *)
  echo "Usage: "$1" {start|stop|restart}"
  exit 1
esac

exit 0

@plytro
Copy link

plytro commented Aug 2, 2013

#!/bin/bash
# Dashing service
# Add this file to /etc/init.d/
# $ sudo cp dashboard /etc/init.d/
# Update variables the variables to suit your installation
# $ sudoedit /etc/init.d/dashboard
# Make executable
# $ sudo chmod 755 /etc/init.d/dashboard
# Update rc.d
# $ sudo update-rc.d dashboard defaults
# Dashboard will start at boot. Check out the boot log for trouble shooting "/var/log/boot.log"
# USAGE: start|stop|restart|status

### BEGIN INIT INFO
# Provides:          dashboard
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start daemon at boot time
# Description:       Enable service provided by daemon.
### END INIT INFO

set -e
. /lib/lsb/init-functions

# Must be a valid filename
NAME=dashing
DASHING_DIR=/var/www/current
PIDFILE="$DASHING_DIR/$NAME.pid"
DAEMON=/usr/local/bin/$NAME
GEM_HOME=/var/lib/gems/1.9.1

DASHING_PORT=8080
DAEMON_OPTS="start -d -p $DASHING_PORT -P $PIDFILE --tag $NAME -D"

RUNUSER=www-data
RUNGROUP=www-data

test -x $DAEMON || { log_failure_msg "$NAME not installed";exit 1; }

function checkuser() {
  if [[ $UID != 0 ]]; then
    if [[ `whoami` != "$RUNUSER" ]]; then
      log_failure_msg "$1 must be run as root or $RUNUSER"
      exit 1
    fi
  fi
}

function start_dashing() {
  log_action_msg "Starting daemon: $NAME" || true
  sleep 5
  start-stop-daemon --verbose --quiet --start --chuid $RUNUSER:$RUNGROUP --chdir $DASHING_DIR --exec $DAEMON -- $DAEMON_OPTS
  log_end_msg 0
}

function stop_dashing() {
  log_action_msg "Stopping daemon: $NAME" || true
  start-stop-daemon --quiet --stop --pidfile $PIDFILE --user $RUNUSER --retry 30 --oknodo
  log_end_msg 0
}


case "$1" in
  start)
    checkuser start
    start_dashing
  ;;
  stop)
    checkuser stop
    stop_dashing
  ;;
  restart)
    checkuser restart
    log_action_msg "Restarting daemon: $NAME"
    stop_dashing
    start_dashing
  ;;
  status)
    status_of_proc -p $DAEMON $NAME
  ;;
  logs)
    tail -F $DASHING_DIR/log/thin.log
  ;;
  *)
  echo "Usage: "$1" {start|stop|restart|status}"
  exit 1
esac

exit 0

@joshmmo
Copy link

joshmmo commented Oct 23, 2013

I keep getting an error using your posted script plytro:

username@JoshUbuntu:/usr/bin$ sudo /etc/init.d/dashboard start

  • Starting daemon: dashing
    /usr/bin/env: ruby_executable_hooks: No such file or directory

Here is the section of my settings for the script:

NAME=dashing
DASHING_DIR=/home/username/onlinetraining_dashboard
PIDFILE="$DASHING_DIR/$NAME.pid"
DAEMON=/home/username/.rvm/gems/ruby-1.9.3-p448/bin/$NAME
GEM_HOME=/home/username/.rvm/gems/ruby-1.9.3-p448

DASHING_PORT=3030
DAEMON_OPTS="start -d -p $DASHING_PORT -P $PIDFILE --tag $NAME -D"

RUNUSER=username
RUNGROUP=username

I can start dashing just fine from the terminal myself. Any ideas why I am getting this error?

@zachar
Copy link

zachar commented Nov 14, 2013

"dashing /usr/bin/env: ruby_executable_hooks: No such file or directory" is an rvm issue. Script is executed by root and you installed rvm as other user (I suppose).

@absoutherland-zz
Copy link

you might try 'rvm repair wrappers', fixed it for me.

Also, I used some of the init scripts in here thus far to write:

https://gist.github.com/absoutherland/7554137

has a restart command, isnt dependent on start-stop-daemons, and the stop command isn't a killall

@dydys4444
Copy link

Hi everyone

Thanks for your jobs, this is really what I needed !

I just have a problem with history.yml. It seems it stops filling when I use the script. This problem has been described by another person: Shopify/dashing#244. The problem seems to be related to -d option on start.

Has anyone an idea on how to keep that file filling?

Thanks for your help

@emanuelstanciu
Copy link

I have another issue.. the script works fine when I run it from the terminal
however, as part of the init.d startup, it doesn't work..
so, if I do sudo service dashing start or sudo /etc/init.d/dashing start, I can successfully start the service
however, it doesn't start as part of the boot.. this is what I see in the boot.log file:
^[[31mbundler: command not found: thin^[[0m
^[[33mInstall missing gem executables with bundle install^[[0m
...done.

And it simply fails to start.. very frustrating, I look in every place to see why this is happening, without luck. I run this on an Ubuntu 14.04 OS.
If anyone can help, please let me know your thoughts on this issue.

@zwergengott
Copy link

How can I reverse it, so that it boots to the desktop again?

@dtburrows
Copy link

I was able to fix the "mbundler: command not found: thin" problem @Ariestar mentions above by adding the following Path variable to the @plytro bash script on the line after GEM_HOME:

PATH=$PATH:/usr/local:/usr/local/bin:/usr/local/sbin

@dannyhw
Copy link

dannyhw commented Oct 24, 2016

Plytros version worked for me, except for the status command which doesn't work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment