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
|
||||
|
||||
. /usr/share/libubox/jshn.sh
|
||||
|
||||
START=99
|
||||
USE_PROCD=1
|
||||
PROG=/usr/bin/alist
|
||||
@ -61,7 +63,6 @@ start_service() {
|
||||
[ $enabled -ne 1 ] && return 1
|
||||
mkdir -p $temp_dir $data_dir
|
||||
[ "$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
|
||||
[ $(awk -F. '{print $1}' /proc/uptime) -lt "120" ] && delayed_start=$delayed_start || delayed_start=0
|
||||
else
|
||||
@ -74,52 +75,113 @@ start_service() {
|
||||
listen_addr=$lan_addr
|
||||
external_access="deny"
|
||||
fi
|
||||
|
||||
# mysql
|
||||
[ "$mysql" -eq 1 ] && database=mysql || database=sqlite3
|
||||
|
||||
set_firewall
|
||||
true > $temp_dir/alist.log
|
||||
cat > $data_dir/config.json <<EOF
|
||||
{
|
||||
"force": false,
|
||||
"site_url": "$site_url",
|
||||
"cdn": "",
|
||||
"jwt_secret": "",
|
||||
"token_expires_in": $token_expires_in,
|
||||
"database": {
|
||||
"type": "$database",
|
||||
"host": "$mysql_host",
|
||||
"port": $mysql_port,
|
||||
"user": "$mysql_username",
|
||||
"password": "$mysql_password",
|
||||
"name": "$mysql_database",
|
||||
"db_file": "$data_dir/data.db",
|
||||
"table_prefix": "x_",
|
||||
"ssl_mode": ""
|
||||
},
|
||||
"scheme": {
|
||||
"address": "$listen_addr",
|
||||
"http_port": $http_port,
|
||||
"https_port": $https_port,
|
||||
"force_https": false,
|
||||
"cert_file": "$ssl_cert",
|
||||
"key_file": "$ssl_key",
|
||||
"unix_file": "/var/run/alist.sock"
|
||||
},
|
||||
"temp_dir": "$temp_dir",
|
||||
"bleve_dir": "$data_dir/bleve",
|
||||
"log": {
|
||||
"enable": $log,
|
||||
"name": "$temp_dir/alist.log",
|
||||
"max_size": 10,
|
||||
"max_backups": 5,
|
||||
"max_age": 28,
|
||||
"compress": false
|
||||
},
|
||||
"delayed_start": $delayed_start,
|
||||
"max_connections": $max_connections,
|
||||
"tls_insecure_skip_verify": true
|
||||
}
|
||||
EOF
|
||||
|
||||
# init config
|
||||
json_init
|
||||
json_add_boolean "force" "1"
|
||||
json_add_string "site_url" "$site_url"
|
||||
json_add_string "cdn" ""
|
||||
json_add_string "jwt_secret" ""
|
||||
json_add_int "token_expires_in" "$token_expires_in"
|
||||
|
||||
# database
|
||||
json_add_object 'database'
|
||||
json_add_string "type" "$database"
|
||||
json_add_string "host" "$mysql_host"
|
||||
json_add_int "port" "$mysql_port"
|
||||
json_add_string "user" "$mysql_username"
|
||||
json_add_string "password" "$mysql_password"
|
||||
json_add_string "name" "$mysql_database"
|
||||
json_add_string "db_file" "$data_dir/data.db"
|
||||
json_add_string "table_prefix" "x_"
|
||||
json_add_string "ssl_mode" ""
|
||||
json_add_string "dsn" ""
|
||||
json_close_object
|
||||
|
||||
# meilisearch
|
||||
json_add_object "meilisearch"
|
||||
json_add_string "host" "http://localhost:7700"
|
||||
json_add_string "api_key" ""
|
||||
json_add_string "index_prefix" ""
|
||||
json_close_object
|
||||
|
||||
# scheme
|
||||
json_add_object "scheme"
|
||||
json_add_string "address" "$listen_addr"
|
||||
json_add_int "http_port" "$http_port"
|
||||
json_add_int "https_port" "$https_port"
|
||||
json_add_boolean "force_https" "0"
|
||||
json_add_string "cert_file" "$ssl_cert"
|
||||
json_add_string "key_file" "$ssl_key"
|
||||
json_add_string "unix_file" "/var/run/alist.sock"
|
||||
json_add_string "unix_file_perm" ""
|
||||
json_close_object
|
||||
|
||||
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_set_param command $PROG
|
||||
@ -140,9 +202,3 @@ stop_service() {
|
||||
external_access="deny"
|
||||
set_firewall
|
||||
}
|
||||
|
||||
reload_service() {
|
||||
stop
|
||||
sleep 1
|
||||
start
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user