Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
cizz0r opened this issue Mar 14, 2023 · 3 comments

Comments

@cizz0r
Copy link

cizz0r commented Mar 14, 2023

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
Copy link
Author

cizz0r commented Mar 14, 2023

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.

@zonyitoo
Copy link
Collaborator

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

@zonyitoo
Copy link
Collaborator

zonyitoo commented Mar 15, 2023

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
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants