From d02e336c19142403755b992a63303f7a47fe6824 Mon Sep 17 00:00:00 2001 From: cubic Date: Tue, 11 Jan 2022 16:17:34 +0800 Subject: [PATCH] fix(Service Script): add http gateway --- config.template.yaml | 2 +- misc/codefever-service-template | 78 +++++++++++++++++++++------------ misc/create_db.sh | 11 ++++- misc/db_data.sql | 15 ++++++- misc/install.sh | 9 +++- misc/modify_authorized_keys.php | 22 +++++++--- 6 files changed, 96 insertions(+), 41 deletions(-) mode change 100644 => 100755 misc/modify_authorized_keys.php diff --git a/config.template.yaml b/config.template.yaml index 62a2cbe..d5e149d 100755 --- a/config.template.yaml +++ b/config.template.yaml @@ -1,5 +1,5 @@ --- -host: localhost +host: http://localhost allowRegister: true email: name: CodeFever Community diff --git a/misc/codefever-service-template b/misc/codefever-service-template index fa3c975..1e01dba 100755 --- a/misc/codefever-service-template +++ b/misc/codefever-service-template @@ -2,66 +2,86 @@ # chkconfig: 2345 50 20 -BASE=/data/www/codefever-community/misc +BASE=/data/www/codefever-community PHP=/usr/local/php/bin/php -SRC=$BASE/modify_authorized_keys.php -SCRIPTNAME=$BASE/modify_authorized_keys + +SRC=$BASE/misc/modify_authorized_keys.php +SCRIPTNAME=$BASE/misc/modify_authorized_keys DESC="modify_authorized_keys_shell_running" PID=`ps -ef | grep -v awk | awk '/'$DESC'/{print $2}'` +HTTP_GATEWAY=$BASE/http-gateway/main +HTTP_GATEWAY_PID=`ps -ef | grep -v awk | awk '/'$HTTP_GATEWAY'/{print $2}'` + start() { - nohup $PHP $SRC $DESC > /dev/null 2>&1 & + if [[ -z "$PID" ]] ;then + echo "Starting service: SSH authorized key sync ..." + nohup $PHP $SRC $DESC > /dev/null 2>&1 & + fi + echo "Service started: SSH authorized key sync" + + if [[ -z "$HTTP_GATEWAY_PID" ]] ;then + echo "Starting service: SSH authorized key sync ..." + nohup $HTTP_GATEWAY > /dev/null 2>&1 & + fi + echo "Service started: HTTP gateway" + exit 0; } stop() { + echo "Shutting down service: SSH authorized key sync ..." for var in $PID do result=`kill -KILL $var 2>&1` if [[ -n "$result" ]] ;then echo $result - exit 1 fi done + echo "Service stopped: SSH authorized key sync" + + echo "Shutting down service: HTTP gateway ..." + for var in $HTTP_GATEWAY_PID + do + result=`kill -KILL $var 2>&1` + + if [[ -n "$result" ]] ;then + echo $result + fi + done + echo "Service stopped: HTTP gateway" + exit 0 } case "$1" in start) - if [[ -n "$PID" ]] ;then - echo "Has started!" - else - echo "Starting!" - echo "." - - start - - echo "Successfully started!" - fi + start ;; stop) - if [[ -n "$PID" ]] ;then - stop - - echo "Stopped running!" - else - echo "Not running!" - fi + stop ;; restart) + stop + start + ;; + + status) if [[ -n "$PID" ]] ;then - stop + echo "SSH authorized key sync: Running ..." + else + echo "SSH authorized key sync: Stopped ..." fi - echo "Restarting!" - echo "." - - start - - echo "Restarted!" + if [[ -n "$HTTP_GATEWAY_PID" ]] ;then + echo "HTTP gateway: Running ..." + else + echo "HTTP gateway: Stopped ..." + fi + exit 0 ;; *) diff --git a/misc/create_db.sh b/misc/create_db.sh index 8c3a529..997b615 100644 --- a/misc/create_db.sh +++ b/misc/create_db.sh @@ -12,7 +12,7 @@ DB_NAME=`cat ../env.yaml | grep db: | awk -F: '{ print $2 }' | sed 's/^\s*//'` -mysql -h"$DB_HOST" -P"$DB_PORT" -u"$DB_USER" -p"$DB_PASS" -e"CREATE DATABASE IF NOT EXISTS `$DB_NAME` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"; +mysql -h"$DB_HOST" -P"$DB_PORT" -u"$DB_USER" -p"$DB_PASS" -e"CREATE DATABASE IF NOT EXISTS $DB_NAME DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"; echo "Database <$DB_NAME> created!" @@ -23,3 +23,12 @@ echo 'Data structure created!' mysql -h"$DB_HOST" -P"$DB_PORT" -u"$DB_USER" -p"$DB_PASS" -D"$DB_NAME" -e"source db_data.sql"; echo 'Default data created!' + +echo 'Done!' + +echo -e "\n\n\n" + +echo '=== IMPORTANT NOTICE ===' +echo '1. Codefever community version is installed.' +echo '2. Type http://127.0.0.1 OR http:// to login.' +echo '3. Default login email: admin@codefever.cn, password: 123456 .' diff --git a/misc/db_data.sql b/misc/db_data.sql index 8531735..faf450a 100644 --- a/misc/db_data.sql +++ b/misc/db_data.sql @@ -1 +1,14 @@ -INSERT IGNORE INTO `cc_users` (`u_id`, `u_key`, `u_email`, `u_password`, `u_name`, `u_avatar`, `u_tel`, `u_calling_code`, `u_team`, `u_role`, `u_location`, `u_notification_status`, `u_register_ip`, `u_2fa`, `u_admin`, `u_created`, `u_updated`, `u_status`) VALUES(1, '00000000000000000000000000000000', 'admin@root', '14e1b600b1fd579f47433b88e8d85291', 'admin', '', '', 86, NULL, NULL, NULL, 0, '0.0.0.0', NULL, 1, '0001-01-01 00:00:00', '0001-01-01 00:00:00', 1); +INSERT IGNORE INTO `cc_users` (`u_id`, `u_key`, `u_email`, `u_password`, `u_name`, `u_avatar`, `u_tel`, `u_calling_code`, `u_team`, `u_role`, `u_location`, `u_notification_status`, `u_register_ip`, `u_2fa`, `u_admin`, `u_created`, `u_updated`, `u_status`) VALUES(1, '00000000000000000000000000000000', 'root@codefever.cn', '14e1b600b1fd579f47433b88e8d85291', 'codefever', '', '', 86, NULL, NULL, NULL, 0, '0.0.0.0', NULL, 1, '0001-01-01 00:00:00', '0001-01-01 00:00:00', 1); + +INSERT INTO `cc_users` (`u_id`, `u_key`, `u_email`, `u_password`, `u_name`, `u_avatar`, `u_tel`, `u_calling_code`, `u_team`, `u_role`, `u_location`, `u_notification_status`, `u_register_ip`, `u_2fa`, `u_admin`, `u_created`, `u_updated`, `u_status`) VALUES +(0, '26c20714af8bc20aa85be657a5170e71', 'test2@pgyer.com', '825c4adf01f22a52f3a191af855bff5f', 'test2', 'd24d2281d6354ec58b27167fe21a6e1e', NULL, 86, NULL, NULL, NULL, 0, '0.0.0.0', NULL, 0, '2022-01-01 00:00:00', '0000-00-00 00:00:00', 4), +(0, 'f4a9c54adef17599d4f709a1167f0fcd', 'test@pgyer.com', '14e1b600b1fd579f47433b88e8d85291', 'test', 'e0a35aac9dd051168aeaf073a54e3c11', NULL, 86, NULL, NULL, NULL, 0, '0.0.0.0', NULL, 0, '2022-01-01 00:00:00', '0000-00-00 00:00:00', 4); + +INSERT INTO `cc_ssh_keys` (`sk_key`, `u_key`, `sk_name`, `sk_key_type`, `sk_key_hash`, `sk_key_data`, `sk_created`, `sk_updated`, `sk_deleted`, `sk_status`) VALUES +('f90613f05b53e9bc080f01e2a465d8e6', 'f4a9c54adef17599d4f709a1167f0fcd', 'test@pgyer.com', 'ssh-rsa', 'e69cbde8123c9e57657c1aa0067166a3', 'AAAAB3NzaC1yc2EAAAADAQABAAABgQDHTyC4jcWdgDEeF6qeAsV0hmkb0uetkwQj3aqXIFnUgMudD8QjQ/dEFNQtYB0Fc1H3CAh3O4NTiWF7cGjj9RuSdAlB4hH96/UzwNraBrczyib1xw1H5VxuqRxdz/GBPnRJUZ84mzyJJuPBsh15lEclVKtdhNr0rNfghQkPaxcOBn3yH1JCOyCBbwtA23CGc2XmT2j8If3lkyoebmZ/fg5Kc8pNu2cZVFyAADgl7OjhXamU8FcYD3ZZ/x0WcUi28kiuAy57p5ZQS9+zqUT8zHXqz553YXreglV/Qp1jm/6g16yliuCeFTtRJ6eL59mqfkUIlXAUkE6bnRrWettoLfyBE56lRxwC5tlBvvYcP9346opb85QxXM1ixj8/CzHZwG38KnKEq6rKbKLUTum3/fRPsuU+GwgKs7/q1sZkctT9FJA1qGh0SseXlV7nWiQ8Hz+HhE/8TE8jwBXyzY1IBes2K4j7SZKP1a2qPbOp9HvxxLPNdhQOZ8F2ux/NIARrCU8=', '2022-01-01 00:00:00', '0000-00-00 00:00:00', NULL, 1); + +INSERT INTO `cc_groups` (`g_key`, `u_key`, `g_type`, `g_display_name`, `g_name`, `g_description`, `g_avatar`, `g_created`, `g_updated`, `g_deleted`, `g_status`) VALUES +('e6508c1a66e86f697c96bdffb30c1ae3', 'f4a9c54adef17599d4f709a1167f0fcd', 2, 'codefever', 'codefever', '', '', '2022-01-01 00:00:00', '0000-00-00 00:00:00', NULL, 1); + +INSERT INTO `cc_repositories` (`r_key`, `u_key`, `g_key`, `r_fork_r_key`, `r_display_name`, `r_name`, `r_path`, `r_description`, `r_avatar`, `r_default_branch_name`, `r_created`, `r_updated`, `r_deleted`, `r_status`) VALUES +('2f941aef39bc8a048da55dd28c678655', 'f4a9c54adef17599d4f709a1167f0fcd', 'e6508c1a66e86f697c96bdffb30c1ae3', NULL, 'codefever', 'codefever', '/7b56eed88bda864c6e5ae1540549f8ab', 'Codefever community test repository', NULL, NULL, '2022-01-01 00:00:00', '0000-00-00 00:00:00', NULL, 1); diff --git a/misc/install.sh b/misc/install.sh index cf46203..96a42f8 100644 --- a/misc/install.sh +++ b/misc/install.sh @@ -38,9 +38,14 @@ cp ../env.template.yaml ../env.yaml echo 'env files generated!' mkdir ../application/logs -chmod -R 0777 ../application/logs +chmod -R www:www ../application/logs -echo 'Log directory created!' +chmod -R 0777 ../git-storage + +mkdir ../storage +chown -R www:www ../storage + +echo 'Enssential directory created!' echo 'Loading composer libraries: (Just Press Enter Key!)' diff --git a/misc/modify_authorized_keys.php b/misc/modify_authorized_keys.php old mode 100644 new mode 100755 index fb3395d..fca6328 --- a/misc/modify_authorized_keys.php +++ b/misc/modify_authorized_keys.php @@ -1,7 +1,15 @@