Code Monkey home page Code Monkey logo

Comments (7)

Litchi2049 avatar Litchi2049 commented on May 25, 2024

I find sing-box -h output says: the flag --directory set working directory.

% sing-box -h
Usage:
  sing-box [command]

Available Commands:
  check       Check configuration
  completion  Generate the autocompletion script for the specified shell
  format      Format configuration
  generate    Generate things
  geoip       GeoIP tools
  geosite     Geosite tools
  help        Help about any command
  merge       Merge configurations
  rule-set    Manage rule sets
  run         Run service
  tools       Experimental tools
  version     Print current version of sing-box

Flags:
  -c, --config stringArray             set configuration file path
  -C, --config-directory stringArray   set configuration directory path
  -D, --directory string               set working directory
      --disable-color                  disable color output
  -h, --help                           help for sing-box

Use "sing-box [command] --help" for more information about a command.

Without this flag, sing-box will use current dir as working directory if using cmd start, however, when use plist, it causes sing-box couldn't find or create working dir

I add the flag to the plist:

IMAGE 2024-04-13 21:28:03

Then sudo brew service restart sing-box works as expect, success starts sing-box

And sudo brew services show sing-box started

from homebrew-core.

Litchi2049 avatar Litchi2049 commented on May 25, 2024

I don't know why I can't pass commit styles check... Someone can help?

from homebrew-core.

Litchi2049 avatar Litchi2049 commented on May 25, 2024

I don't know why I can't pass commit styles check... Someone can help?

I found out: 1st the title is too long, 2nd after reopen PR, commits aren't squashed to one

from homebrew-core.

Jerry1144 avatar Jerry1144 commented on May 25, 2024

I think there's a relevant key for this, and macOS actually recommends using it.

From service block methods there is a working_dir method, which translates into <key>WorkingDirectory</key><string>path/to/working/directory</string>. Can you try using this and see if it works as intended?

<key>ProgramArguments</key>
<array>
  <string>/usr/local/opt/sing-box/bin/sing-box</string>
  <string>run</string>
  <string>--config</string>
  <string>/usr/local/etc/sing-box/config.ison</string>
</array>
<key>WorkingDirectory</key>
<string>/usr/local/etc/sing-box</string>

If it works, then an easier fix would be:

service do
  [...]
  working_dir etc/"sing-box"
end

EDIT: obviously it's working_dir var/"lib/sing-box", and that folder needs to be created with (var/"lib/sing-box").mkpath during install because launchd doesn't create that automatically.

from homebrew-core.

Litchi2049 avatar Litchi2049 commented on May 25, 2024

It works

litchi@LitchideMacBookAir 1.8.11 % launchctl list homebrew.mxcl.sing-box
{
	"LimitLoadToSessionType" = "Aqua";
	"Label" = "homebrew.mxcl.sing-box";
	"OnDemand" = false;
	"LastExitStatus" = 256;
	"Program" = "/usr/local/opt/sing-box/bin/sing-box";
	"ProgramArguments" = (
		"/usr/local/opt/sing-box/bin/sing-box";
		"run";
		"--config";
		"/usr/local/etc/sing-box/config.json";
	);
};
litchi@LitchideMacBookAir 1.8.11 % sudo brew services
Name     Status User File
sing-box none   root
litchi@LitchideMacBookAir 1.8.11 % cat homebrew.mxcl.sing-box.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>KeepAlive</key>
	<true/>
	<key>Label</key>
	<string>homebrew.mxcl.sing-box</string>
	<key>LimitLoadToSessionType</key>
	<array>
		<string>Aqua</string>
		<string>Background</string>
		<string>LoginWindow</string>
		<string>StandardIO</string>
		<string>System</string>
	</array>
	<key>ProgramArguments</key>
	<array>
		<string>/usr/local/opt/sing-box/bin/sing-box</string>
		<string>run</string>
		<string>--config</string>
		<string>/usr/local/etc/sing-box/config.json</string>
	</array>
        <key>WorkingDirectory</key>
        <string>/usr/local/etc/sing-box</string>
	<key>RunAtLoad</key>
	<true/>
</dict>
</plist>
litchi@LitchideMacBookAir 1.8.11 % sudo brew services restart sing-box
Warning: Taking root:admin ownership of some sing-box paths:
  /usr/local/Cellar/sing-box/1.8.11/bin
  /usr/local/Cellar/sing-box/1.8.11/bin/sing-box
  /usr/local/opt/sing-box
  /usr/local/opt/sing-box/bin
  /usr/local/var/homebrew/linked/sing-box
This will require manual removal of these paths using `sudo rm` on
brew upgrade/reinstall/uninstall.
Warning: sing-box must be run as non-root to start at user login!
==> Successfully started `sing-box` (label: homebrew.mxcl.sing-box)
litchi@LitchideMacBookAir 1.8.11 % launchctl list homebrew.mxcl.sing-box
{
	"LimitLoadToSessionType" = "Aqua";
	"Label" = "homebrew.mxcl.sing-box";
	"OnDemand" = false;
	"LastExitStatus" = 256;
	"PID" = 20795;
	"Program" = "/usr/local/opt/sing-box/bin/sing-box";
	"ProgramArguments" = (
		"/usr/local/opt/sing-box/bin/sing-box";
		"run";
		"--config";
		"/usr/local/etc/sing-box/config.json";
	);
};
litchi@LitchideMacBookAir 1.8.11 % sudo brew services
Name     Status  User File
sing-box started root /Library/LaunchDaemons/homebrew.mxcl.sing-box.plist
litchi@LitchideMacBookAir 1.8.11 %

from homebrew-core.

Litchi2049 avatar Litchi2049 commented on May 25, 2024

So, which one is better😂

from homebrew-core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.