more Linux install script fixes.

This commit is contained in:
Ylian Saint-Hilaire 2019-03-01 18:07:38 -08:00
parent 67eb89143d
commit 9319e6ed43
4 changed files with 90 additions and 91 deletions

View File

@ -30,58 +30,53 @@ stop() {
echo 'Service not running' >&2 echo 'Service not running' >&2
return 1 return 1
else else
pid=$( cat "$PIDFILE" ) pid=$( cat "$PIDFILE" )
if kill -0 $pid 2>/dev/null; then if kill -0 $pid 2>/dev/null; then
echo 'Stopping service…' >&2 echo 'Stopping service…' >&2
kill -16 $pid kill -16 $pid
echo 'Service stopped' >&2 echo 'Service stopped' >&2
else else
echo 'Service not running' echo 'Service not running'
fi fi
rm -f $"PIDFILE" rm -f $"PIDFILE"
fi fi
} }
restart(){ restart(){
stop stop
start start
} }
status(){ status(){
if [ -f "$PIDFILE" ] if [ -f "$PIDFILE" ]
then then
pid=$( cat "$PIDFILE" ) pid=$( cat "$PIDFILE" )
if kill -0 $pid 2>/dev/null; then if kill -0 $pid 2>/dev/null; then
echo "meshagent start/running, process $pid" echo "meshagent start/running, process $pid"
else else
echo 'meshagent stop/waiting' echo 'meshagent stop/waiting'
fi fi
else else
echo 'meshagent stop/waiting' echo 'meshagent stop/waiting'
fi fi
} }
case "$1" in case "$1" in
start) start)
start start
;; ;;
stop) stop)
stop stop
;; ;;
restart) restart)
stop stop
start start
;; ;;
status) status)
status status
;; ;;
*) *)
echo "Usage: service meshagent {start|stop|restart|status}" echo "Usage: service meshagent {start|stop|restart|status}"
;; ;;
esac esac
exit 0 exit 0

View File

