shadowsocks/shadowsocks-rust

Is there a guide on how to start and configure the config.json when installed via snap?

cizz0r opened this issue · 3 comments

cizz0r commented

I just can't get it to working using this .service file I created.

[Unit]
Description=Shadowsocks-Libev Custom Server Service for %I
Documentation=manss-server(1)
After=network-online.target

[Service]
Type=simple
ExecStart=/usr/bin/snap run shadowsocks-rust.ss-server -c /var/snap/shadowsocks-rust/common/etc/shadowsocks-rust/config.json

[Install]
WantedBy=multi-user.target
cizz0r commented

Screenshot 2023-03-14 at 23 03 54

And where can I modify the normal systemd file so that it doesn't overwrite? I'd like to add my config parameter permanently.

Not sure. If you finally find the answer, please help to improve the README.md.

passthrough:
layout:
/etc/shadowsocks-rust:
bind: $SNAP_COMMON/etc/shadowsocks-rust

As you can see in the snapcraft.yaml, it passthroughs $SNAP_COMMON/etc/shadowsocks-rust to /etc/shadowsocks-rust.

https://snapcraft.io/docs/environment-variables

According to document, $SNAP_COMMON is: SNAP_COMMON=/var/snap/<snap>/common, which in this case, /var/snap/shadowsocks-rust/common.

So you could put the configuration file to /var/snap/shadowsocks-rust/common/etc/shadowsocks-rust/config.json.

Here is the default search path:

/// Default configuration file path
pub fn get_default_config_path() -> Option<PathBuf> {
// config.json in the current working directory ($PWD)
if let Ok(mut path) = env::current_dir() {
path.push("config.json");
if path.exists() {
return Some(path);
}
} else {
// config.json in the current working directory (relative path)
let relative_path = PathBuf::from("config.json");
if relative_path.exists() {
return Some(relative_path);
}
}
// System standard directories
if let Some(project_dirs) = ProjectDirs::from("org", "shadowsocks", "shadowsocks-rust") {
// Linux: $XDG_CONFIG_HOME/shadowsocks-rust/config.json
// $HOME/.config/shadowsocks-rust/config.json
// macOS: $HOME/Library/Application Support/org.shadowsocks.shadowsocks-rust/config.json
// Windows: {FOLDERID_RoamingAppData}/shadowsocks/shadowsocks-rust/config/config.json
let mut config_path = project_dirs.config_dir().to_path_buf();
config_path.push("config.json");
if config_path.exists() {
return Some(config_path);
}
}
// UNIX systems, XDG Base Directory
// https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
#[cfg(unix)]
if let Ok(base_directories) = xdg::BaseDirectories::with_prefix("shadowsocks-rust") {
// $XDG_CONFIG_HOME/shadowsocks-rust/config.json
// for dir in $XDG_CONFIG_DIRS; $dir/shadowsocks-rust/config.json
if let Some(config_path) = base_directories.find_config_file("config.json") {
return Some(config_path);
}
}
// UNIX global configuration file
#[cfg(unix)]
{
let global_config_path = Path::new("/etc/shadowsocks-rust/config.json");
if global_config_path.exists() {
return Some(global_config_path.to_path_buf());
}
}
None
}