how does pfS keep track of services for packages?
-
I have the following...
zerotier.xml
<?xml version="1.0" encoding="utf-8" ?> <!DOCTYPE packagegui SYSTEM "../schema/packages.dtd"> <?xml-stylesheet type="text/xsl" href="../xsl/package.xsl"?> <packagegui> <name>zerotier</name> <title>Zerotier</title> <include_file>/usr/local/pkg/zerotier.inc</include_file> <menu> <name>Zerotier</name> <section>VPN</section> <url>/zerotier.php</url> </menu> <service> <name>zerotier</name> <rcfile>zerotier</rcfile> <executable>zerotier-one</executable> <description>Zerotier Daemon</description> </service> <custom_php_global_functions></custom_php_global_functions> <custom_php_install_command> zerotier_install(); </custom_php_install_command> <custom_php_deinstall_command> zerotier_deinstall(); </custom_php_deinstall_command> <custom_add_php_command></custom_add_php_command> <custom_add_php_command_late></custom_add_php_command_late> <custom_delete_php_command></custom_delete_php_command> <custom_php_resync_config_command> zerotier_sync(); </custom_php_resync_config_command> <start_command> </start_command> <process_kill_command> zerotier_kill(); </process_kill_command> </packagegui>
zerotier.inc
<?php /* * */ require_once("config.inc"); require_once("interfaces.inc"); require_once("globals.inc"); require_once("services.inc"); require_once("service-utils.inc"); require_once("util.inc"); function zerotier_sync() { global $config; if (is_service_running("zerotier")) { stop_service("zerotier"); } if ($config['installedpackages']['zerotier']['enabled'] == 'true') { start_service("zerotier"); } } function zerotier_install() { global $config; $config['installedpackages']['zerotier']['enabled'] = 'false'; $config['installedpackages']['zerotier']['experimental'] = 'false'; $zerotier = <<<EOD #!/bin/sh # $FreeBSD: head/net/zerotier/files/zerotier.in 454856 2017-11-24 23:17:50Z dbaio $ # # PROVIDE: zerotier # REQUIRE: NETWORKING # BEFORE: SERVERS # KEYWORD: shutdown # # Add these lines to /etc/rc.conf.local or /etc/rc.conf # to enable this service: # # zerotier_enable (bool): Set to NO by default. # Set it to YES to enable zerotier. . /etc/rc.subr name=zerotier rcvar=zerotier_enable pidfile="/var/db/\${name}-one/\${name}-one.pid" load_rc_config \${name} command="/usr/local/sbin/\${name}-one" command_args="-d" run_rc_command "$1" EOD; $fd = fopen("/usr/local/etc/rc.d/zerotier", "w"); fwrite($fd, $zerotier); fclose($fd); chmod("/usr/local/etc/rc.d/zerotier", 0555); $fd = fopen("/etc/rc.conf.local", "a"); fwrite($fd, "zerotier_enable=\"YES\"\n"); fclose($fd); $file_contents = file_get_contents("/etc/inc/util.inc"); $file_contents = preg_replace('/(\^enc\|)/', "^zt|$1", $file_contents); file_put_contents("/etc/inc/util.inc", $file_contents); write_config("[zerotier] Package installed."); } function zerotier_deinstall() { exec("killall zerotier-one"); $file_contents = file_get_contents("/etc/rc.conf.local"); $file_contents = str_replace("zerotier_enable=\"YES\"\n","",$file_contents); file_put_contents("/etc/rc.conf.local",$file_contents); $file_contents = file_get_contents("/etc/inc/util.inc"); $file_contents = preg_replace('/\^zt\|(\^enc\|)/', "$1", $file_contents); file_put_contents("/etc/inc/util.inc", $file_contents); } function zerotier_kill() { if (is_service_running("zerotier")) { stop_service("zerotier"); // exec("killall zerotier-one"); } } function zerotier_start() { if ($config['installedpackages']['zerotier']['enabled'] == 'true') { if (!is_service_running("zerotier")) { start_service("zerotier"); } } } ?>
Right now, the services status page shows the Zerotier service as always running, regardless of weather the daemon is actually alive or not. How would I fix that?
-
https://github.com/coreybrett/pfSense-pkg-zerotier
-
Would this be a pfS or FreeBSD question?
-
You can use the functions in this file to create a service. That same file also has the functions that are used to determine the status of a service. Avahi example