@ -3,13 +3,13 @@
CheckStartupType() { CheckStartupType() {
# echo "Checking process autostart system..." # echo "Checking process autostart system..."
starttype=`ps -p 1 | awk '/1/ {print $4}'` starttype=`ps -p 1 | awk '/1/ {print $4}'`
# 1 is Systemd; # Systemd
if [[ $starttype == 'systemd' ]]; then return 1; if [[ $starttype == 'systemd' ]]; then return 1;
elif [[ $starttype == 'init' ]]; elif [[ $starttype == 'init' ]];
then then
# 2 is Upstart # Upstart
if [[ `/sbin/init --version` =~ upstart ]]; then return 2; if [[ `/sbin/init --version` =~ upstart ]]; then return 2;
# 3 is Sysv-init # Sysv-init
return 3; return 3;
fi fi
fi fi
@ -47,8 +47,8 @@ CheckInstallAgent() {
if [ $# -ge 3 ] if [ $# -ge 3 ]
then then
# echo "Computer type is specified..." # echo "Computer type is specified..."
machineid=$3 machineid=$3
else else
# echo "Detecting computer type..." # echo "Detecting computer type..."
if [ $machinetype == 'x86_64' ] || [ $machinetype == 'amd64' ] if [ $machinetype == 'x86_64' ] || [ $machinetype == 'amd64' ]
then then
@ -66,9 +66,9 @@ CheckInstallAgent() {
machineid=25 machineid=25
fi fi
# Add more machine types, detect KVM support... here. # Add more machine types, detect KVM support... here.
fi fi
if [ $machineid -eq 0 ] if [ $machineid -eq 0 ]
then then
echo "Unsupported machine type: $machinetype." echo "Unsupported machine type: $machinetype."
else else
@ -92,13 +92,13 @@ DownloadAgent() {
mkdir -p /usr/local/mesh mkdir -p /usr/local/mesh
cd /usr/local/mesh cd /usr/local/mesh
echo "Downloading Mesh agent #$machineid..." echo "Downloading Mesh agent #$machineid..."
wget $url/meshagents?id=$machineid --no-check-certificate -O /usr/local/mesh/meshagent wget $url/meshagents?id=$machineid --no-check-certificate {{{noproxy}}}-O /usr/local/mesh/meshagent
# If it did not work, try again using http # If it did not work, try again using http
if [ $? != 0 ] if [ $? != 0 ]
then then
url=${url/"https://"/"http://"} url=${url/"https://"/"http://"}
wget $url/meshagents?id=$machineid -O /usr/local/mesh/meshagent wget $url/meshagents?id=$machineid {{{noproxy}}}-O /usr/local/mesh/meshagent
fi fi
if [ $? -eq 0 ] if [ $? -eq 0 ]
@ -106,62 +106,62 @@ DownloadAgent() {
echo "Mesh agent downloaded." echo "Mesh agent downloaded."
# TODO: We could check the meshagent sha256 hash, but best to authenticate the server. # TODO: We could check the meshagent sha256 hash, but best to authenticate the server.
chmod 755 /usr/local/mesh/meshagent chmod 755 /usr/local/mesh/meshagent
wget $url/meshsettings?id=$meshid --no-check-certificate -O /usr/local/mesh/meshagent.msh wget $url/meshsettings?id=$meshid --no-check-certificate {{{noproxy}}}-O /usr/local/mesh/meshagent.msh
# If it did not work, try again using http # If it did not work, try again using http
if [ $? -ne 0 ] if [ $? -ne 0 ]
then then
wget $url/meshsettings?id=$meshid -O /usr/local/mesh/meshagent.msh wget $url/meshsettings?id=$meshid {{{noproxy}}}-O /usr/local/mesh/meshagent.msh
fi fi
if [ $? -eq 0 ] if [ $? -eq 0 ]
then then
UpdateMshFile UpdateMshFile
if [ $starttype -eq 1 ] if [ $starttype -eq 1 ]
then then
# systemd # systemd
if [ -d "/lib/systemd/system/" ] if [ -d "/lib/systemd/system/" ]
then then
echo -e "[Unit]\nDescription=MeshCentral Agent\n[Service]\nExecStart=/usr/local/mesh/meshagent\nStandardOutput=null\nRestart=always\nRestartSec=3\n[Install]\nWantedBy=multi-user.target\nAlias=meshagent.service\n" > /lib/systemd/system/meshagent.service echo -e "[Unit]\nDescription=MeshCentral Agent\n[Service]\nExecStart=/usr/local/mesh/meshagent\nStandardOutput=null\nRestart=always\nRestartSec=3\n[Install]\nWantedBy=multi-user.target\nAlias=meshagent.service\n" > /lib/systemd/system/meshagent.service
else else
# Some distros have the systemd folder at a different place # Some distros have the systemd folder at a different place
if [ -d "/usr/lib/systemd/system/" ] if [ -d "/usr/lib/systemd/system/" ]
then then
echo -e "[Unit]\nDescription=MeshCentral Agent\n[Service]\nExecStart=/usr/local/mesh/meshagent\nStandardOutput=null\nRestart=always\nRestartSec=3\n[Install]\nWantedBy=multi-user.target\nAlias=meshagent.service\n" > /usr/lib/systemd/system/meshagent.service echo -e "[Unit]\nDescription=MeshCentral Agent\n[Service]\nExecStart=/usr/local/mesh/meshagent\nStandardOutput=null\nRestart=always\nRestartSec=3\n[Install]\nWantedBy=multi-user.target\nAlias=meshagent.service\n" > /usr/lib/systemd/system/meshagent.service
else else
echo "Unable to find systemd folder." echo "Unable to find systemd folder."
fi fi
fi fi
systemctl enable meshagent systemctl enable meshagent
systemctl start meshagent systemctl start meshagent
echo 'meshagent installed as systemd service.' echo 'meshagent installed as systemd service.'
echo 'To start service: sudo systemctl start meshagent' echo 'To start service: sudo systemctl start meshagent'
echo 'To stop service: sudo systemctl stop meshagent' echo 'To stop service: sudo systemctl stop meshagent'
elif [ $starttype -eq 3 ] elif [ $starttype -eq 3 ]
then then
# initd # initd
wget $url/meshagents?script=2 --no-check-certificate -O /etc/init.d/meshagent wget $url/meshagents?script=2 --no-check-certificate {{{noproxy}}}-O /etc/init.d/meshagent
chmod +x /etc/init.d/meshagent chmod +x /etc/init.d/meshagent
# creates symlinks for rc.d # creates symlinks for rc.d
update-rc.d meshagent defaults update-rc.d meshagent defaults
service meshagent start service meshagent start
echo 'meshagent installed as init.d service.' echo 'meshagent installed as init.d service.'
echo 'To start service: sudo service meshagent start' echo 'To start service: sudo service meshagent start'
echo 'To stop service: sudo service meshagent stop' echo 'To stop service: sudo service meshagent stop'
elif [ $starttype -eq 2 ] elif [ $starttype -eq 2 ]
then then
# upstart # upstart
echo -e "start on runlevel [2345]\nstop on runlevel [016]\n\nrespawn\n\nchdir /usr/local/mesh\nexec /usr/local/mesh/meshagent\n\n" > /etc/init/meshagent.conf echo -e "start on runlevel [2345]\nstop on runlevel [016]\n\nrespawn\n\nchdir /usr/local/mesh\nexec /usr/local/mesh/meshagent\n\n" > /etc/init/meshagent.conf
service meshagent start service meshagent start
echo 'meshagent installed as upstart/init.d service.' echo 'meshagent installed as upstart/init.d service.'
echo 'To start service: sudo service meshagent start' echo 'To start service: sudo service meshagent start'
echo 'To stop service: sudo service meshagent stop' echo 'To stop service: sudo service meshagent stop'
else else
# unknown # unknown
echo "Unknown Service Platform Type. (ie: init, systemd, etc)" echo "Unknown Service Platform Type. (ie: init, systemd, etc)"
echo "Unable to install meshagent as service." echo "Unable to install meshagent as service."
fi fi
echo "Mesh agent started." echo "Mesh agent started."
else else
echo "Unable to download mesh settings at: $url/meshsettings?id=$meshid." echo "Unable to download mesh settings at: $url/meshsettings?id=$meshid."
fi fi
@ -187,16 +187,17 @@ UninstallAgent() {
systemctl stop meshagent systemctl stop meshagent
else else
if [ $starttype -eq 3 ]; then if [ $starttype -eq 3 ]; then
# initd # initd
service meshagent stop service meshagent stop
update-rc.d -f meshagent remove update-rc.d -f meshagent remove
rm -f /sbin/meshcmd /etc/init.d/meshagent rm -f /sbin/meshcmd /etc/init.d/meshagent
elif [ $starttype -eq 2 ]; then elif [ $starttype -eq 2 ]; then
# upstart # upstart
service meshagent stop service meshagent stop
rm -f /sbin/meshcmd rm -f /sbin/meshcmd
rm -f /etc/init/meshagent.conf rm -f /etc/init/meshagent.conf
fi rm -f /etc/rc2.d/S20mesh /etc/rc3.d/S20mesh /etc/rc5.d/S20mesh
fi
fi fi
if [ -e $installpath ] if [ -e $installpath ]

View File

@ -1275,8 +1275,8 @@ function CreateMeshCentralServer(config, args) {
// List of possible mesh agent install scripts // List of possible mesh agent install scripts
var meshAgentsInstallScriptList = { var meshAgentsInstallScriptList = {
1: { id: 1, localname: 'meshinstall-linux.sh', rname: 'meshinstall.sh' }, 1: { id: 1, localname: 'meshinstall-linux.sh', rname: 'meshinstall.sh', linux: true },
2: { id: 2, localname: 'meshinstall-initd.sh', rname: 'meshagent' } 2: { id: 2, localname: 'meshinstall-initd.sh', rname: 'meshagent', linux: true }
}; };
// Update the list of available mesh agents // Update the list of available mesh agents
@ -1302,6 +1302,9 @@ function CreateMeshCentralServer(config, args) {
var stats = null; var stats = null;
try { stats = obj.fs.statSync(this.agentpath); } catch (e) { } try { stats = obj.fs.statSync(this.agentpath); } catch (e) { }
if (stats != null) { obj.meshAgentInstallScripts[this.info.id].size = stats.size; } if (stats != null) { obj.meshAgentInstallScripts[this.info.id].size = stats.size; }
// Place Unit line breaks on Linux scripts if not already present.
if (obj.meshAgentInstallScripts[this.info.id].linux === true) { obj.meshAgentInstallScripts[this.info.id].data = obj.meshAgentInstallScripts[this.info.id].data.split('\r\n').join('\n') }
}); });
stream.info = meshAgentsInstallScriptList[scriptid]; stream.info = meshAgentsInstallScriptList[scriptid];
stream.agentpath = scriptpath; stream.agentpath = scriptpath;

View File

@ -1,6 +1,6 @@
{ {
"name": "meshcentral", "name": "meshcentral",
"version": "0.2.9-m", "version": "0.2.9-n",
"keywords": [ "keywords": [
"Remote Management", "Remote Management",
"Intel AMT", "Intel AMT",