/debian/init.d/timekoin
Shell | 96 lines | 62 code | 23 blank | 11 comment | 10 complexity | 1b21da331e9e99c56cb2de26ad370e9c MD5 | raw file
- #! /bin/sh
- ### BEGIN INIT INFO
- # Provides: timekoin
- # Required-Start: $local_fs $remote_fs $named $network $time mysql
- # Required-Stop: $local_fs $remote_fs $named $network $time mysql
- # Default-Start: 2 3 4 5
- # Default-Stop: 0 1 6
- # Short-Description: timekoin cryptocurrency
- # Description: timekoin is a peer-to-peer cryptocurrency system
- ### END INIT INFO
- set -e
- test -x /usr/share/timekoin/ || exit 0
- . /lib/lsb/init-functions
- LANG=C
- export LANG
- PIDFILE="/var/run/timekoin.pid"
- NAME="timekoin"
- stop_timekoin() {
- log_daemon_msg "Stopping TimeKoin" "timekoin"
- start-stop-daemon --stop --pidfile "$PIDFILE" --quiet --oknodo
- status=$?
- if [ x"$status" = x"0" ]; then
- cd /usr/share/timekoin/public/
- echo "<?PHP
- include 'configuration.php';
- include 'function.php';
- if (mysql_connect(MYSQL_IP,MYSQL_USERNAME,MYSQL_PASSWORD) == FALSE) { exit; }
- if (mysql_select_db(MYSQL_DATABASE) == FALSE) { exit; }
- mysql_query(\"UPDATE \`main_loop_status\` SET \`field_data\` = '0' WHERE \`main_loop_status\`.\`field_name\` = 'main_heartbeat_active' LIMIT 1\");
- // Clear transaction queue to avoid unnecessary peer confusion
- mysql_query(\"TRUNCATE TABLE \`transaction_queue\`\");
- ?>" |su www-data -c php
- fi
- rm -f $PIDFILE
- log_end_msg $?
- }
- start_timekoin() {
- log_daemon_msg "Starting TimeKoin" "timekoin"
- cd /usr/share/timekoin/public/
- echo "<?PHP
- include 'configuration.php';
- include 'function.php';
- if (mysql_connect(MYSQL_IP,MYSQL_USERNAME,MYSQL_PASSWORD) == FALSE) { exit; }
- if (mysql_select_db(MYSQL_DATABASE) == FALSE) { exit; }
- // Database Initialization
- initialization_database();
- mysql_query(\"UPDATE \`main_loop_status\` SET \`field_data\` = '\" . time() . \"' WHERE \`main_loop_status\`.\`field_name\` = 'main_last_heartbeat' LIMIT 1\");
- // Set loop at active now
- mysql_query(\"UPDATE \`main_loop_status\` SET \`field_data\` = '1' WHERE \`main_loop_status\`.\`field_name\` = 'main_heartbeat_active' LIMIT 1\"); ?>" |su www-data -c php
- # Enable the main process
- f=/var/lib/timekoin/status.php.$(uuid)
- sed "s/defined* *[(][^)A-Za-z]TIMEKOIN_DISABLED[^)]*[)];/define(\"TIMEKOIN_DISABLED\", \"0\");/" </var/lib/timekoin/status.php >"$f"
- mv "$f" /var/lib/timekoin/status.php
- start-stop-daemon --chdir /usr/share/timekoin/public --start --chuid www-data --make-pidfile --pidfile "$PIDFILE" --nicelevel 2 --oknodo --background --startas /usr/bin/php -- main.php
- status=$?
- log_end_msg $?
- }
- case "$1" in
- start) start_timekoin ;;
- stop) stop_timekoin ;;
- restart|force-reload)
- stop_timekoin
- start_timekoin
- ;;
- status)
- start-stop-daemon --status --pidfile "$PIDFILE" --quiet
- ;;
- *)
- echo "Usage: $0 {start|stop|restart|force-reload|status}"
- exit 1
- ;;
- esac
- exit 0