alist: init.d: use jshn to generate config file
Signed-off-by: sbwml <admin@cooluc.com>
This commit is contained in:
parent
baa383cec9
commit
41875850a8
@ -1,5 +1,7 @@
|
|||||||
#!/bin/sh /etc/rc.common
|
#!/bin/sh /etc/rc.common
|
||||||
|
|
||||||
|
. /usr/share/libubox/jshn.sh
|
||||||
|
|
||||||
START=99
|
START=99
|
||||||
USE_PROCD=1
|
USE_PROCD=1
|
||||||
PROG=/usr/bin/alist
|
PROG=/usr/bin/alist
|
||||||
@ -61,7 +63,6 @@ start_service() {
|
|||||||
[ $enabled -ne 1 ] && return 1
|
[ $enabled -ne 1 ] && return 1
|
||||||
mkdir -p $temp_dir $data_dir
|
mkdir -p $temp_dir $data_dir
|
||||||
[ "$ssl" -eq 1 ] && https_port=$port http_port="-1" || https_port="-1" http_port=$port
|
[ "$ssl" -eq 1 ] && https_port=$port http_port="-1" || https_port="-1" http_port=$port
|
||||||
[ "$log" -eq 1 ] && log=true || log=false
|
|
||||||
if [ -e /proc/uptime ]; then
|
if [ -e /proc/uptime ]; then
|
||||||
[ $(awk -F. '{print $1}' /proc/uptime) -lt "120" ] && delayed_start=$delayed_start || delayed_start=0
|
[ $(awk -F. '{print $1}' /proc/uptime) -lt "120" ] && delayed_start=$delayed_start || delayed_start=0
|
||||||
else
|
else
|
||||||
@ -74,52 +75,113 @@ start_service() {
|
|||||||
listen_addr=$lan_addr
|
listen_addr=$lan_addr
|
||||||
external_access="deny"
|
external_access="deny"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# mysql
|
# mysql
|
||||||
[ "$mysql" -eq 1 ] && database=mysql || database=sqlite3
|
[ "$mysql" -eq 1 ] && database=mysql || database=sqlite3
|
||||||
|
|
||||||
set_firewall
|
set_firewall
|
||||||
true > $temp_dir/alist.log
|
true > $temp_dir/alist.log
|
||||||
cat > $data_dir/config.json <<EOF
|
|
||||||
{
|
# init config
|
||||||
"force": false,
|
json_init
|
||||||
"site_url": "$site_url",
|
json_add_boolean "force" "1"
|
||||||
"cdn": "",
|
json_add_string "site_url" "$site_url"
|
||||||
"jwt_secret": "",
|
json_add_string "cdn" ""
|
||||||
"token_expires_in": $token_expires_in,
|
json_add_string "jwt_secret" ""
|
||||||
"database": {
|
json_add_int "token_expires_in" "$token_expires_in"
|
||||||
"type": "$database",
|
|
||||||
"host": "$mysql_host",
|
# database
|
||||||
"port": $mysql_port,
|
json_add_object 'database'
|
||||||
"user": "$mysql_username",
|
json_add_string "type" "$database"
|
||||||
"password": "$mysql_password",
|
json_add_string "host" "$mysql_host"
|
||||||
"name": "$mysql_database",
|
json_add_int "port" "$mysql_port"
|
||||||
"db_file": "$data_dir/data.db",
|
json_add_string "user" "$mysql_username"
|
||||||
"table_prefix": "x_",
|
json_add_string "password" "$mysql_password"
|
||||||
"ssl_mode": ""
|
json_add_string "name" "$mysql_database"
|
||||||
},
|
json_add_string "db_file" "$data_dir/data.db"
|
||||||
"scheme": {
|
json_add_string "table_prefix" "x_"
|
||||||
"address": "$listen_addr",
|
json_add_string "ssl_mode" ""
|
||||||
"http_port": $http_port,
|
json_add_string "dsn" ""
|
||||||
"https_port": $https_port,
|
json_close_object
|
||||||
"force_https": false,
|
|
||||||
"cert_file": "$ssl_cert",
|
# meilisearch
|
||||||
"key_file": "$ssl_key",
|
json_add_object "meilisearch"
|
||||||
"unix_file": "/var/run/alist.sock"
|
json_add_string "host" "http://localhost:7700"
|
||||||
},
|
json_add_string "api_key" ""
|
||||||
"temp_dir": "$temp_dir",
|
json_add_string "index_prefix" ""
|
||||||
"bleve_dir": "$data_dir/bleve",
|
json_close_object
|
||||||
"log": {
|
|
||||||
"enable": $log,
|
# scheme
|
||||||
"name": "$temp_dir/alist.log",
|
json_add_object "scheme"
|
||||||
"max_size": 10,
|
json_add_string "address" "$listen_addr"
|
||||||
"max_backups": 5,
|
json_add_int "http_port" "$http_port"
|
||||||
"max_age": 28,
|
json_add_int "https_port" "$https_port"
|
||||||
"compress": false
|
json_add_boolean "force_https" "0"
|
||||||
},
|
json_add_string "cert_file" "$ssl_cert"
|
||||||
"delayed_start": $delayed_start,
|
json_add_string "key_file" "$ssl_key"
|
||||||
"max_connections": $max_connections,
|
json_add_string "unix_file" "/var/run/alist.sock"
|
||||||
"tls_insecure_skip_verify": true
|
json_add_string "unix_file_perm" ""
|
||||||
}
|
json_close_object
|
||||||
EOF
|
|
||||||
|
json_add_string "temp_dir" "$temp_dir"
|
||||||
|
json_add_string "bleve_dir" "$data_dir/bleve"
|
||||||
|
json_add_string "dist_dir" ""
|
||||||
|
|
||||||
|
# log
|
||||||
|
json_add_object "log"
|
||||||
|
json_add_boolean "enable" "$log"
|
||||||
|
json_add_string "name" "$temp_dir/alist.log"
|
||||||
|
json_add_int "max_size" "10"
|
||||||
|
json_add_int "max_backups" "5"
|
||||||
|
json_add_int "max_age" "28"
|
||||||
|
json_add_boolean "compress" "0"
|
||||||
|
json_close_object
|
||||||
|
|
||||||
|
json_add_int "delayed_start" "$delayed_start"
|
||||||
|
json_add_int "max_connections" "$max_connections"
|
||||||
|
json_add_boolean "tls_insecure_skip_verify" "1"
|
||||||
|
|
||||||
|
# tasks
|
||||||
|
json_add_object "tasks"
|
||||||
|
json_add_object "download"
|
||||||
|
json_add_int "workers" "5"
|
||||||
|
json_add_int "max_retry" "1"
|
||||||
|
json_close_object
|
||||||
|
json_add_object "transfer"
|
||||||
|
json_add_int "workers" "5"
|
||||||
|
json_add_int "max_retry" "2"
|
||||||
|
json_close_object
|
||||||
|
json_add_object "upload"
|
||||||
|
json_add_int "workers" "5"
|
||||||
|
json_add_int "max_retry" "0"
|
||||||
|
json_close_object
|
||||||
|
json_add_object "copy"
|
||||||
|
json_add_int "workers" "5"
|
||||||
|
json_add_int "max_retry" "2"
|
||||||
|
json_close_object
|
||||||
|
json_close_object
|
||||||
|
|
||||||
|
# cors
|
||||||
|
json_add_object "cors"
|
||||||
|
json_add_array "allow_origins"
|
||||||
|
json_add_string "" "*"
|
||||||
|
json_close_array
|
||||||
|
json_add_array "allow_methods"
|
||||||
|
json_add_string "" "*"
|
||||||
|
json_close_array
|
||||||
|
json_add_array "allow_headers"
|
||||||
|
json_add_string "" "*"
|
||||||
|
json_close_array
|
||||||
|
json_close_object
|
||||||
|
|
||||||
|
# s3
|
||||||
|
json_add_object "s3"
|
||||||
|
json_add_boolean "enable" "0"
|
||||||
|
json_add_int "port" "5246"
|
||||||
|
json_add_boolean "ssl" "0"
|
||||||
|
json_close_object
|
||||||
|
|
||||||
|
json_dump > $data_dir/config.json
|
||||||
|
|
||||||
procd_open_instance
|
procd_open_instance
|
||||||
procd_set_param command $PROG
|
procd_set_param command $PROG
|
||||||
@ -140,9 +202,3 @@ stop_service() {
|
|||||||
external_access="deny"
|
external_access="deny"
|
||||||
set_firewall
|
set_firewall
|
||||||
}
|
}
|
||||||
|
|
||||||
reload_service() {
|
|
||||||
stop
|
|
||||||
sleep 1
|
|
||||||
start
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user