Last active
August 29, 2015 14:02
-
-
Save enridaga/5d99eaa48114e11375d1 to your computer and use it in GitHub Desktop.
Virtuoso init.d script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
### BEGIN INIT INFO | |
# Provides: virtuoso7 | |
# Required-Start: $syslog $local_fs $network | |
# Should-Start: $remote_fs | |
# Required-Stop: $network | |
# Should-Stop: $remote_fs | |
# Default-Start: 3 4 5 | |
# Default-Stop: 0 1 2 6 | |
# Short-Description: Controls virtuoso7 data server | |
# Description: Controls virtuoso7 data server | |
### END INIT INFO | |
. /etc/init.d/functions | |
get_pid() { | |
[ -f "$pid_file" ] && cat "$pid_file" |sed -e 's/[^0-9]//g' | |
} | |
is_running() { | |
[ -f "$pid_file" ] && ps `get_pid` > /dev/null 2>&1 | |
} | |
# CONFIGURE HERE AS YOU LIKE | |
name="virtuoso7" | |
virtuoso_bin="/example/virtuoso/bin" | |
virtuoso_db="/example/virtuoso-db" | |
cmd="$virtuoso_bin/virtuoso-t" | |
pid_file="$virtuoso_db/virtuoso.lck" | |
# (END CONF) | |
case "$1" in | |
start) | |
if is_running; then | |
echo "Already started with pid "$(get_pid) | |
else | |
echo "Starting $name" | |
cd $virtuoso_db | |
daemon --user virtuoso $cmd | |
fi | |
;; | |
stop) | |
#kill $(get_pid) | |
if is_running; then | |
echo -n "Stopping $name.." | |
kill `get_pid` | |
for i in {1..10} | |
do | |
if ! is_running; then | |
break | |
fi | |
echo -n "." | |
sleep 1 | |
done | |
echo | |
if is_running; then | |
echo "Not stopped; may still be shutting down or shutdown may have failed" | |
exit 1 | |
else | |
echo "Stopped" | |
if [ -f "$pid_file" ]; then | |
rm "$pid_file" | |
fi | |
fi | |
else | |
echo "Not running" | |
fi | |
;; | |
reload) | |
/etc/init.d/$name stop | |
if is_running; then | |
echo "Unable to stop, will not attempt to start" | |
exit 1 | |
fi | |
/etc/init.d/$name start | |
;; | |
restart) | |
/etc/init.d/$name stop | |
sleep 1 | |
/etc/init.d/$name start | |
;; | |
status) | |
if is_running; then | |
echo "Running" | |
else | |
echo "Stopped" | |
exit 1 | |
fi | |
;; | |
*) | |
echo "Usage: $0 {start|stop|reload|restart|status}" | |
exit 1 | |
;; | |
esac | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment