mirror of
https://github.com/rustdesk/rustdesk.git
synced 2024-11-23 19:49:05 +08:00
wayland: remove user service
Signed-off-by: fufesou <shuanglongchen@yeah.net>
This commit is contained in:
parent
9385e95b4e
commit
c48ed06d93
6
build.py
6
build.py
@ -161,8 +161,6 @@ def build_flutter_deb(version):
|
||||
'cp -r build/linux/x64/release/bundle/* tmpdeb/usr/lib/rustdesk/')
|
||||
os.system(
|
||||
'cp ../res/rustdesk.service tmpdeb/usr/share/rustdesk/files/systemd/')
|
||||
os.system(
|
||||
'cp ../res/rustdesk.service.user tmpdeb/usr/share/rustdesk/files/systemd/')
|
||||
os.system(
|
||||
'cp ../res/128x128@2x.png tmpdeb/usr/share/rustdesk/files/rustdesk.png')
|
||||
os.system(
|
||||
@ -177,7 +175,6 @@ def build_flutter_deb(version):
|
||||
generate_control_file(version)
|
||||
os.system('cp -a ../res/DEBIAN/* tmpdeb/DEBIAN/')
|
||||
md5_file('usr/share/rustdesk/files/systemd/rustdesk.service')
|
||||
md5_file('usr/share/rustdesk/files/systemd/rustdesk.service.user')
|
||||
os.system('dpkg-deb -b tmpdeb rustdesk.deb;')
|
||||
|
||||
os.system('/bin/rm -rf tmpdeb/')
|
||||
@ -331,8 +328,6 @@ def main():
|
||||
os.system('mkdir -p tmpdeb/usr/share/rustdesk/files/systemd/')
|
||||
os.system(
|
||||
'cp res/rustdesk.service tmpdeb/usr/share/rustdesk/files/systemd/')
|
||||
os.system(
|
||||
'cp res/rustdesk.service.user tmpdeb/usr/share/rustdesk/files/systemd/')
|
||||
os.system(
|
||||
'cp res/128x128@2x.png tmpdeb/usr/share/rustdesk/files/rustdesk.png')
|
||||
os.system(
|
||||
@ -345,7 +340,6 @@ def main():
|
||||
os.system('mv tmpdeb/usr/bin/rustdesk tmpdeb/usr/lib/rustdesk/')
|
||||
os.system('cp libsciter-gtk.so tmpdeb/usr/lib/rustdesk/')
|
||||
md5_file('usr/share/rustdesk/files/systemd/rustdesk.service')
|
||||
md5_file('usr/share/rustdesk/files/systemd/rustdesk.service.user')
|
||||
md5_file('usr/lib/rustdesk/libsciter-gtk.so')
|
||||
os.system('dpkg-deb -b tmpdeb rustdesk.deb; /bin/rm -rf tmpdeb/')
|
||||
os.rename('rustdesk.deb', 'rustdesk-%s.deb' % version)
|
||||
|
@ -19,14 +19,5 @@ if [ "$1" = configure ]; then
|
||||
systemctl daemon-reload
|
||||
systemctl enable rustdesk
|
||||
systemctl start rustdesk
|
||||
|
||||
cp /usr/share/rustdesk/files/systemd/rustdesk.service.user /usr/lib/systemd/user/rustdesk.service
|
||||
ubuntuVersion=$(grep -oP 'VERSION_ID="\K[\d]+' /etc/os-release | bc -l)
|
||||
waylandSupportVersion=21
|
||||
if [ "$ubuntuVersion" -ge "$waylandSupportVersion" ]
|
||||
then
|
||||
curUser=$(who | awk '{print $1}' | head -1)
|
||||
systemctl --machine=${curUser}@.host --user daemon-reload
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
@ -7,13 +7,6 @@ case $1 in
|
||||
INITSYS=$(ls -al /proc/1/exe | awk -F' ' '{print $NF}' | awk -F'/' '{print $NF}')
|
||||
if [ "systemd" == "${INITSYS}" ]; then
|
||||
service rustdesk stop || true
|
||||
|
||||
serverUser=$(ps -ef | grep -E 'rustdesk +--server' | awk '{print $1}' | head -1)
|
||||
if [ "$serverUser" != "" ] && [ "$serverUser" != "root" ]
|
||||
then
|
||||
systemctl --machine=${serverUser}@.host --user stop rustdesk || true
|
||||
fi
|
||||
|
||||
sleep 1
|
||||
rm -rf /usr/bin/libsciter-gtk.so
|
||||
fi
|
||||
|
@ -11,7 +11,9 @@ case $1 in
|
||||
|
||||
systemctl stop rustdesk || true
|
||||
systemctl disable rustdesk || true
|
||||
rm /etc/systemd/system/rustdesk.service /usr/lib/systemd/system/rustdesk.service || true
|
||||
|
||||
# workaround temp dev build between 1.1.9 and 1.2.0
|
||||
serverUser=$(ps -ef | grep -E 'rustdesk +--server' | awk '{print $1}' | head -1)
|
||||
ubuntuVersion=$(grep -oP 'VERSION_ID="\K[\d]+' /etc/os-release | bc -l)
|
||||
waylandSupportVersion=21
|
||||
@ -19,8 +21,7 @@ case $1 in
|
||||
then
|
||||
systemctl --machine=${serverUser}@.host --user stop rustdesk || true
|
||||
fi
|
||||
|
||||
rm /etc/systemd/system/rustdesk.service /usr/lib/systemd/system/rustdesk.service /usr/lib/systemd/user/rustdesk.service || true
|
||||
rm /usr/lib/systemd/user/rustdesk.service >/dev/null 2>/dev/null || true
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
@ -1,15 +0,0 @@
|
||||
[Unit]
|
||||
Description=RustDesk user service (--server)
|
||||
|
||||
[Service]
|
||||
Type=simple
|
||||
ExecStart=/usr/bin/rustdesk --server
|
||||
PIDFile=/run/rustdesk.user.pid
|
||||
KillMode=mixed
|
||||
TimeoutStopSec=30
|
||||
LimitNOFILE=100000
|
||||
Restart=on-failure
|
||||
RestartSec=3
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
@ -161,45 +161,6 @@ fn start_uinput_service() {
|
||||
});
|
||||
}
|
||||
|
||||
fn try_start_user_service(username: &str) {
|
||||
if username == "" || username == "root" {
|
||||
return;
|
||||
}
|
||||
|
||||
if let Ok(mut cur_username) =
|
||||
run_cmds("ps -ef | grep -E 'rustdesk +--server' | awk '{print $1}' | head -1".to_owned())
|
||||
{
|
||||
cur_username = cur_username.trim().to_owned();
|
||||
if cur_username != "root" && cur_username != username {
|
||||
let _ = run_cmds(format!(
|
||||
"systemctl --machine={}@.host --user stop rustdesk",
|
||||
&cur_username
|
||||
));
|
||||
} else if cur_username == username {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
let _ = run_cmds(format!(
|
||||
"systemctl --machine={}@.host --user start rustdesk",
|
||||
username
|
||||
));
|
||||
}
|
||||
|
||||
fn try_stop_user_service() {
|
||||
if let Ok(mut username) =
|
||||
run_cmds("ps -ef | grep -E 'rustdesk +--server' | awk '{print $1}' | head -1".to_owned())
|
||||
{
|
||||
username = username.trim().to_owned();
|
||||
if username != "root" {
|
||||
let _ = run_cmds(format!(
|
||||
"systemctl --machine={}@.host --user stop rustdesk",
|
||||
&username
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn stop_server(server: &mut Option<std::process::Child>) {
|
||||
if let Some(mut ps) = server.take() {
|
||||
allow_err!(ps.kill());
|
||||
@ -214,13 +175,106 @@ fn stop_server(server: &mut Option<std::process::Child>) {
|
||||
}
|
||||
}
|
||||
|
||||
fn set_x11_env(uid: &str) {
|
||||
log::info!("uid of seat0: {}", uid);
|
||||
let gdm = format!("/run/user/{}/gdm/Xauthority", uid);
|
||||
let mut auth = get_env_tries("XAUTHORITY", uid, 10);
|
||||
if auth.is_empty() {
|
||||
auth = if std::path::Path::new(&gdm).exists() {
|
||||
gdm
|
||||
} else {
|
||||
let username = get_active_username();
|
||||
if username == "root" {
|
||||
format!("/{}/.Xauthority", username)
|
||||
} else {
|
||||
let tmp = format!("/home/{}/.Xauthority", username);
|
||||
if std::path::Path::new(&tmp).exists() {
|
||||
tmp
|
||||
} else {
|
||||
format!("/var/lib/{}/.Xauthority", username)
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
let mut d = get_env("DISPLAY", uid);
|
||||
if d.is_empty() {
|
||||
d = get_display();
|
||||
}
|
||||
if d.is_empty() {
|
||||
d = ":0".to_owned();
|
||||
}
|
||||
d = d.replace(&whoami::hostname(), "").replace("localhost", "");
|
||||
log::info!("DISPLAY: {}", d);
|
||||
log::info!("XAUTHORITY: {}", auth);
|
||||
std::env::set_var("XAUTHORITY", auth);
|
||||
std::env::set_var("DISPLAY", d);
|
||||
}
|
||||
|
||||
fn stop_rustdesk_servers() {
|
||||
let _ = run_cmds(format!(
|
||||
r##"ps -ef | grep -E 'rustdesk +--server' | awk '{{printf("kill -9 %d\n", $2)}}' | bash"##,
|
||||
));
|
||||
}
|
||||
|
||||
fn should_start_server(
|
||||
try_x11: bool,
|
||||
uid: &mut String,
|
||||
cm0: &mut bool,
|
||||
last_restart: &mut std::time::Instant,
|
||||
server: &mut Option<std::process::Child>,
|
||||
) -> bool {
|
||||
let cm = get_cm();
|
||||
let tmp = get_active_userid();
|
||||
let mut start_new = false;
|
||||
if tmp != *uid && !tmp.is_empty() {
|
||||
*uid = tmp;
|
||||
if try_x11 {
|
||||
set_x11_env(&uid);
|
||||
}
|
||||
if let Some(ps) = server.as_mut() {
|
||||
allow_err!(ps.kill());
|
||||
std::thread::sleep(std::time::Duration::from_millis(30));
|
||||
*last_restart = std::time::Instant::now();
|
||||
}
|
||||
} else if !cm
|
||||
&& ((*cm0 && last_restart.elapsed().as_secs() > 60)
|
||||
|| last_restart.elapsed().as_secs() > 3600)
|
||||
{
|
||||
// restart server if new connections all closed, or every one hour,
|
||||
// as a workaround to resolve "SpotUdp" (dns resolve)
|
||||
// and x server get displays failure issue
|
||||
if let Some(ps) = server.as_mut() {
|
||||
allow_err!(ps.kill());
|
||||
std::thread::sleep(std::time::Duration::from_millis(30));
|
||||
*last_restart = std::time::Instant::now();
|
||||
log::info!("restart server");
|
||||
}
|
||||
}
|
||||
if let Some(ps) = server.as_mut() {
|
||||
match ps.try_wait() {
|
||||
Ok(Some(_)) => {
|
||||
*server = None;
|
||||
start_new = true;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
} else {
|
||||
start_new = true;
|
||||
}
|
||||
*cm0 = cm;
|
||||
start_new
|
||||
}
|
||||
|
||||
pub fn start_os_service() {
|
||||
stop_rustdesk_servers();
|
||||
|
||||
start_uinput_service();
|
||||
|
||||
let running = Arc::new(AtomicBool::new(true));
|
||||
let r = running.clone();
|
||||
let mut uid = "".to_owned();
|
||||
let mut server: Option<std::process::Child> = None;
|
||||
let mut user_server: Option<std::process::Child> = None;
|
||||
if let Err(err) = ctrlc::set_handler(move || {
|
||||
r.store(false, Ordering::SeqCst);
|
||||
}) {
|
||||
@ -234,78 +288,9 @@ pub fn start_os_service() {
|
||||
let is_wayland = current_is_wayland();
|
||||
|
||||
if username == "root" || !is_wayland {
|
||||
// try stop user service
|
||||
try_stop_user_service();
|
||||
|
||||
stop_server(&mut user_server);
|
||||
// try start subprocess "--server"
|
||||
let cm = get_cm();
|
||||
let tmp = get_active_userid();
|
||||
let mut start_new = false;
|
||||
if tmp != uid && !tmp.is_empty() {
|
||||
uid = tmp;
|
||||
log::info!("uid of seat0: {}", uid);
|
||||
let gdm = format!("/run/user/{}/gdm/Xauthority", uid);
|
||||
let mut auth = get_env_tries("XAUTHORITY", &uid, 10);
|
||||
if auth.is_empty() {
|
||||
auth = if std::path::Path::new(&gdm).exists() {
|
||||
gdm
|
||||
} else {
|
||||
let username = get_active_username();
|
||||
if username == "root" {
|
||||
format!("/{}/.Xauthority", username)
|
||||
} else {
|
||||
let tmp = format!("/home/{}/.Xauthority", username);
|
||||
if std::path::Path::new(&tmp).exists() {
|
||||
tmp
|
||||
} else {
|
||||
format!("/var/lib/{}/.Xauthority", username)
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
let mut d = get_env("DISPLAY", &uid);
|
||||
if d.is_empty() {
|
||||
d = get_display();
|
||||
}
|
||||
if d.is_empty() {
|
||||
d = ":0".to_owned();
|
||||
}
|
||||
d = d.replace(&whoami::hostname(), "").replace("localhost", "");
|
||||
log::info!("DISPLAY: {}", d);
|
||||
log::info!("XAUTHORITY: {}", auth);
|
||||
std::env::set_var("XAUTHORITY", auth);
|
||||
std::env::set_var("DISPLAY", d);
|
||||
if let Some(ps) = server.as_mut() {
|
||||
allow_err!(ps.kill());
|
||||
std::thread::sleep(std::time::Duration::from_millis(30));
|
||||
last_restart = std::time::Instant::now();
|
||||
}
|
||||
} else if !cm
|
||||
&& ((cm0 && last_restart.elapsed().as_secs() > 60)
|
||||
|| last_restart.elapsed().as_secs() > 3600)
|
||||
{
|
||||
// restart server if new connections all closed, or every one hour,
|
||||
// as a workaround to resolve "SpotUdp" (dns resolve)
|
||||
// and x server get displays failure issue
|
||||
if let Some(ps) = server.as_mut() {
|
||||
allow_err!(ps.kill());
|
||||
std::thread::sleep(std::time::Duration::from_millis(30));
|
||||
last_restart = std::time::Instant::now();
|
||||
log::info!("restart server");
|
||||
}
|
||||
}
|
||||
if let Some(ps) = server.as_mut() {
|
||||
match ps.try_wait() {
|
||||
Ok(Some(_)) => {
|
||||
server = None;
|
||||
start_new = true;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
} else {
|
||||
start_new = true;
|
||||
}
|
||||
if start_new {
|
||||
if should_start_server(true, &mut uid, &mut cm0, &mut last_restart, &mut server) {
|
||||
match crate::run_me(vec!["--server"]) {
|
||||
Ok(ps) => server = Some(ps),
|
||||
Err(err) => {
|
||||
@ -313,23 +298,37 @@ pub fn start_os_service() {
|
||||
}
|
||||
}
|
||||
}
|
||||
cm0 = cm;
|
||||
} else if username != "" {
|
||||
if username != "gdm" {
|
||||
// try kill subprocess "--server"
|
||||
stop_server(&mut server);
|
||||
|
||||
// try start user service
|
||||
try_start_user_service(&username);
|
||||
// try start subprocess "--server"
|
||||
if should_start_server(
|
||||
false,
|
||||
&mut uid,
|
||||
&mut cm0,
|
||||
&mut last_restart,
|
||||
&mut user_server,
|
||||
) {
|
||||
match run_as_user("--server") {
|
||||
Ok(ps) => user_server = ps,
|
||||
Err(err) => {
|
||||
log::error!("Failed to start server: {}", err);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
try_stop_user_service();
|
||||
stop_server(&mut user_server);
|
||||
stop_server(&mut server);
|
||||
}
|
||||
std::thread::sleep(std::time::Duration::from_millis(super::SERVICE_INTERVAL));
|
||||
}
|
||||
|
||||
try_stop_user_service();
|
||||
if let Some(ps) = user_server.take().as_mut() {
|
||||
allow_err!(ps.kill());
|
||||
}
|
||||
if let Some(ps) = server.take().as_mut() {
|
||||
allow_err!(ps.kill());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user