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

Detached mode and logs #8

Closed
Morethanevil opened this issue May 24, 2023 · 4 comments
Closed

Detached mode and logs #8

Morethanevil opened this issue May 24, 2023 · 4 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@Morethanevil
Copy link
Contributor

First: Thanks for this great program!

I am testing zoraxy inside LXC and I would like to know if there is any detached mode? At the moment I use screen to detach zoraxy output. I can not leave the CLI open the whole time.

It would be cool to start zoraxy with a "-d" argument in the background.

Then I would like to know if there are any logs?

@Morethanevil Morethanevil added the enhancement New feature or request label May 24, 2023
@tobychui
Copy link
Owner

"-d" argument seems like an interesting idea. However, adding this might bring some issue with Windows compatibility.
For my linux setups, I am using systemd for this purpose. Here is how I did it.

First, you would like to create a start.sh file next to your zoraxy binary. Assuming your binary file is located at /home/user/zoraxy/src/zoraxy

cd /home/user/zoraxy/src/zoraxy
nano start.sh

Put the following lines into start.sh, save and exit

#!/bin/bash
sudo ./zoraxy

Then assign the correct permission to the start script

sudo chmod 775 ./start.sh 

Next, you can add it to systemd service with the following commands

cd /etc/systemd/system/
sudo systemctl enable systemd-networkd.service systemd-networkd-wait-online.service
sudo nano zoraxy.service

In the service file, fill in the following info

[Unit]
Description=Zoraxy Reverse Proxy Server
After=systemd-networkd-wait-online.service
Wants=systemd-networkd-wait-online.service

[Service]
Type=simple
ExecStartPre=/bin/sleep 10
WorkingDirectory=/home/user/zoraxy/src/
ExecStart=/bin/bash /home/user/zoraxy/src/start.sh

Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target

Lastly, enable and start the systemd service

sudo systemctl enable zoraxy
sudo systemctl start zoraxy

Then it should be running as a valid daemon which will start following your server (or container) startup. As I am no expert in LXC, I can only provide you answer under normal Linux (Debian) based installation. If you have issues using systemd in your container, I guess you might need to seek help from the developer who provided the container / docker configs.

@Morethanevil
Copy link
Contributor Author

Morethanevil commented May 24, 2023

Okay now it is running with systemd. Did not think about systemd :D I needed to modify your scripts and now it runs just fine. For quick testing a "-d" would still be great :)
Please add one of the solutions to the docs.

Here are my steps:

  1. Create start.sh in the zoraxy folder with:

nano start.sh

Put in those lines

#!/bin/bash
./zoraxy -port=:8000
  1. make executable with

chmod +x start.sh

  1. Now create systemd-service with

sudo nano /etc/systemd/system/zoraxy.service

Put in following lines:

[Unit]
Description=Zoraxy Reverse Proxy Server
After=network-online.target #waits for network to be online
Wants=network-online.target

[Service]
Type=simple

User=root   #no sudo required in start.sh
Group=root
WorkingDirectory=/zoraxy/src/    #folder where zoraxy is
ExecStart=/bin/bash /zoraxy/src/start.sh     #absolute path for start.sh

[Install]
WantedBy=multi-user.target
  1. Start and enable autostart with:

sudo systemctl enable --now zoraxy.service

Now status and logs can be displayed with:

sudo systemctl status zoraxy

Logs-files would still be great, but thanks for the help with autostart
A sidenote for LXC-Users: After login as root the working directory is not /zoraxy/src but /root/zoraxy/src
(/root/ is the home of root user) Tested with LXC Ubuntu 22.04

@TheTaran
Copy link

TheTaran commented May 26, 2023

Thanks for that grate tool! 👍🏻

A little fix. :)

Description=Zoraxy Reverse Proxy Server
#waits for network to be online
After=network-online.target
Wants=network-online.target

[Service]
Type=simple

#no sudo required in start.sh
User=root   
Group=root

#folder where zoraxy is
WorkingDirectory=/zoraxy/src/    
#absolute path for start.sh
ExecStart=/bin/bash /zoraxy/src/start.sh     

[Install]
WantedBy=multi-user.target

@tobychui tobychui added the good first issue Good for newcomers label May 29, 2023
@Korenchkin
Copy link

Korenchkin commented Jun 12, 2024

init.d script for those who want (some thin lxc images still use rc.d - alpine for example)
just a basic quick and dirty,restart on crash(should work),no /sys.db but /opt/zoraxy/sys.db ...could be better,but for me directory=/opt/zoraxy as a chdir parameter for supervisor did not work,so hacked a cd and that worked

#!/sbin/openrc-run

name="zoraxy"
supervisor="supervise-daemon"
#directory="/opt/zoraxy"
command="./zoraxy_linux_amd64"
command_args="-port=:8000"
pidfile="/run/$SVCNAME.pid"

depend() {
        need net
        use dns
}

start_pre()
{
        cd /opt/zoraxy
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants