PageRenderTime 54ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/debian/init.d/timekoin

https://bitbucket.org/rev22/timekoin
Shell | 96 lines | 62 code | 23 blank | 11 comment | 10 complexity | 1b21da331e9e99c56cb2de26ad370e9c MD5 | raw file
  1. #! /bin/sh
  2. ### BEGIN INIT INFO
  3. # Provides: timekoin
  4. # Required-Start: $local_fs $remote_fs $named $network $time mysql
  5. # Required-Stop: $local_fs $remote_fs $named $network $time mysql
  6. # Default-Start: 2 3 4 5
  7. # Default-Stop: 0 1 6
  8. # Short-Description: timekoin cryptocurrency
  9. # Description: timekoin is a peer-to-peer cryptocurrency system
  10. ### END INIT INFO
  11. set -e
  12. test -x /usr/share/timekoin/ || exit 0
  13. . /lib/lsb/init-functions
  14. LANG=C
  15. export LANG
  16. PIDFILE="/var/run/timekoin.pid"
  17. NAME="timekoin"
  18. stop_timekoin() {
  19. log_daemon_msg "Stopping TimeKoin" "timekoin"
  20. start-stop-daemon --stop --pidfile "$PIDFILE" --quiet --oknodo
  21. status=$?
  22. if [ x"$status" = x"0" ]; then
  23. cd /usr/share/timekoin/public/
  24. echo "<?PHP
  25. include 'configuration.php';
  26. include 'function.php';
  27. if (mysql_connect(MYSQL_IP,MYSQL_USERNAME,MYSQL_PASSWORD) == FALSE) { exit; }
  28. if (mysql_select_db(MYSQL_DATABASE) == FALSE) { exit; }
  29. mysql_query(\"UPDATE \`main_loop_status\` SET \`field_data\` = '0' WHERE \`main_loop_status\`.\`field_name\` = 'main_heartbeat_active' LIMIT 1\");
  30. // Clear transaction queue to avoid unnecessary peer confusion
  31. mysql_query(\"TRUNCATE TABLE \`transaction_queue\`\");
  32. ?>" |su www-data -c php
  33. fi
  34. rm -f $PIDFILE
  35. log_end_msg $?
  36. }
  37. start_timekoin() {
  38. log_daemon_msg "Starting TimeKoin" "timekoin"
  39. cd /usr/share/timekoin/public/
  40. echo "<?PHP
  41. include 'configuration.php';
  42. include 'function.php';
  43. if (mysql_connect(MYSQL_IP,MYSQL_USERNAME,MYSQL_PASSWORD) == FALSE) { exit; }
  44. if (mysql_select_db(MYSQL_DATABASE) == FALSE) { exit; }
  45. // Database Initialization
  46. initialization_database();
  47. mysql_query(\"UPDATE \`main_loop_status\` SET \`field_data\` = '\" . time() . \"' WHERE \`main_loop_status\`.\`field_name\` = 'main_last_heartbeat' LIMIT 1\");
  48. // Set loop at active now
  49. 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
  50. # Enable the main process
  51. f=/var/lib/timekoin/status.php.$(uuid)
  52. sed "s/defined* *[(][^)A-Za-z]TIMEKOIN_DISABLED[^)]*[)];/define(\"TIMEKOIN_DISABLED\", \"0\");/" </var/lib/timekoin/status.php >"$f"
  53. mv "$f" /var/lib/timekoin/status.php
  54. 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
  55. status=$?
  56. log_end_msg $?
  57. }
  58. case "$1" in
  59. start) start_timekoin ;;
  60. stop) stop_timekoin ;;
  61. restart|force-reload)
  62. stop_timekoin
  63. start_timekoin
  64. ;;
  65. status)
  66. start-stop-daemon --status --pidfile "$PIDFILE" --quiet
  67. ;;
  68. *)
  69. echo "Usage: $0 {start|stop|restart|force-reload|status}"
  70. exit 1
  71. ;;
  72. esac
  73. exit 0