Skip to content

Instantly share code, notes, and snippets.

@cjhgo
Last active March 12, 2017 17:24
Show Gist options
  • Select an option

  • Save cjhgo/fc4f088d497f8e15fa6b5ca001f899df to your computer and use it in GitHub Desktop.

Select an option

Save cjhgo/fc4f088d497f8e15fa6b5ca001f899df to your computer and use it in GitHub Desktop.
the script to add tiddly as a init service
#!/bin/bash
#
#chkconfig: 35 99 99
#description: tiddlywiki
#
#reference
# https://www.rosehosting.com/blog/install-and-run-tiddlywiki-on-a-centoos-6-vps-using-nginx/
. /etc/rc.d/init.d/functions
USER="root"
DAEMON="/usr/bin/tiddlywiki"
#指定wiki目录,端口,重定向日志,2>&1
PARAMS="/data/nodejs/wiki --server 8001 >>/data/nodejs/logs/wiki.log 2>&1"
LOCK_FILE="/var/lock/subsys/tiddlywiki"
do_start()
{
if [ ! -f "$LOCK_FILE" ] ; then
echo -n $"Starting $SERVER: "
runuser -l "$USER" -c "$DAEMON $PARAMS &" && echo_success || echo_failure
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch $LOCK_FILE
else
echo "$SERVER is locked."
RETVAL=1
fi
}
do_stop()
{
echo -n $"Stopping $SERVER: "
pid=`ps -aefw | grep "$DAEMON $SERVER" | grep -v " grep " | awk '{print $2}'`
kill -9 $pid > /dev/null 2>&1 && echo_success || echo_failure
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f $LOCK_FILE
}
case "$1" in
start)
do_start
;;
stop)
do_stop
;;
restart)
do_stop
do_start
;;
*)
echo "Usage: $0 {start|stop|restart}"
RETVAL=1
esac
exit $RETVAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment